amazeui.legacy.js 191 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798
  1. /*! Amaze UI v2.4.0 ~ Old IE Fucker | by Amaze UI Team | (c) 2015 AllMobilize, Inc. | Licensed under MIT | 2015-06-01T09:54:08+0800 */
  2. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  3. (function (global){
  4. // Amaze UI JavaScript for IE8
  5. 'use strict';
  6. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  7. require('./core');
  8. require('./ui.alert');
  9. require('./ui.button');
  10. require('./ui.collapse');
  11. require('./ui.dimmer');
  12. require('./ui.dropdown');
  13. require('./ui.flexslider');
  14. require('./ui.modal');
  15. require('./ui.offcanvas');
  16. require('./ui.popover');
  17. require('./ui.progress');
  18. require('./ui.scrollspynav');
  19. require('./ui.sticky');
  20. require('./util.cookie');
  21. module.exports = $.AMUI;
  22. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  23. },{"./core":2,"./ui.alert":3,"./ui.button":4,"./ui.collapse":5,"./ui.dimmer":6,"./ui.dropdown":7,"./ui.flexslider":8,"./ui.modal":9,"./ui.offcanvas":10,"./ui.popover":11,"./ui.progress":12,"./ui.scrollspynav":13,"./ui.sticky":15,"./util.cookie":16}],2:[function(require,module,exports){
  24. (function (global){
  25. 'use strict';
  26. /* jshint -W040 */
  27. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  28. if (typeof $ === 'undefined') {
  29. throw new Error('Amaze UI 2.x requires jQuery :-(\n' +
  30. '\u7231\u4e0a\u4e00\u5339\u91ce\u9a6c\uff0c\u53ef\u4f60' +
  31. '\u7684\u5bb6\u91cc\u6ca1\u6709\u8349\u539f\u2026');
  32. }
  33. var UI = $.AMUI || {};
  34. var $win = $(window);
  35. var doc = window.document;
  36. var $html = $('html');
  37. UI.VERSION = '2.4.0';
  38. UI.support = {};
  39. UI.support.transition = (function() {
  40. var transitionEnd = (function() {
  41. // https://developer.mozilla.org/en-US/docs/Web/Events/transitionend#Browser_compatibility
  42. var element = doc.body || doc.documentElement;
  43. var transEndEventNames = {
  44. WebkitTransition: 'webkitTransitionEnd',
  45. MozTransition: 'transitionend',
  46. OTransition: 'oTransitionEnd otransitionend',
  47. transition: 'transitionend'
  48. };
  49. for (var name in transEndEventNames) {
  50. if (element.style[name] !== undefined) {
  51. return transEndEventNames[name];
  52. }
  53. }
  54. })();
  55. return transitionEnd && {end: transitionEnd};
  56. })();
  57. UI.support.animation = (function() {
  58. var animationEnd = (function() {
  59. var element = doc.body || doc.documentElement;
  60. var animEndEventNames = {
  61. WebkitAnimation: 'webkitAnimationEnd',
  62. MozAnimation: 'animationend',
  63. OAnimation: 'oAnimationEnd oanimationend',
  64. animation: 'animationend'
  65. };
  66. for (var name in animEndEventNames) {
  67. if (element.style[name] !== undefined) {
  68. return animEndEventNames[name];
  69. }
  70. }
  71. })();
  72. return animationEnd && {end: animationEnd};
  73. })();
  74. /* jshint -W069 */
  75. UI.support.touch = (
  76. ('ontouchstart' in window &&
  77. navigator.userAgent.toLowerCase().match(/mobile|tablet/)) ||
  78. (window.DocumentTouch && document instanceof window.DocumentTouch) ||
  79. (window.navigator['msPointerEnabled'] &&
  80. window.navigator['msMaxTouchPoints'] > 0) || //IE 10
  81. (window.navigator['pointerEnabled'] &&
  82. window.navigator['maxTouchPoints'] > 0) || //IE >=11
  83. false);
  84. // https://developer.mozilla.org/zh-CN/docs/DOM/MutationObserver
  85. UI.support.mutationobserver = (window.MutationObserver ||
  86. window.WebKitMutationObserver || null);
  87. // https://github.com/Modernizr/Modernizr/blob/924c7611c170ef2dc502582e5079507aff61e388/feature-detects/forms/validation.js#L20
  88. UI.support.formValidation = (typeof document.createElement('form').
  89. checkValidity === 'function');
  90. UI.utils = {};
  91. /**
  92. * Debounce function
  93. * @param {function} func Function to be debounced
  94. * @param {number} wait Function execution threshold in milliseconds
  95. * @param {bool} immediate Whether the function should be called at
  96. * the beginning of the delay instead of the
  97. * end. Default is false.
  98. * @desc Executes a function when it stops being invoked for n seconds
  99. * @via _.debounce() http://underscorejs.org
  100. */
  101. UI.utils.debounce = function(func, wait, immediate) {
  102. var timeout;
  103. return function() {
  104. var context = this;
  105. var args = arguments;
  106. var later = function() {
  107. timeout = null;
  108. if (!immediate) {
  109. func.apply(context, args);
  110. }
  111. };
  112. var callNow = immediate && !timeout;
  113. clearTimeout(timeout);
  114. timeout = setTimeout(later, wait);
  115. if (callNow) {
  116. func.apply(context, args);
  117. }
  118. };
  119. };
  120. UI.utils.isInView = function(element, options) {
  121. var $element = $(element);
  122. var visible = !!($element.width() || $element.height()) &&
  123. $element.css('display') !== 'none';
  124. if (!visible) {
  125. return false;
  126. }
  127. var windowLeft = $win.scrollLeft();
  128. var windowTop = $win.scrollTop();
  129. var offset = $element.offset();
  130. var left = offset.left;
  131. var top = offset.top;
  132. options = $.extend({topOffset: 0, leftOffset: 0}, options);
  133. return (top + $element.height() >= windowTop &&
  134. top - options.topOffset <= windowTop + $win.height() &&
  135. left + $element.width() >= windowLeft &&
  136. left - options.leftOffset <= windowLeft + $win.width());
  137. };
  138. /* jshint -W054 */
  139. UI.utils.parseOptions = UI.utils.options = function(string) {
  140. if ($.isPlainObject(string)) {
  141. return string;
  142. }
  143. var start = (string ? string.indexOf('{') : -1);
  144. var options = {};
  145. if (start != -1) {
  146. try {
  147. options = (new Function('',
  148. 'var json = ' + string.substr(start) +
  149. '; return JSON.parse(JSON.stringify(json));'))();
  150. } catch (e) {
  151. }
  152. }
  153. return options;
  154. };
  155. /* jshint +W054 */
  156. UI.utils.generateGUID = function(namespace) {
  157. var uid = namespace + '-' || 'am-';
  158. do {
  159. uid += Math.random().toString(36).substring(2, 7);
  160. } while (document.getElementById(uid));
  161. return uid;
  162. };
  163. // http://blog.alexmaccaw.com/css-transitions
  164. $.fn.emulateTransitionEnd = function(duration) {
  165. var called = false;
  166. var $el = this;
  167. $(this).one(UI.support.transition.end, function() {
  168. called = true;
  169. });
  170. var callback = function() {
  171. if (!called) {
  172. $($el).trigger(UI.support.transition.end);
  173. }
  174. $el.transitionEndTimmer = undefined;
  175. };
  176. this.transitionEndTimmer = setTimeout(callback, duration);
  177. return this;
  178. };
  179. $.fn.redraw = function() {
  180. $(this).each(function() {
  181. /* jshint unused:false */
  182. var redraw = this.offsetHeight;
  183. });
  184. return this;
  185. };
  186. /* jshint unused:true */
  187. $.fn.transitionEnd = function(callback) {
  188. var endEvent = UI.support.transition.end;
  189. var dom = this;
  190. function fireCallBack(e) {
  191. callback.call(this, e);
  192. endEvent && dom.off(endEvent, fireCallBack);
  193. }
  194. if (callback && endEvent) {
  195. dom.on(endEvent, fireCallBack);
  196. }
  197. return this;
  198. };
  199. $.fn.removeClassRegEx = function() {
  200. return this.each(function(regex) {
  201. var classes = $(this).attr('class');
  202. if (!classes || !regex) {
  203. return false;
  204. }
  205. var classArray = [];
  206. classes = classes.split(' ');
  207. for (var i = 0, len = classes.length; i < len; i++) {
  208. if (!classes[i].match(regex)) {
  209. classArray.push(classes[i]);
  210. }
  211. }
  212. $(this).attr('class', classArray.join(' '));
  213. });
  214. };
  215. //
  216. $.fn.alterClass = function(removals, additions) {
  217. var self = this;
  218. if (removals.indexOf('*') === -1) {
  219. // Use native jQuery methods if there is no wildcard matching
  220. self.removeClass(removals);
  221. return !additions ? self : self.addClass(additions);
  222. }
  223. var classPattern = new RegExp('\\s' +
  224. removals.
  225. replace(/\*/g, '[A-Za-z0-9-_]+').
  226. split(' ').
  227. join('\\s|\\s') +
  228. '\\s', 'g');
  229. self.each(function(i, it) {
  230. var cn = ' ' + it.className + ' ';
  231. while (classPattern.test(cn)) {
  232. cn = cn.replace(classPattern, ' ');
  233. }
  234. it.className = $.trim(cn);
  235. });
  236. return !additions ? self : self.addClass(additions);
  237. };
  238. // handle multiple browsers for requestAnimationFrame()
  239. // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  240. // https://github.com/gnarf/jquery-requestAnimationFrame
  241. UI.utils.rAF = (function() {
  242. return window.requestAnimationFrame ||
  243. window.webkitRequestAnimationFrame ||
  244. window.mozRequestAnimationFrame ||
  245. window.oRequestAnimationFrame ||
  246. // if all else fails, use setTimeout
  247. function(callback) {
  248. return window.setTimeout(callback, 1000 / 60); // shoot for 60 fps
  249. };
  250. })();
  251. // handle multiple browsers for cancelAnimationFrame()
  252. UI.utils.cancelAF = (function() {
  253. return window.cancelAnimationFrame ||
  254. window.webkitCancelAnimationFrame ||
  255. window.mozCancelAnimationFrame ||
  256. window.oCancelAnimationFrame ||
  257. function(id) {
  258. window.clearTimeout(id);
  259. };
  260. })();
  261. // via http://davidwalsh.name/detect-scrollbar-width
  262. UI.utils.measureScrollbar = function() {
  263. if (document.body.clientWidth >= window.innerWidth) {
  264. return 0;
  265. }
  266. // if ($html.width() >= window.innerWidth) return;
  267. // var scrollbarWidth = window.innerWidth - $html.width();
  268. var $measure = $('<div ' +
  269. 'style="width: 100px;height: 100px;overflow: scroll;' +
  270. 'position: absolute;top: -9999px;"></div>');
  271. $(document.body).append($measure);
  272. var scrollbarWidth = $measure[0].offsetWidth - $measure[0].clientWidth;
  273. $measure.remove();
  274. return scrollbarWidth;
  275. };
  276. UI.utils.imageLoader = function($image, callback) {
  277. function loaded() {
  278. callback($image[0]);
  279. }
  280. function bindLoad() {
  281. this.one('load', loaded);
  282. if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
  283. var src = this.attr('src');
  284. var param = src.match(/\?/) ? '&' : '?';
  285. param += 'random=' + (new Date()).getTime();
  286. this.attr('src', src + param);
  287. }
  288. }
  289. if (!$image.attr('src')) {
  290. loaded();
  291. return;
  292. }
  293. if ($image[0].complete || $image[0].readyState === 4) {
  294. loaded();
  295. } else {
  296. bindLoad.call($image);
  297. }
  298. };
  299. /**
  300. * https://github.com/cho45/micro-template.js
  301. * (c) cho45 http://cho45.github.com/mit-license
  302. */
  303. /* jshint -W109 */
  304. UI.template = function(id, data) {
  305. var me = UI.template;
  306. if (!me.cache[id]) {
  307. me.cache[id] = (function() {
  308. var name = id;
  309. var string = /^[\w\-]+$/.test(id) ?
  310. me.get(id) : (name = 'template(string)', id); // no warnings
  311. var line = 1;
  312. var body = ('try { ' + (me.variable ?
  313. 'var ' + me.variable + ' = this.stash;' : 'with (this.stash) { ') +
  314. "this.ret += '" +
  315. string.
  316. replace(/<%/g, '\x11').replace(/%>/g, '\x13'). // if you want other tag, just edit this line
  317. replace(/'(?![^\x11\x13]+?\x13)/g, '\\x27').
  318. replace(/^\s*|\s*$/g, '').
  319. replace(/\n/g, function() {
  320. return "';\nthis.line = " + (++line) + "; this.ret += '\\n";
  321. }).
  322. replace(/\x11-(.+?)\x13/g, "' + ($1) + '").
  323. replace(/\x11=(.+?)\x13/g, "' + this.escapeHTML($1) + '").
  324. replace(/\x11(.+?)\x13/g, "'; $1; this.ret += '") +
  325. "'; " + (me.variable ? "" : "}") + "return this.ret;" +
  326. "} catch (e) { throw 'TemplateError: ' + e + ' (on " + name +
  327. "' + ' line ' + this.line + ')'; } " +
  328. "//@ sourceURL=" + name + "\n" // source map
  329. ).replace(/this\.ret \+= '';/g, '');
  330. /* jshint -W054 */
  331. var func = new Function(body);
  332. var map = {
  333. '&': '&amp;',
  334. '<': '&lt;',
  335. '>': '&gt;',
  336. '\x22': '&#x22;',
  337. '\x27': '&#x27;'
  338. };
  339. var escapeHTML = function(string) {
  340. return ('' + string).replace(/[&<>\'\"]/g, function(_) {
  341. return map[_];
  342. });
  343. };
  344. return function(stash) {
  345. return func.call(me.context = {
  346. escapeHTML: escapeHTML,
  347. line: 1,
  348. ret: '',
  349. stash: stash
  350. });
  351. };
  352. })();
  353. }
  354. return data ? me.cache[id](data) : me.cache[id];
  355. };
  356. /* jshint +W109 */
  357. /* jshint +W054 */
  358. UI.template.cache = {};
  359. UI.template.get = function(id) {
  360. if (id) {
  361. var element = document.getElementById(id);
  362. return element && element.innerHTML || '';
  363. }
  364. };
  365. // Dom mutation watchers
  366. UI.DOMWatchers = [];
  367. UI.DOMReady = false;
  368. UI.ready = function(callback) {
  369. UI.DOMWatchers.push(callback);
  370. if (UI.DOMReady) {
  371. // console.log('Ready call');
  372. callback(document);
  373. }
  374. };
  375. UI.DOMObserve = function(elements, options, callback) {
  376. var Observer = UI.support.mutationobserver;
  377. if (!Observer) {
  378. return;
  379. }
  380. options = $.isPlainObject(options) ?
  381. options : {childList: true, subtree: true};
  382. callback = typeof callback === 'function' && callback || function() {
  383. };
  384. $(elements).each(function() {
  385. var element = this;
  386. var $element = $(element);
  387. if ($element.data('am.observer')) {
  388. return;
  389. }
  390. try {
  391. var observer = new Observer(UI.utils.debounce(
  392. function(mutations, instance) {
  393. callback.call(element, mutations, instance);
  394. // trigger this event manually if MutationObserver not supported
  395. $element.trigger('changed.dom.amui');
  396. }, 50));
  397. observer.observe(element, options);
  398. $element.data('am.observer', observer);
  399. } catch (e) {
  400. }
  401. });
  402. };
  403. $.fn.DOMObserve = function(options, callback) {
  404. return this.each(function() {
  405. UI.DOMObserve(this, options, callback);
  406. });
  407. };
  408. if (UI.support.touch) {
  409. $html.addClass('am-touch');
  410. }
  411. $(document).on('changed.dom.amui', function(e) {
  412. var element = e.target;
  413. // TODO: just call changed element's watcher
  414. // every watcher callback should have a key
  415. // use like this: <div data-am-observe='key1, key2'>
  416. // get keys via $(element).data('amObserve')
  417. // call functions store with these keys
  418. $.each(UI.DOMWatchers, function(i, watcher) {
  419. watcher(element);
  420. });
  421. });
  422. $(function() {
  423. var $body = $('body');
  424. UI.DOMReady = true;
  425. // Run default init
  426. $.each(UI.DOMWatchers, function(i, watcher) {
  427. watcher(document);
  428. });
  429. // watches DOM
  430. UI.DOMObserve('[data-am-observe]');
  431. $html.removeClass('no-js').addClass('js');
  432. UI.support.animation && $html.addClass('cssanimations');
  433. // iOS standalone mode
  434. if (window.navigator.standalone) {
  435. $html.addClass('am-standalone');
  436. }
  437. $('.am-topbar-fixed-top').length &&
  438. $body.addClass('am-with-topbar-fixed-top');
  439. $('.am-topbar-fixed-bottom').length &&
  440. $body.addClass('am-with-topbar-fixed-bottom');
  441. // Remove responsive classes in .am-layout
  442. var $layout = $('.am-layout');
  443. $layout.find('[class*="md-block-grid"]').alterClass('md-block-grid-*');
  444. $layout.find('[class*="lg-block-grid"]').alterClass('lg-block-grid');
  445. // widgets not in .am-layout
  446. $('[data-am-widget]').each(function() {
  447. var $widget = $(this);
  448. // console.log($widget.parents('.am-layout').length)
  449. if ($widget.parents('.am-layout').length === 0) {
  450. $widget.addClass('am-no-layout');
  451. }
  452. });
  453. });
  454. $.AMUI = UI;
  455. module.exports = UI;
  456. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  457. },{}],3:[function(require,module,exports){
  458. (function (global){
  459. 'use strict';
  460. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  461. var UI = require('./core');
  462. /**
  463. * @via https://github.com/Minwe/bootstrap/blob/master/js/alert.js
  464. * @copyright Copyright 2013 Twitter, Inc.
  465. * @license Apache 2.0
  466. */
  467. // Alert Class
  468. // NOTE: removeElement option is unavailable now
  469. var Alert = function(element, options) {
  470. var _this = this;
  471. this.options = $.extend({}, Alert.DEFAULTS, options);
  472. this.$element = $(element);
  473. this.$element.
  474. addClass('am-fade am-in').
  475. on('click.alert.amui', '.am-close', function() {
  476. _this.close.call(this);
  477. });
  478. };
  479. Alert.DEFAULTS = {
  480. removeElement: true
  481. };
  482. Alert.prototype.close = function() {
  483. var $this = $(this);
  484. var $target = $this.hasClass('am-alert') ?
  485. $this :
  486. $this.parent('.am-alert');
  487. $target.trigger('close.alert.amui');
  488. $target.removeClass('am-in');
  489. function processAlert() {
  490. $target.trigger('closed.alert.amui').remove();
  491. }
  492. UI.support.transition && $target.hasClass('am-fade') ?
  493. $target.
  494. one(UI.support.transition.end, processAlert).
  495. emulateTransitionEnd(200) : processAlert();
  496. };
  497. // Alert Plugin
  498. $.fn.alert = function(option) {
  499. return this.each(function() {
  500. var $this = $(this);
  501. var data = $this.data('amui.alert');
  502. var options = typeof option == 'object' && option;
  503. if (!data) {
  504. $this.data('amui.alert', (data = new Alert(this, options || {})));
  505. }
  506. if (typeof option == 'string') {
  507. data[option].call($this);
  508. }
  509. });
  510. };
  511. // Init code
  512. $(document).on('click.alert.amui.data-api', '[data-am-alert]', function(e) {
  513. var $target = $(e.target);
  514. $(this).addClass('am-fade am-in');
  515. $target.is('.am-close') && $(this).alert('close');
  516. });
  517. $.AMUI.alert = Alert;
  518. module.exports = Alert;
  519. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  520. },{"./core":2}],4:[function(require,module,exports){
  521. (function (global){
  522. 'use strict';
  523. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  524. var UI = require('./core');
  525. /**
  526. * @via https://github.com/twbs/bootstrap/blob/master/js/button.js
  527. * @copyright (c) 2011-2014 Twitter, Inc
  528. * @license The MIT License
  529. */
  530. var Button = function(element, options) {
  531. this.$element = $(element);
  532. this.options = $.extend({}, Button.DEFAULTS, options);
  533. this.isLoading = false;
  534. this.hasSpinner = false;
  535. };
  536. Button.DEFAULTS = {
  537. loadingText: 'loading...',
  538. className: {
  539. loading: 'am-btn-loading',
  540. disabled: 'am-disabled'
  541. },
  542. spinner: undefined
  543. };
  544. Button.prototype.setState = function(state) {
  545. var disabled = 'disabled';
  546. var $element = this.$element;
  547. var options = this.options;
  548. var val = $element.is('input') ? 'val' : 'html';
  549. var loadingClassName = options.className.disabled + ' ' +
  550. options.className.loading;
  551. state = state + 'Text';
  552. if (!options.resetText) {
  553. options.resetText = $element[val]();
  554. }
  555. // add spinner for element with html()
  556. if (UI.support.animation && options.spinner &&
  557. val === 'html' && !this.hasSpinner) {
  558. options.loadingText = '<span class="am-icon-' +
  559. options.spinner +
  560. ' am-icon-spin"></span>' + options.loadingText;
  561. this.hasSpinner = true;
  562. }
  563. $element[val](options[state]);
  564. // push to event loop to allow forms to submit
  565. setTimeout($.proxy(function() {
  566. if (state == 'loadingText') {
  567. $element.addClass(loadingClassName).attr(disabled, disabled);
  568. this.isLoading = true;
  569. } else if (this.isLoading) {
  570. $element.removeClass(loadingClassName).removeAttr(disabled);
  571. this.isLoading = false;
  572. }
  573. }, this), 0);
  574. };
  575. Button.prototype.toggle = function() {
  576. var changed = true;
  577. var $element = this.$element;
  578. var $parent = this.$element.parent('.am-btn-group');
  579. if ($parent.length) {
  580. var $input = this.$element.find('input');
  581. if ($input.prop('type') == 'radio') {
  582. if ($input.prop('checked') && $element.hasClass('am-active')) {
  583. changed = false;
  584. } else {
  585. $parent.find('.am-active').removeClass('am-active');
  586. }
  587. }
  588. if (changed) {
  589. $input.prop('checked',
  590. !$element.hasClass('am-active')).trigger('change');
  591. }
  592. }
  593. if (changed) {
  594. $element.toggleClass('am-active');
  595. if (!$element.hasClass('am-active')) {
  596. $element.blur();
  597. }
  598. }
  599. };
  600. // Button plugin
  601. function Plugin(option) {
  602. return this.each(function() {
  603. var $this = $(this);
  604. var data = $this.data('amui.button');
  605. var options = typeof option == 'object' && option || {};
  606. if (!data) {
  607. $this.data('amui.button', (data = new Button(this, options)));
  608. }
  609. if (option == 'toggle') {
  610. data.toggle();
  611. } else if (typeof option == 'string') {
  612. data.setState(option);
  613. }
  614. });
  615. }
  616. $.fn.button = Plugin;
  617. // Init code
  618. $(document).on('click.button.amui.data-api', '[data-am-button]', function(e) {
  619. var $btn = $(e.target);
  620. if (!$btn.hasClass('am-btn')) {
  621. $btn = $btn.closest('.am-btn');
  622. }
  623. Plugin.call($btn, 'toggle');
  624. e.preventDefault();
  625. });
  626. UI.ready(function(context) {
  627. $('[data-am-loading]', context).each(function() {
  628. $(this).button(UI.utils.parseOptions($(this).data('amLoading')));
  629. });
  630. });
  631. $.AMUI.button = Button;
  632. module.exports = Button;
  633. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  634. },{"./core":2}],5:[function(require,module,exports){
  635. (function (global){
  636. 'use strict';
  637. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  638. var UI = require('./core');
  639. /**
  640. * @via https://github.com/twbs/bootstrap/blob/master/js/collapse.js
  641. * @copyright (c) 2011-2014 Twitter, Inc
  642. * @license The MIT License
  643. */
  644. var Collapse = function(element, options) {
  645. this.$element = $(element);
  646. this.options = $.extend({}, Collapse.DEFAULTS, options);
  647. this.transitioning = null;
  648. if (this.options.parent) {
  649. this.$parent = $(this.options.parent);
  650. }
  651. if (this.options.toggle) {
  652. this.toggle();
  653. }
  654. };
  655. Collapse.DEFAULTS = {
  656. toggle: true
  657. };
  658. Collapse.prototype.open = function() {
  659. if (this.transitioning || this.$element.hasClass('am-in')) {
  660. return;
  661. }
  662. var startEvent = $.Event('open.collapse.amui');
  663. this.$element.trigger(startEvent);
  664. if (startEvent.isDefaultPrevented()) {
  665. return;
  666. }
  667. var actives = this.$parent && this.$parent.find('> .am-panel > .am-in');
  668. if (actives && actives.length) {
  669. var hasData = actives.data('amui.collapse');
  670. if (hasData && hasData.transitioning) {
  671. return;
  672. }
  673. Plugin.call(actives, 'close');
  674. hasData || actives.data('amui.collapse', null);
  675. }
  676. this.$element
  677. .removeClass('am-collapse')
  678. .addClass('am-collapsing').height(0);
  679. this.transitioning = 1;
  680. var complete = function() {
  681. this.$element.
  682. removeClass('am-collapsing').
  683. addClass('am-collapse am-in').
  684. height('');
  685. this.transitioning = 0;
  686. this.$element.trigger('opened.collapse.amui');
  687. };
  688. if (!UI.support.transition) {
  689. return complete.call(this);
  690. }
  691. var scrollHeight = this.$element[0].scrollHeight;
  692. this.$element
  693. .one(UI.support.transition.end, $.proxy(complete, this))
  694. .emulateTransitionEnd(300).
  695. css({height: scrollHeight}); // 当折叠的容器有 padding 时,如果用 height() 只能设置内容的宽度
  696. };
  697. Collapse.prototype.close = function() {
  698. if (this.transitioning || !this.$element.hasClass('am-in')) {
  699. return;
  700. }
  701. var startEvent = $.Event('close.collapse.amui');
  702. this.$element.trigger(startEvent);
  703. if (startEvent.isDefaultPrevented()) {
  704. return;
  705. }
  706. this.$element.height(this.$element.height()).redraw();
  707. this.$element.addClass('am-collapsing').
  708. removeClass('am-collapse am-in');
  709. this.transitioning = 1;
  710. var complete = function() {
  711. this.transitioning = 0;
  712. this.$element.trigger('closed.collapse.amui').
  713. removeClass('am-collapsing').
  714. addClass('am-collapse');
  715. // css({height: '0'});
  716. };
  717. if (!UI.support.transition) {
  718. return complete.call(this);
  719. }
  720. this.$element.height(0)
  721. .one(UI.support.transition.end, $.proxy(complete, this))
  722. .emulateTransitionEnd(300);
  723. };
  724. Collapse.prototype.toggle = function() {
  725. this[this.$element.hasClass('am-in') ? 'close' : 'open']();
  726. };
  727. // Collapse Plugin
  728. function Plugin(option) {
  729. return this.each(function() {
  730. var $this = $(this);
  731. var data = $this.data('amui.collapse');
  732. var options = $.extend({}, Collapse.DEFAULTS,
  733. UI.utils.options($this.attr('data-am-collapse')),
  734. typeof option == 'object' && option);
  735. if (!data && options.toggle && option == 'open') {
  736. option = !option;
  737. }
  738. if (!data) {
  739. $this.data('amui.collapse', (data = new Collapse(this, options)));
  740. }
  741. if (typeof option == 'string') {
  742. data[option]();
  743. }
  744. });
  745. }
  746. $.fn.collapse = Plugin;
  747. // Init code
  748. $(document).on('click.collapse.amui.data-api', '[data-am-collapse]',
  749. function(e) {
  750. var href;
  751. var $this = $(this);
  752. var options = UI.utils.options($this.attr('data-am-collapse'));
  753. var target = options.target ||
  754. e.preventDefault() ||
  755. (href = $this.attr('href')) &&
  756. href.replace(/.*(?=#[^\s]+$)/, '');
  757. var $target = $(target);
  758. var data = $target.data('amui.collapse');
  759. var option = data ? 'toggle' : options;
  760. var parent = options.parent;
  761. var $parent = parent && $(parent);
  762. if (!data || !data.transitioning) {
  763. if ($parent) {
  764. // '[data-am-collapse*="{parent: \'' + parent + '"]
  765. $parent.find('[data-am-collapse]').not($this).addClass('am-collapsed');
  766. }
  767. $this[$target.hasClass('am-in') ? 'addClass' :
  768. 'removeClass']('am-collapsed');
  769. }
  770. Plugin.call($target, option);
  771. });
  772. $.AMUI.collapse = Collapse;
  773. module.exports = Collapse;
  774. // TODO: 更好的 target 选择方式
  775. // 折叠的容器必须没有 border/padding 才能正常处理,否则动画会有一些小问题
  776. // 寻找更好的未知高度 transition 动画解决方案,max-height 之类的就算了
  777. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  778. },{"./core":2}],6:[function(require,module,exports){
  779. (function (global){
  780. 'use strict';
  781. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  782. var UI = require('./core');
  783. var $doc = $(document);
  784. var transition = UI.support.transition;
  785. var Dimmer = function() {
  786. this.id = UI.utils.generateGUID('am-dimmer');
  787. this.$element = $(Dimmer.DEFAULTS.tpl, {
  788. id: this.id
  789. });
  790. this.inited = false;
  791. this.scrollbarWidth = 0;
  792. this.$used = $([]);
  793. };
  794. Dimmer.DEFAULTS = {
  795. tpl: '<div class="am-dimmer" data-am-dimmer></div>'
  796. };
  797. Dimmer.prototype.init = function() {
  798. if (!this.inited) {
  799. $(document.body).append(this.$element);
  800. this.inited = true;
  801. $doc.trigger('init.dimmer.amui');
  802. }
  803. return this;
  804. };
  805. Dimmer.prototype.open = function(relatedElement) {
  806. if (!this.inited) {
  807. this.init();
  808. }
  809. var $element = this.$element;
  810. // 用于多重调用
  811. if (relatedElement) {
  812. this.$used = this.$used.add($(relatedElement));
  813. }
  814. this.checkScrollbar().setScrollbar();
  815. $element.off(transition.end).show().trigger('open.dimmer.amui');
  816. setTimeout(function() {
  817. $element.addClass('am-active');
  818. }, 0);
  819. return this;
  820. };
  821. Dimmer.prototype.close = function(relatedElement, force) {
  822. this.$used = this.$used.not($(relatedElement));
  823. if (!force && this.$used.length) {
  824. return this;
  825. }
  826. var $element = this.$element;
  827. $element.removeClass('am-active').trigger('close.dimmer.amui');
  828. function complete() {
  829. $element.hide();
  830. this.resetScrollbar();
  831. }
  832. // transition ? $element.one(transition.end, $.proxy(complete, this)) :
  833. complete.call(this);
  834. return this;
  835. };
  836. Dimmer.prototype.checkScrollbar = function() {
  837. this.scrollbarWidth = UI.utils.measureScrollbar();
  838. return this;
  839. };
  840. Dimmer.prototype.setScrollbar = function() {
  841. var $body = $(document.body);
  842. var bodyPaddingRight = parseInt(($body.css('padding-right') || 0), 10);
  843. if (this.scrollbarWidth) {
  844. $body.css('padding-right', bodyPaddingRight + this.scrollbarWidth);
  845. }
  846. $body.addClass('am-dimmer-active');
  847. return this;
  848. };
  849. Dimmer.prototype.resetScrollbar = function() {
  850. $(document.body).css('padding-right', '').removeClass('am-dimmer-active');
  851. return this;
  852. };
  853. var dimmer = new Dimmer();
  854. $.AMUI.dimmer = dimmer;
  855. module.exports = dimmer;
  856. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  857. },{"./core":2}],7:[function(require,module,exports){
  858. (function (global){
  859. 'use strict';
  860. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  861. var UI = require('./core');
  862. var animation = UI.support.animation;
  863. /**
  864. * @via https://github.com/Minwe/bootstrap/blob/master/js/dropdown.js
  865. * @copyright (c) 2011-2014 Twitter, Inc
  866. * @license The MIT License
  867. */
  868. // var toggle = '[data-am-dropdown] > .am-dropdown-toggle';
  869. var Dropdown = function(element, options) {
  870. this.options = $.extend({}, Dropdown.DEFAULTS, options);
  871. options = this.options;
  872. this.$element = $(element);
  873. this.$toggle = this.$element.find(options.selector.toggle);
  874. this.$dropdown = this.$element.find(options.selector.dropdown);
  875. this.$boundary = (options.boundary === window) ? $(window) :
  876. this.$element.closest(options.boundary);
  877. this.$justify = (options.justify && $(options.justify).length &&
  878. $(options.justify)) || undefined;
  879. !this.$boundary.length && (this.$boundary = $(window));
  880. this.active = this.$element.hasClass('am-active') ? true : false;
  881. this.animating = null;
  882. this.events();
  883. };
  884. Dropdown.DEFAULTS = {
  885. animation: 'am-animation-slide-top-fixed',
  886. boundary: window,
  887. justify: undefined,
  888. selector: {
  889. dropdown: '.am-dropdown-content',
  890. toggle: '.am-dropdown-toggle'
  891. },
  892. trigger: 'click'
  893. };
  894. Dropdown.prototype.toggle = function() {
  895. this.clear();
  896. if (this.animating) {
  897. return;
  898. }
  899. this[this.active ? 'close' : 'open']();
  900. };
  901. Dropdown.prototype.open = function(e) {
  902. var $toggle = this.$toggle;
  903. var $element = this.$element;
  904. var $dropdown = this.$dropdown;
  905. if ($toggle.is('.am-disabled, :disabled')) {
  906. return;
  907. }
  908. if (this.active) {
  909. return;
  910. }
  911. $element.trigger('open.dropdown.amui').addClass('am-active');
  912. $toggle.trigger('focus');
  913. this.checkDimensions();
  914. var complete = $.proxy(function() {
  915. $element.trigger('opened.dropdown.amui');
  916. this.active = true;
  917. this.animating = 0;
  918. }, this);
  919. if (animation) {
  920. this.animating = 1;
  921. $dropdown.addClass(this.options.animation).
  922. on(animation.end + '.open.dropdown.amui', $.proxy(function() {
  923. complete();
  924. $dropdown.removeClass(this.options.animation);
  925. }, this));
  926. } else {
  927. complete();
  928. }
  929. };
  930. Dropdown.prototype.close = function() {
  931. if (!this.active) {
  932. return;
  933. }
  934. // fix #165
  935. // var animationName = this.options.animation + ' am-animation-reverse';
  936. var animationName = 'am-dropdown-animation';
  937. var $element = this.$element;
  938. var $dropdown = this.$dropdown;
  939. $element.trigger('close.dropdown.amui');
  940. var complete = $.proxy(function complete() {
  941. $element.
  942. removeClass('am-active').
  943. trigger('closed.dropdown.amui');
  944. this.active = false;
  945. this.animating = 0;
  946. this.$toggle.blur();
  947. }, this);
  948. if (animation) {
  949. $dropdown.removeClass(this.options.animation);
  950. $dropdown.addClass(animationName);
  951. this.animating = 1;
  952. // animation
  953. $dropdown.one(animation.end + '.close.dropdown.amui', function() {
  954. $dropdown.removeClass(animationName);
  955. complete();
  956. });
  957. } else {
  958. complete();
  959. }
  960. };
  961. Dropdown.prototype.checkDimensions = function() {
  962. if (!this.$dropdown.length) {
  963. return;
  964. }
  965. var $dropdown = this.$dropdown;
  966. var offset = $dropdown.offset();
  967. var width = $dropdown.outerWidth();
  968. var boundaryWidth = this.$boundary.width();
  969. var boundaryOffset = $.isWindow(this.boundary) && this.$boundary.offset() ?
  970. this.$boundary.offset().left : 0;
  971. if (this.$justify) {
  972. // jQuery.fn.width() is really...
  973. $dropdown.css({'min-width': this.$justify.css('width')});
  974. }
  975. if ((width + (offset.left - boundaryOffset)) > boundaryWidth) {
  976. this.$element.addClass('am-dropdown-flip');
  977. }
  978. };
  979. Dropdown.prototype.clear = function() {
  980. $('[data-am-dropdown]').not(this.$element).each(function() {
  981. var data = $(this).data('amui.dropdown');
  982. data && data.close();
  983. });
  984. };
  985. Dropdown.prototype.events = function() {
  986. var eventNS = 'dropdown.amui';
  987. // triggers = this.options.trigger.split(' '),
  988. var $toggle = this.$toggle;
  989. $toggle.on('click.' + eventNS, $.proxy(function(e) {
  990. e.preventDefault();
  991. this.toggle();
  992. }, this));
  993. /*for (var i = triggers.length; i--;) {
  994. var trigger = triggers[i];
  995. if (trigger === 'click') {
  996. $toggle.on('click.' + eventNS, $.proxy(this.toggle, this))
  997. }
  998. if (trigger === 'focus' || trigger === 'hover') {
  999. var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
  1000. var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
  1001. this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this))
  1002. .on(eventOut + '.' + eventNS, $.proxy(this.close, this));
  1003. }
  1004. }*/
  1005. $(document).on('keydown.dropdown.amui', $.proxy(function(e) {
  1006. e.keyCode === 27 && this.active && this.close();
  1007. }, this)).on('click.outer.dropdown.amui', $.proxy(function(e) {
  1008. // var $target = $(e.target);
  1009. if (this.active &&
  1010. (this.$element[0] === e.target || !this.$element.find(e.target).length)) {
  1011. this.close();
  1012. }
  1013. }, this));
  1014. };
  1015. // Dropdown Plugin
  1016. function Plugin(option) {
  1017. return this.each(function() {
  1018. var $this = $(this);
  1019. var data = $this.data('amui.dropdown');
  1020. var options = $.extend({},
  1021. UI.utils.parseOptions($this.attr('data-am-dropdown')),
  1022. typeof option == 'object' && option);
  1023. if (!data) {
  1024. $this.data('amui.dropdown', (data = new Dropdown(this, options)));
  1025. }
  1026. if (typeof option == 'string') {
  1027. data[option]();
  1028. }
  1029. });
  1030. }
  1031. $.fn.dropdown = Plugin;
  1032. // Init code
  1033. UI.ready(function(context) {
  1034. $('[data-am-dropdown]', context).dropdown();
  1035. });
  1036. $(document).on('click.dropdown.amui.data-api', '.am-dropdown form',
  1037. function(e) {
  1038. e.stopPropagation();
  1039. });
  1040. $.AMUI.dropdown = Dropdown;
  1041. module.exports = Dropdown;
  1042. // TODO: 1. 处理链接 focus
  1043. // 2. 增加 mouseenter / mouseleave 选项
  1044. // 3. 宽度适应
  1045. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1046. },{"./core":2}],8:[function(require,module,exports){
  1047. (function (global){
  1048. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  1049. var UI = require('./core');
  1050. // MODIFIED:
  1051. // - LINE 226: add `<i></i>`
  1052. // - namespace
  1053. // - Init code
  1054. // TODO: start after x ms when pause on actions
  1055. /*
  1056. * jQuery FlexSlider v2.4.0
  1057. * Copyright 2012 WooThemes
  1058. * Contributing Author: Tyler Smith
  1059. */
  1060. // FlexSlider: Object Instance
  1061. $.flexslider = function(el, options) {
  1062. var slider = $(el);
  1063. // making variables public
  1064. slider.vars = $.extend({}, $.flexslider.defaults, options);
  1065. var namespace = slider.vars.namespace,
  1066. msGesture = window.navigator && window.navigator.msPointerEnabled && window.MSGesture,
  1067. touch = (( "ontouchstart" in window ) || msGesture || window.DocumentTouch && document instanceof DocumentTouch) && slider.vars.touch,
  1068. // depricating this idea, as devices are being released with both of these events
  1069. //eventType = (touch) ? "touchend" : "click",
  1070. eventType = "click touchend MSPointerUp keyup",
  1071. watchedEvent = "",
  1072. watchedEventClearTimer,
  1073. vertical = slider.vars.direction === "vertical",
  1074. reverse = slider.vars.reverse,
  1075. carousel = (slider.vars.itemWidth > 0),
  1076. fade = slider.vars.animation === "fade",
  1077. asNav = slider.vars.asNavFor !== "",
  1078. methods = {},
  1079. focused = true;
  1080. // Store a reference to the slider object
  1081. $.data(el, 'flexslider', slider);
  1082. // Private slider methods
  1083. methods = {
  1084. init: function() {
  1085. slider.animating = false;
  1086. // Get current slide and make sure it is a number
  1087. slider.currentSlide = parseInt((slider.vars.startAt ? slider.vars.startAt : 0), 10);
  1088. if (isNaN(slider.currentSlide)) {
  1089. slider.currentSlide = 0;
  1090. }
  1091. slider.animatingTo = slider.currentSlide;
  1092. slider.atEnd = (slider.currentSlide === 0 || slider.currentSlide === slider.last);
  1093. slider.containerSelector = slider.vars.selector.substr(0, slider.vars.selector.search(' '));
  1094. slider.slides = $(slider.vars.selector, slider);
  1095. slider.container = $(slider.containerSelector, slider);
  1096. slider.count = slider.slides.length;
  1097. // SYNC:
  1098. slider.syncExists = $(slider.vars.sync).length > 0;
  1099. // SLIDE:
  1100. if (slider.vars.animation === "slide") {
  1101. slider.vars.animation = "swing";
  1102. }
  1103. slider.prop = (vertical) ? "top" : "marginLeft";
  1104. slider.args = {};
  1105. // SLIDESHOW:
  1106. slider.manualPause = false;
  1107. slider.stopped = false;
  1108. //PAUSE WHEN INVISIBLE
  1109. slider.started = false;
  1110. slider.startTimeout = null;
  1111. // TOUCH/USECSS:
  1112. slider.transitions = !slider.vars.video && !fade && slider.vars.useCSS && (function() {
  1113. var obj = document.createElement('div'),
  1114. props = ['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective'];
  1115. for (var i in props) {
  1116. if (obj.style[props[i]] !== undefined) {
  1117. slider.pfx = props[i].replace('Perspective', '').toLowerCase();
  1118. slider.prop = "-" + slider.pfx + "-transform";
  1119. return true;
  1120. }
  1121. }
  1122. return false;
  1123. }());
  1124. slider.ensureAnimationEnd = '';
  1125. // CONTROLSCONTAINER:
  1126. if (slider.vars.controlsContainer !== "") slider.controlsContainer = $(slider.vars.controlsContainer).length > 0 && $(slider.vars.controlsContainer);
  1127. // MANUAL:
  1128. if (slider.vars.manualControls !== "") slider.manualControls = $(slider.vars.manualControls).length > 0 && $(slider.vars.manualControls);
  1129. // RANDOMIZE:
  1130. if (slider.vars.randomize) {
  1131. slider.slides.sort(function() {
  1132. return (Math.round(Math.random()) - 0.5);
  1133. });
  1134. slider.container.empty().append(slider.slides);
  1135. }
  1136. slider.doMath();
  1137. // INIT
  1138. slider.setup("init");
  1139. // CONTROLNAV:
  1140. if (slider.vars.controlNav) {
  1141. methods.controlNav.setup();
  1142. }
  1143. // DIRECTIONNAV:
  1144. if (slider.vars.directionNav) {
  1145. methods.directionNav.setup();
  1146. }
  1147. // KEYBOARD:
  1148. if (slider.vars.keyboard && ($(slider.containerSelector).length === 1 || slider.vars.multipleKeyboard)) {
  1149. $(document).bind('keyup', function(event) {
  1150. var keycode = event.keyCode;
  1151. if (!slider.animating && (keycode === 39 || keycode === 37)) {
  1152. var target = (keycode === 39) ? slider.getTarget('next') :
  1153. (keycode === 37) ? slider.getTarget('prev') : false;
  1154. slider.flexAnimate(target, slider.vars.pauseOnAction);
  1155. }
  1156. });
  1157. }
  1158. // MOUSEWHEEL:
  1159. if (slider.vars.mousewheel) {
  1160. slider.bind('mousewheel', function(event, delta, deltaX, deltaY) {
  1161. event.preventDefault();
  1162. var target = (delta < 0) ? slider.getTarget('next') : slider.getTarget('prev');
  1163. slider.flexAnimate(target, slider.vars.pauseOnAction);
  1164. });
  1165. }
  1166. // PAUSEPLAY
  1167. if (slider.vars.pausePlay) {
  1168. methods.pausePlay.setup();
  1169. }
  1170. //PAUSE WHEN INVISIBLE
  1171. if (slider.vars.slideshow && slider.vars.pauseInvisible) {
  1172. methods.pauseInvisible.init();
  1173. }
  1174. // SLIDSESHOW
  1175. if (slider.vars.slideshow) {
  1176. if (slider.vars.pauseOnHover) {
  1177. slider.hover(function() {
  1178. if (!slider.manualPlay && !slider.manualPause) {slider.pause();}
  1179. }, function() {
  1180. if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {slider.play();}
  1181. });
  1182. }
  1183. // initialize animation
  1184. // If we're visible, or we don't use PageVisibility API
  1185. if (!slider.vars.pauseInvisible || !methods.pauseInvisible.isHidden()) {
  1186. (slider.vars.initDelay > 0) ? slider.startTimeout = setTimeout(slider.play, slider.vars.initDelay) : slider.play();
  1187. }
  1188. }
  1189. // ASNAV:
  1190. if (asNav) {methods.asNav.setup();}
  1191. // TOUCH
  1192. if (touch && slider.vars.touch) {methods.touch();}
  1193. // FADE&&SMOOTHHEIGHT || SLIDE:
  1194. if (!fade || (fade && slider.vars.smoothHeight)) {$(window).bind("resize orientationchange focus", methods.resize);}
  1195. slider.find("img").attr("draggable", "false");
  1196. // API: start() Callback
  1197. setTimeout(function() {
  1198. slider.vars.start(slider);
  1199. }, 200);
  1200. },
  1201. asNav: {
  1202. setup: function() {
  1203. slider.asNav = true;
  1204. slider.animatingTo = Math.floor(slider.currentSlide / slider.move);
  1205. slider.currentItem = slider.currentSlide;
  1206. slider.slides.removeClass(namespace + "active-slide").eq(slider.currentItem).addClass(namespace + "active-slide");
  1207. if (!msGesture) {
  1208. slider.slides.on(eventType, function(e) {
  1209. e.preventDefault();
  1210. var $slide = $(this),
  1211. target = $slide.index();
  1212. var posFromLeft = $slide.offset().left - $(slider).scrollLeft(); // Find position of slide relative to left of slider container
  1213. if (posFromLeft <= 0 && $slide.hasClass(namespace + 'active-slide')) {
  1214. slider.flexAnimate(slider.getTarget("prev"), true);
  1215. } else if (!$(slider.vars.asNavFor).data('flexslider').animating && !$slide.hasClass(namespace + "active-slide")) {
  1216. slider.direction = (slider.currentItem < target) ? "next" : "prev";
  1217. slider.flexAnimate(target, slider.vars.pauseOnAction, false, true, true);
  1218. }
  1219. });
  1220. } else {
  1221. el._slider = slider;
  1222. slider.slides.each(function() {
  1223. var that = this;
  1224. that._gesture = new MSGesture();
  1225. that._gesture.target = that;
  1226. that.addEventListener("MSPointerDown", function(e) {
  1227. e.preventDefault();
  1228. if (e.currentTarget._gesture) {
  1229. e.currentTarget._gesture.addPointer(e.pointerId);
  1230. }
  1231. }, false);
  1232. that.addEventListener("MSGestureTap", function(e) {
  1233. e.preventDefault();
  1234. var $slide = $(this),
  1235. target = $slide.index();
  1236. if (!$(slider.vars.asNavFor).data('flexslider').animating && !$slide.hasClass('active')) {
  1237. slider.direction = (slider.currentItem < target) ? "next" : "prev";
  1238. slider.flexAnimate(target, slider.vars.pauseOnAction, false, true, true);
  1239. }
  1240. });
  1241. });
  1242. }
  1243. }
  1244. },
  1245. controlNav: {
  1246. setup: function() {
  1247. if (!slider.manualControls) {
  1248. methods.controlNav.setupPaging();
  1249. } else { // MANUALCONTROLS:
  1250. methods.controlNav.setupManual();
  1251. }
  1252. },
  1253. setupPaging: function() {
  1254. var type = (slider.vars.controlNav === "thumbnails") ? 'control-thumbs' : 'control-paging',
  1255. j = 1,
  1256. item,
  1257. slide;
  1258. slider.controlNavScaffold = $('<ol class="' + namespace + 'control-nav ' + namespace + type + '"></ol>');
  1259. if (slider.pagingCount > 1) {
  1260. for (var i = 0; i < slider.pagingCount; i++) {
  1261. slide = slider.slides.eq(i);
  1262. item = (slider.vars.controlNav === "thumbnails") ? '<img src="' + slide.attr('data-thumb') + '"/>' : '<a>' + j + '</a>';
  1263. if ('thumbnails' === slider.vars.controlNav && true === slider.vars.thumbCaptions) {
  1264. var captn = slide.attr('data-thumbcaption');
  1265. if ('' != captn && undefined != captn) {item += '<span class="' + namespace + 'caption">' + captn + '</span>'};
  1266. }
  1267. // slider.controlNavScaffold.append('<li>' + item + '</li>');
  1268. slider.controlNavScaffold.append('<li>' + item + '<i></i></li>');
  1269. j++;
  1270. }
  1271. }
  1272. // CONTROLSCONTAINER:
  1273. (slider.controlsContainer) ? $(slider.controlsContainer).append(slider.controlNavScaffold) : slider.append(slider.controlNavScaffold);
  1274. methods.controlNav.set();
  1275. methods.controlNav.active();
  1276. slider.controlNavScaffold.delegate('a, img', eventType, function(event) {
  1277. event.preventDefault();
  1278. if (watchedEvent === "" || watchedEvent === event.type) {
  1279. var $this = $(this),
  1280. target = slider.controlNav.index($this);
  1281. if (!$this.hasClass(namespace + 'active')) {
  1282. slider.direction = (target > slider.currentSlide) ? "next" : "prev";
  1283. slider.flexAnimate(target, slider.vars.pauseOnAction);
  1284. }
  1285. }
  1286. // setup flags to prevent event duplication
  1287. if (watchedEvent === "") {
  1288. watchedEvent = event.type;
  1289. }
  1290. methods.setToClearWatchedEvent();
  1291. });
  1292. },
  1293. setupManual: function() {
  1294. slider.controlNav = slider.manualControls;
  1295. methods.controlNav.active();
  1296. slider.controlNav.bind(eventType, function(event) {
  1297. event.preventDefault();
  1298. if (watchedEvent === "" || watchedEvent === event.type) {
  1299. var $this = $(this),
  1300. target = slider.controlNav.index($this);
  1301. if (!$this.hasClass(namespace + 'active')) {
  1302. (target > slider.currentSlide) ? slider.direction = "next" : slider.direction = "prev";
  1303. slider.flexAnimate(target, slider.vars.pauseOnAction);
  1304. }
  1305. }
  1306. // setup flags to prevent event duplication
  1307. if (watchedEvent === "") {
  1308. watchedEvent = event.type;
  1309. }
  1310. methods.setToClearWatchedEvent();
  1311. });
  1312. },
  1313. set: function() {
  1314. var selector = (slider.vars.controlNav === "thumbnails") ? 'img' : 'a';
  1315. slider.controlNav = $('.' + namespace + 'control-nav li ' + selector, (slider.controlsContainer) ? slider.controlsContainer : slider);
  1316. },
  1317. active: function() {
  1318. slider.controlNav.removeClass(namespace + "active").eq(slider.animatingTo).addClass(namespace + "active");
  1319. },
  1320. update: function(action, pos) {
  1321. if (slider.pagingCount > 1 && action === "add") {
  1322. slider.controlNavScaffold.append($('<li><a>' + slider.count + '</a></li>'));
  1323. } else if (slider.pagingCount === 1) {
  1324. slider.controlNavScaffold.find('li').remove();
  1325. } else {
  1326. slider.controlNav.eq(pos).closest('li').remove();
  1327. }
  1328. methods.controlNav.set();
  1329. (slider.pagingCount > 1 && slider.pagingCount !== slider.controlNav.length) ? slider.update(pos, action) : methods.controlNav.active();
  1330. }
  1331. },
  1332. directionNav: {
  1333. setup: function() {
  1334. var directionNavScaffold = $('<ul class="' + namespace + 'direction-nav"><li class="' + namespace + 'nav-prev"><a class="' + namespace + 'prev" href="#">' + slider.vars.prevText + '</a></li><li class="' + namespace + 'nav-next"><a class="' + namespace + 'next" href="#">' + slider.vars.nextText + '</a></li></ul>');
  1335. // CONTROLSCONTAINER:
  1336. if (slider.controlsContainer) {
  1337. $(slider.controlsContainer).append(directionNavScaffold);
  1338. slider.directionNav = $('.' + namespace + 'direction-nav li a', slider.controlsContainer);
  1339. } else {
  1340. slider.append(directionNavScaffold);
  1341. slider.directionNav = $('.' + namespace + 'direction-nav li a', slider);
  1342. }
  1343. methods.directionNav.update();
  1344. slider.directionNav.bind(eventType, function(event) {
  1345. event.preventDefault();
  1346. var target;
  1347. if (watchedEvent === "" || watchedEvent === event.type) {
  1348. target = ($(this).hasClass(namespace + 'next')) ? slider.getTarget('next') : slider.getTarget('prev');
  1349. slider.flexAnimate(target, slider.vars.pauseOnAction);
  1350. }
  1351. // setup flags to prevent event duplication
  1352. if (watchedEvent === "") {
  1353. watchedEvent = event.type;
  1354. }
  1355. methods.setToClearWatchedEvent();
  1356. });
  1357. },
  1358. update: function() {
  1359. var disabledClass = namespace + 'disabled';
  1360. if (slider.pagingCount === 1) {
  1361. slider.directionNav.addClass(disabledClass).attr('tabindex', '-1');
  1362. } else if (!slider.vars.animationLoop) {
  1363. if (slider.animatingTo === 0) {
  1364. slider.directionNav.removeClass(disabledClass).filter('.' + namespace + "prev").addClass(disabledClass).attr('tabindex', '-1');
  1365. } else if (slider.animatingTo === slider.last) {
  1366. slider.directionNav.removeClass(disabledClass).filter('.' + namespace + "next").addClass(disabledClass).attr('tabindex', '-1');
  1367. } else {
  1368. slider.directionNav.removeClass(disabledClass).removeAttr('tabindex');
  1369. }
  1370. } else {
  1371. slider.directionNav.removeClass(disabledClass).removeAttr('tabindex');
  1372. }
  1373. }
  1374. },
  1375. pausePlay: {
  1376. setup: function() {
  1377. var pausePlayScaffold = $('<div class="' + namespace + 'pauseplay"><a></a></div>');
  1378. // CONTROLSCONTAINER:
  1379. if (slider.controlsContainer) {
  1380. slider.controlsContainer.append(pausePlayScaffold);
  1381. slider.pausePlay = $('.' + namespace + 'pauseplay a', slider.controlsContainer);
  1382. } else {
  1383. slider.append(pausePlayScaffold);
  1384. slider.pausePlay = $('.' + namespace + 'pauseplay a', slider);
  1385. }
  1386. methods.pausePlay.update((slider.vars.slideshow) ? namespace + 'pause' : namespace + 'play');
  1387. slider.pausePlay.bind(eventType, function(event) {
  1388. event.preventDefault();
  1389. if (watchedEvent === "" || watchedEvent === event.type) {
  1390. if ($(this).hasClass(namespace + 'pause')) {
  1391. slider.manualPause = true;
  1392. slider.manualPlay = false;
  1393. slider.pause();
  1394. } else {
  1395. slider.manualPause = false;
  1396. slider.manualPlay = true;
  1397. slider.play();
  1398. }
  1399. }
  1400. // setup flags to prevent event duplication
  1401. if (watchedEvent === "") {
  1402. watchedEvent = event.type;
  1403. }
  1404. methods.setToClearWatchedEvent();
  1405. });
  1406. },
  1407. update: function(state) {
  1408. (state === "play") ? slider.pausePlay.removeClass(namespace + 'pause').addClass(namespace + 'play').html(slider.vars.playText) : slider.pausePlay.removeClass(namespace + 'play').addClass(namespace + 'pause').html(slider.vars.pauseText);
  1409. }
  1410. },
  1411. touch: function() {
  1412. var startX,
  1413. startY,
  1414. offset,
  1415. cwidth,
  1416. dx,
  1417. startT,
  1418. scrolling = false,
  1419. localX = 0,
  1420. localY = 0,
  1421. accDx = 0;
  1422. if (!msGesture) {
  1423. el.addEventListener('touchstart', onTouchStart, false);
  1424. function onTouchStart(e) {
  1425. if (slider.animating) {
  1426. e.preventDefault();
  1427. } else if (( window.navigator.msPointerEnabled ) || e.touches.length === 1) {
  1428. slider.pause();
  1429. // CAROUSEL:
  1430. cwidth = (vertical) ? slider.h : slider.w;
  1431. startT = Number(new Date());
  1432. // CAROUSEL:
  1433. // Local vars for X and Y points.
  1434. localX = e.touches[0].pageX;
  1435. localY = e.touches[0].pageY;
  1436. offset = (carousel && reverse && slider.animatingTo === slider.last) ? 0 :
  1437. (carousel && reverse) ? slider.limit - (((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo) :
  1438. (carousel && slider.currentSlide === slider.last) ? slider.limit :
  1439. (carousel) ? ((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.currentSlide :
  1440. (reverse) ? (slider.last - slider.currentSlide + slider.cloneOffset) * cwidth : (slider.currentSlide + slider.cloneOffset) * cwidth;
  1441. startX = (vertical) ? localY : localX;
  1442. startY = (vertical) ? localX : localY;
  1443. el.addEventListener('touchmove', onTouchMove, false);
  1444. el.addEventListener('touchend', onTouchEnd, false);
  1445. }
  1446. }
  1447. function onTouchMove(e) {
  1448. // Local vars for X and Y points.
  1449. localX = e.touches[0].pageX;
  1450. localY = e.touches[0].pageY;
  1451. dx = (vertical) ? startX - localY : startX - localX;
  1452. scrolling = (vertical) ? (Math.abs(dx) < Math.abs(localX - startY)) : (Math.abs(dx) < Math.abs(localY - startY));
  1453. var fxms = 500;
  1454. if (!scrolling || Number(new Date()) - startT > fxms) {
  1455. e.preventDefault();
  1456. if (!fade && slider.transitions) {
  1457. if (!slider.vars.animationLoop) {
  1458. dx = dx / ((slider.currentSlide === 0 && dx < 0 || slider.currentSlide === slider.last && dx > 0) ? (Math.abs(dx) / cwidth + 2) : 1);
  1459. }
  1460. slider.setProps(offset + dx, "setTouch");
  1461. }
  1462. }
  1463. }
  1464. function onTouchEnd(e) {
  1465. // finish the touch by undoing the touch session
  1466. el.removeEventListener('touchmove', onTouchMove, false);
  1467. if (slider.animatingTo === slider.currentSlide && !scrolling && !(dx === null)) {
  1468. var updateDx = (reverse) ? -dx : dx,
  1469. target = (updateDx > 0) ? slider.getTarget('next') : slider.getTarget('prev');
  1470. if (slider.canAdvance(target) && (Number(new Date()) - startT < 550 && Math.abs(updateDx) > 50 || Math.abs(updateDx) > cwidth / 2)) {
  1471. slider.flexAnimate(target, slider.vars.pauseOnAction);
  1472. } else {
  1473. if (!fade) {slider.flexAnimate(slider.currentSlide, slider.vars.pauseOnAction, true);}
  1474. }
  1475. }
  1476. el.removeEventListener('touchend', onTouchEnd, false);
  1477. startX = null;
  1478. startY = null;
  1479. dx = null;
  1480. offset = null;
  1481. }
  1482. } else {
  1483. el.style.msTouchAction = "none";
  1484. el._gesture = new MSGesture();
  1485. el._gesture.target = el;
  1486. el.addEventListener("MSPointerDown", onMSPointerDown, false);
  1487. el._slider = slider;
  1488. el.addEventListener("MSGestureChange", onMSGestureChange, false);
  1489. el.addEventListener("MSGestureEnd", onMSGestureEnd, false);
  1490. function onMSPointerDown(e) {
  1491. e.stopPropagation();
  1492. if (slider.animating) {
  1493. e.preventDefault();
  1494. } else {
  1495. slider.pause();
  1496. el._gesture.addPointer(e.pointerId);
  1497. accDx = 0;
  1498. cwidth = (vertical) ? slider.h : slider.w;
  1499. startT = Number(new Date());
  1500. // CAROUSEL:
  1501. offset = (carousel && reverse && slider.animatingTo === slider.last) ? 0 :
  1502. (carousel && reverse) ? slider.limit - (((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo) :
  1503. (carousel && slider.currentSlide === slider.last) ? slider.limit :
  1504. (carousel) ? ((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.currentSlide :
  1505. (reverse) ? (slider.last - slider.currentSlide + slider.cloneOffset) * cwidth : (slider.currentSlide + slider.cloneOffset) * cwidth;
  1506. }
  1507. }
  1508. function onMSGestureChange(e) {
  1509. e.stopPropagation();
  1510. var slider = e.target._slider;
  1511. if (!slider) {
  1512. return;
  1513. }
  1514. var transX = -e.translationX,
  1515. transY = -e.translationY;
  1516. //Accumulate translations.
  1517. accDx = accDx + ((vertical) ? transY : transX);
  1518. dx = accDx;
  1519. scrolling = (vertical) ? (Math.abs(accDx) < Math.abs(-transX)) : (Math.abs(accDx) < Math.abs(-transY));
  1520. if (e.detail === e.MSGESTURE_FLAG_INERTIA) {
  1521. setImmediate(function() {
  1522. el._gesture.stop();
  1523. });
  1524. return;
  1525. }
  1526. if (!scrolling || Number(new Date()) - startT > 500) {
  1527. e.preventDefault();
  1528. if (!fade && slider.transitions) {
  1529. if (!slider.vars.animationLoop) {
  1530. dx = accDx / ((slider.currentSlide === 0 && accDx < 0 || slider.currentSlide === slider.last && accDx > 0) ? (Math.abs(accDx) / cwidth + 2) : 1);
  1531. }
  1532. slider.setProps(offset + dx, "setTouch");
  1533. }
  1534. }
  1535. }
  1536. function onMSGestureEnd(e) {
  1537. e.stopPropagation();
  1538. var slider = e.target._slider;
  1539. if (!slider) {
  1540. return;
  1541. }
  1542. if (slider.animatingTo === slider.currentSlide && !scrolling && !(dx === null)) {
  1543. var updateDx = (reverse) ? -dx : dx,
  1544. target = (updateDx > 0) ? slider.getTarget('next') : slider.getTarget('prev');
  1545. if (slider.canAdvance(target) && (Number(new Date()) - startT < 550 && Math.abs(updateDx) > 50 || Math.abs(updateDx) > cwidth / 2)) {
  1546. slider.flexAnimate(target, slider.vars.pauseOnAction);
  1547. } else {
  1548. if (!fade) {slider.flexAnimate(slider.currentSlide, slider.vars.pauseOnAction, true);}
  1549. }
  1550. }
  1551. startX = null;
  1552. startY = null;
  1553. dx = null;
  1554. offset = null;
  1555. accDx = 0;
  1556. }
  1557. }
  1558. },
  1559. resize: function() {
  1560. if (!slider.animating && slider.is(':visible')) {
  1561. if (!carousel) {slider.doMath()};
  1562. if (fade) {
  1563. // SMOOTH HEIGHT:
  1564. methods.smoothHeight();
  1565. } else if (carousel) { //CAROUSEL:
  1566. slider.slides.width(slider.computedW);
  1567. slider.update(slider.pagingCount);
  1568. slider.setProps();
  1569. }
  1570. else if (vertical) { //VERTICAL:
  1571. slider.viewport.height(slider.h);
  1572. slider.setProps(slider.h, "setTotal");
  1573. } else {
  1574. // SMOOTH HEIGHT:
  1575. if (slider.vars.smoothHeight) {methods.smoothHeight();}
  1576. slider.newSlides.width(slider.computedW);
  1577. slider.setProps(slider.computedW, "setTotal");
  1578. }
  1579. }
  1580. },
  1581. smoothHeight: function(dur) {
  1582. if (!vertical || fade) {
  1583. var $obj = (fade) ? slider : slider.viewport;
  1584. (dur) ? $obj.animate({"height": slider.slides.eq(slider.animatingTo).height()}, dur) : $obj.height(slider.slides.eq(slider.animatingTo).height());
  1585. }
  1586. },
  1587. sync: function(action) {
  1588. var $obj = $(slider.vars.sync).data("flexslider"),
  1589. target = slider.animatingTo;
  1590. switch (action) {
  1591. case "animate":
  1592. $obj.flexAnimate(target, slider.vars.pauseOnAction, false, true);
  1593. break;
  1594. case "play":
  1595. if (!$obj.playing && !$obj.asNav) {
  1596. $obj.play();
  1597. }
  1598. break;
  1599. case "pause":
  1600. $obj.pause();
  1601. break;
  1602. }
  1603. },
  1604. uniqueID: function($clone) {
  1605. // Append _clone to current level and children elements with id attributes
  1606. $clone.filter('[id]').add($clone.find('[id]')).each(function() {
  1607. var $this = $(this);
  1608. $this.attr('id', $this.attr('id') + '_clone');
  1609. });
  1610. return $clone;
  1611. },
  1612. pauseInvisible: {
  1613. visProp: null,
  1614. init: function() {
  1615. var visProp = methods.pauseInvisible.getHiddenProp();
  1616. if (visProp) {
  1617. var evtname = visProp.replace(/[H|h]idden/,'') + 'visibilitychange';
  1618. document.addEventListener(evtname, function() {
  1619. if (methods.pauseInvisible.isHidden()) {
  1620. if(slider.startTimeout) {
  1621. clearTimeout(slider.startTimeout); //If clock is ticking, stop timer and prevent from starting while invisible
  1622. } else {
  1623. slider.pause(); //Or just pause
  1624. }
  1625. }
  1626. else {
  1627. if(slider.started) {
  1628. slider.play(); //Initiated before, just play
  1629. } else {
  1630. if (slider.vars.initDelay > 0) {
  1631. setTimeout(slider.play, slider.vars.initDelay);
  1632. } else {
  1633. slider.play(); //Didn't init before: simply init or wait for it
  1634. }
  1635. }
  1636. }
  1637. });
  1638. }
  1639. },
  1640. isHidden: function() {
  1641. var prop = methods.pauseInvisible.getHiddenProp();
  1642. if (!prop) {
  1643. return false;
  1644. }
  1645. return document[prop];
  1646. },
  1647. getHiddenProp: function() {
  1648. var prefixes = ['webkit','moz','ms','o'];
  1649. // if 'hidden' is natively supported just return it
  1650. if ('hidden' in document) {
  1651. return 'hidden';
  1652. }
  1653. // otherwise loop over all the known prefixes until we find one
  1654. for (var i = 0; i < prefixes.length; i++ ) {
  1655. if ((prefixes[i] + 'Hidden') in document) {
  1656. return prefixes[i] + 'Hidden';
  1657. }
  1658. }
  1659. // otherwise it's not supported
  1660. return null;
  1661. }
  1662. },
  1663. setToClearWatchedEvent: function() {
  1664. clearTimeout(watchedEventClearTimer);
  1665. watchedEventClearTimer = setTimeout(function() {
  1666. watchedEvent = "";
  1667. }, 3000);
  1668. }
  1669. };
  1670. // public methods
  1671. slider.flexAnimate = function(target, pause, override, withSync, fromNav) {
  1672. if (!slider.vars.animationLoop && target !== slider.currentSlide) {
  1673. slider.direction = (target > slider.currentSlide) ? "next" : "prev";
  1674. }
  1675. if (asNav && slider.pagingCount === 1) slider.direction = (slider.currentItem < target) ? "next" : "prev";
  1676. if (!slider.animating && (slider.canAdvance(target, fromNav) || override) && slider.is(":visible")) {
  1677. if (asNav && withSync) {
  1678. var master = $(slider.vars.asNavFor).data('flexslider');
  1679. slider.atEnd = target === 0 || target === slider.count - 1;
  1680. master.flexAnimate(target, true, false, true, fromNav);
  1681. slider.direction = (slider.currentItem < target) ? "next" : "prev";
  1682. master.direction = slider.direction;
  1683. if (Math.ceil((target + 1) / slider.visible) - 1 !== slider.currentSlide && target !== 0) {
  1684. slider.currentItem = target;
  1685. slider.slides.removeClass(namespace + "active-slide").eq(target).addClass(namespace + "active-slide");
  1686. target = Math.floor(target / slider.visible);
  1687. } else {
  1688. slider.currentItem = target;
  1689. slider.slides.removeClass(namespace + "active-slide").eq(target).addClass(namespace + "active-slide");
  1690. return false;
  1691. }
  1692. }
  1693. slider.animating = true;
  1694. slider.animatingTo = target;
  1695. // SLIDESHOW:
  1696. if (pause) {slider.pause();}
  1697. // API: before() animation Callback
  1698. slider.vars.before(slider);
  1699. // SYNC:
  1700. if (slider.syncExists && !fromNav) {methods.sync("animate");}
  1701. // CONTROLNAV
  1702. if (slider.vars.controlNav) {methods.controlNav.active();}
  1703. // !CAROUSEL:
  1704. // CANDIDATE: slide active class (for add/remove slide)
  1705. if (!carousel) {slider.slides.removeClass(namespace + 'active-slide').eq(target).addClass(namespace + 'active-slide');}
  1706. // INFINITE LOOP:
  1707. // CANDIDATE: atEnd
  1708. slider.atEnd = target === 0 || target === slider.last;
  1709. // DIRECTIONNAV:
  1710. if (slider.vars.directionNav) {methods.directionNav.update();}
  1711. if (target === slider.last) {
  1712. // API: end() of cycle Callback
  1713. slider.vars.end(slider);
  1714. // SLIDESHOW && !INFINITE LOOP:
  1715. if (!slider.vars.animationLoop) {slider.pause();}
  1716. }
  1717. // SLIDE:
  1718. if (!fade) {
  1719. var dimension = (vertical) ? slider.slides.filter(':first').height() : slider.computedW,
  1720. margin, slideString, calcNext;
  1721. // INFINITE LOOP / REVERSE:
  1722. if (carousel) {
  1723. //margin = (slider.vars.itemWidth > slider.w) ? slider.vars.itemMargin * 2 : slider.vars.itemMargin;
  1724. margin = slider.vars.itemMargin;
  1725. calcNext = ((slider.itemW + margin) * slider.move) * slider.animatingTo;
  1726. slideString = (calcNext > slider.limit && slider.visible !== 1) ? slider.limit : calcNext;
  1727. } else if (slider.currentSlide === 0 && target === slider.count - 1 && slider.vars.animationLoop && slider.direction !== "next") {
  1728. slideString = (reverse) ? (slider.count + slider.cloneOffset) * dimension : 0;
  1729. } else if (slider.currentSlide === slider.last && target === 0 && slider.vars.animationLoop && slider.direction !== "prev") {
  1730. slideString = (reverse) ? 0 : (slider.count + 1) * dimension;
  1731. } else {
  1732. slideString = (reverse) ? ((slider.count - 1) - target + slider.cloneOffset) * dimension : (target + slider.cloneOffset) * dimension;
  1733. }
  1734. slider.setProps(slideString, "", slider.vars.animationSpeed);
  1735. if (slider.transitions) {
  1736. if (!slider.vars.animationLoop || !slider.atEnd) {
  1737. slider.animating = false;
  1738. slider.currentSlide = slider.animatingTo;
  1739. }
  1740. // Unbind previous transitionEnd events and re-bind new transitionEnd event
  1741. slider.container.unbind("webkitTransitionEnd transitionend");
  1742. slider.container.bind("webkitTransitionEnd transitionend", function() {
  1743. clearTimeout(slider.ensureAnimationEnd);
  1744. slider.wrapup(dimension);
  1745. });
  1746. // Insurance for the ever-so-fickle transitionEnd event
  1747. clearTimeout(slider.ensureAnimationEnd);
  1748. slider.ensureAnimationEnd = setTimeout(function() {
  1749. slider.wrapup(dimension);
  1750. }, slider.vars.animationSpeed + 100);
  1751. } else {
  1752. slider.container.animate(slider.args, slider.vars.animationSpeed, slider.vars.easing, function(){
  1753. slider.wrapup(dimension);
  1754. });
  1755. }
  1756. } else { // FADE:
  1757. if (!touch) {
  1758. //slider.slides.eq(slider.currentSlide).fadeOut(slider.vars.animationSpeed, slider.vars.easing);
  1759. //slider.slides.eq(target).fadeIn(slider.vars.animationSpeed, slider.vars.easing, slider.wrapup);
  1760. slider.slides.eq(slider.currentSlide).css({"zIndex": 1}).animate({"opacity": 0}, slider.vars.animationSpeed, slider.vars.easing);
  1761. slider.slides.eq(target).css({"zIndex": 2}).animate({"opacity": 1}, slider.vars.animationSpeed, slider.vars.easing, slider.wrapup);
  1762. } else {
  1763. slider.slides.eq(slider.currentSlide).css({
  1764. "opacity": 0,
  1765. "zIndex": 1
  1766. });
  1767. slider.slides.eq(target).css({"opacity": 1, "zIndex": 2});
  1768. slider.wrapup(dimension);
  1769. }
  1770. }
  1771. // SMOOTH HEIGHT:
  1772. if (slider.vars.smoothHeight) {methods.smoothHeight(slider.vars.animationSpeed)};
  1773. }
  1774. };
  1775. slider.wrapup = function(dimension) {
  1776. // SLIDE:
  1777. if (!fade && !carousel) {
  1778. if (slider.currentSlide === 0 && slider.animatingTo === slider.last && slider.vars.animationLoop) {
  1779. slider.setProps(dimension, "jumpEnd");
  1780. } else if (slider.currentSlide === slider.last && slider.animatingTo === 0 && slider.vars.animationLoop) {
  1781. slider.setProps(dimension, "jumpStart");
  1782. }
  1783. }
  1784. slider.animating = false;
  1785. slider.currentSlide = slider.animatingTo;
  1786. // API: after() animation Callback
  1787. slider.vars.after(slider);
  1788. };
  1789. // SLIDESHOW:
  1790. slider.animateSlides = function() {
  1791. if (!slider.animating && focused) {slider.flexAnimate(slider.getTarget("next"));}
  1792. };
  1793. // SLIDESHOW:
  1794. slider.pause = function() {
  1795. clearInterval(slider.animatedSlides);
  1796. slider.animatedSlides = null;
  1797. slider.playing = false;
  1798. // PAUSEPLAY:
  1799. if (slider.vars.pausePlay) {methods.pausePlay.update("play");}
  1800. // SYNC:
  1801. if (slider.syncExists) {methods.sync("pause");}
  1802. };
  1803. // SLIDESHOW:
  1804. slider.play = function() {
  1805. if (slider.playing) {clearInterval(slider.animatedSlides);}
  1806. slider.animatedSlides = slider.animatedSlides || setInterval(slider.animateSlides, slider.vars.slideshowSpeed);
  1807. slider.started = slider.playing = true;
  1808. // PAUSEPLAY:
  1809. if (slider.vars.pausePlay) {methods.pausePlay.update("pause");}
  1810. // SYNC:
  1811. if (slider.syncExists) {methods.sync("play");}
  1812. };
  1813. // STOP:
  1814. slider.stop = function() {
  1815. slider.pause();
  1816. slider.stopped = true;
  1817. };
  1818. slider.canAdvance = function(target, fromNav) {
  1819. // ASNAV:
  1820. var last = (asNav) ? slider.pagingCount - 1 : slider.last;
  1821. return (fromNav) ? true :
  1822. (asNav && slider.currentItem === slider.count - 1 && target === 0 && slider.direction === "prev") ? true :
  1823. (asNav && slider.currentItem === 0 && target === slider.pagingCount - 1 && slider.direction !== "next") ? false :
  1824. (target === slider.currentSlide && !asNav) ? false :
  1825. (slider.vars.animationLoop) ? true :
  1826. (slider.atEnd && slider.currentSlide === 0 && target === last && slider.direction !== "next") ? false :
  1827. (slider.atEnd && slider.currentSlide === last && target === 0 && slider.direction === "next") ? false :
  1828. true;
  1829. };
  1830. slider.getTarget = function(dir) {
  1831. slider.direction = dir;
  1832. if (dir === "next") {
  1833. return (slider.currentSlide === slider.last) ? 0 : slider.currentSlide + 1;
  1834. } else {
  1835. return (slider.currentSlide === 0) ? slider.last : slider.currentSlide - 1;
  1836. }
  1837. };
  1838. // SLIDE:
  1839. slider.setProps = function(pos, special, dur) {
  1840. var target = (function() {
  1841. var posCheck = (pos) ? pos : ((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo,
  1842. posCalc = (function() {
  1843. if (carousel) {
  1844. return (special === "setTouch") ? pos :
  1845. (reverse && slider.animatingTo === slider.last) ? 0 :
  1846. (reverse) ? slider.limit - (((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo) :
  1847. (slider.animatingTo === slider.last) ? slider.limit : posCheck;
  1848. } else {
  1849. switch (special) {
  1850. case "setTotal":
  1851. return (reverse) ? ((slider.count - 1) - slider.currentSlide + slider.cloneOffset) * pos : (slider.currentSlide + slider.cloneOffset) * pos;
  1852. case "setTouch":
  1853. return (reverse) ? pos : pos;
  1854. case "jumpEnd":
  1855. return (reverse) ? pos : slider.count * pos;
  1856. case "jumpStart":
  1857. return (reverse) ? slider.count * pos : pos;
  1858. default:
  1859. return pos;
  1860. }
  1861. }
  1862. }());
  1863. return (posCalc * -1) + "px";
  1864. }());
  1865. if (slider.transitions) {
  1866. target = (vertical) ? "translate3d(0," + target + ",0)" : "translate3d(" + target + ",0,0)";
  1867. dur = (dur !== undefined) ? (dur / 1000) + "s" : "0s";
  1868. slider.container.css("-" + slider.pfx + "-transition-duration", dur);
  1869. slider.container.css("transition-duration", dur);
  1870. }
  1871. slider.args[slider.prop] = target;
  1872. if (slider.transitions || dur === undefined) {slider.container.css(slider.args);}
  1873. slider.container.css('transform', target);
  1874. };
  1875. slider.setup = function(type) {
  1876. // SLIDE:
  1877. if (!fade) {
  1878. var sliderOffset, arr;
  1879. if (type === "init") {
  1880. slider.viewport = $('<div class="' + namespace + 'viewport"></div>').css({
  1881. "overflow": "hidden",
  1882. "position": "relative"
  1883. }).appendTo(slider).append(slider.container);
  1884. // INFINITE LOOP:
  1885. slider.cloneCount = 0;
  1886. slider.cloneOffset = 0;
  1887. // REVERSE:
  1888. if (reverse) {
  1889. arr = $.makeArray(slider.slides).reverse();
  1890. slider.slides = $(arr);
  1891. slider.container.empty().append(slider.slides);
  1892. }
  1893. }
  1894. // INFINITE LOOP && !CAROUSEL:
  1895. if (slider.vars.animationLoop && !carousel) {
  1896. slider.cloneCount = 2;
  1897. slider.cloneOffset = 1;
  1898. // clear out old clones
  1899. if (type !== "init") { slider.container.find('.clone').remove(); }
  1900. slider.container.append(methods.uniqueID(slider.slides.first().clone().addClass('clone')).attr('aria-hidden', 'true'))
  1901. .prepend(methods.uniqueID(slider.slides.last().clone().addClass('clone')).attr('aria-hidden', 'true'));
  1902. }
  1903. slider.newSlides = $(slider.vars.selector, slider);
  1904. sliderOffset = (reverse) ? slider.count - 1 - slider.currentSlide + slider.cloneOffset : slider.currentSlide + slider.cloneOffset;
  1905. // VERTICAL:
  1906. if (vertical && !carousel) {
  1907. slider.container.height((slider.count + slider.cloneCount) * 200 + "%").css("position", "absolute").width("100%");
  1908. setTimeout(function() {
  1909. slider.newSlides.css({"display": "block"});
  1910. slider.doMath();
  1911. slider.viewport.height(slider.h);
  1912. slider.setProps(sliderOffset * slider.h, "init");
  1913. }, (type === "init") ? 100 : 0);
  1914. } else {
  1915. slider.container.width((slider.count + slider.cloneCount) * 200 + "%");
  1916. slider.setProps(sliderOffset * slider.computedW, "init");
  1917. setTimeout(function() {
  1918. slider.doMath();
  1919. slider.newSlides.css({
  1920. "width": slider.computedW,
  1921. "float": "left",
  1922. "display": "block"
  1923. });
  1924. // SMOOTH HEIGHT:
  1925. if (slider.vars.smoothHeight) {methods.smoothHeight();}
  1926. }, (type === "init") ? 100 : 0);
  1927. }
  1928. } else { // FADE:
  1929. slider.slides.css({
  1930. "width": "100%",
  1931. "float": "left",
  1932. "marginRight": "-100%",
  1933. "position": "relative"
  1934. });
  1935. if (type === "init") {
  1936. if (!touch) {
  1937. //slider.slides.eq(slider.currentSlide).fadeIn(slider.vars.animationSpeed, slider.vars.easing);
  1938. if (slider.vars.fadeFirstSlide == false) {
  1939. slider.slides.css({ "opacity": 0, "display": "block", "zIndex": 1 }).eq(slider.currentSlide).css({"zIndex": 2}).css({"opacity": 1});
  1940. } else {
  1941. slider.slides.css({ "opacity": 0, "display": "block", "zIndex": 1 }).eq(slider.currentSlide).css({"zIndex": 2}).animate({"opacity": 1},slider.vars.animationSpeed,slider.vars.easing);
  1942. }
  1943. } else {
  1944. slider.slides.css({ "opacity": 0, "display": "block", "webkitTransition": "opacity " + slider.vars.animationSpeed / 1000 + "s ease", "zIndex": 1 }).eq(slider.currentSlide).css({ "opacity": 1, "zIndex": 2});
  1945. }
  1946. }
  1947. // SMOOTH HEIGHT:
  1948. if (slider.vars.smoothHeight) {methods.smoothHeight();}
  1949. }
  1950. // !CAROUSEL:
  1951. // CANDIDATE: active slide
  1952. if (!carousel) {slider.slides.removeClass(namespace + "active-slide").eq(slider.currentSlide).addClass(namespace + "active-slide");}
  1953. //FlexSlider: init() Callback
  1954. slider.vars.init(slider);
  1955. };
  1956. slider.doMath = function() {
  1957. var slide = slider.slides.first(),
  1958. slideMargin = slider.vars.itemMargin,
  1959. minItems = slider.vars.minItems,
  1960. maxItems = slider.vars.maxItems;
  1961. slider.w = (slider.viewport === undefined) ? slider.width() : slider.viewport.width();
  1962. slider.h = slide.height();
  1963. slider.boxPadding = slide.outerWidth() - slide.width();
  1964. // CAROUSEL:
  1965. if (carousel) {
  1966. slider.itemT = slider.vars.itemWidth + slideMargin;
  1967. slider.minW = (minItems) ? minItems * slider.itemT : slider.w;
  1968. slider.maxW = (maxItems) ? (maxItems * slider.itemT) - slideMargin : slider.w;
  1969. slider.itemW = (slider.minW > slider.w) ? (slider.w - (slideMargin * (minItems - 1))) / minItems :
  1970. (slider.maxW < slider.w) ? (slider.w - (slideMargin * (maxItems - 1))) / maxItems :
  1971. (slider.vars.itemWidth > slider.w) ? slider.w : slider.vars.itemWidth;
  1972. slider.visible = Math.floor(slider.w / (slider.itemW));
  1973. slider.move = (slider.vars.move > 0 && slider.vars.move < slider.visible ) ? slider.vars.move : slider.visible;
  1974. slider.pagingCount = Math.ceil(((slider.count - slider.visible) / slider.move) + 1);
  1975. slider.last = slider.pagingCount - 1;
  1976. slider.limit = (slider.pagingCount === 1) ? 0 :
  1977. (slider.vars.itemWidth > slider.w) ? (slider.itemW * (slider.count - 1)) + (slideMargin * (slider.count - 1)) : ((slider.itemW + slideMargin) * slider.count) - slider.w - slideMargin;
  1978. } else {
  1979. slider.itemW = slider.w;
  1980. slider.pagingCount = slider.count;
  1981. slider.last = slider.count - 1;
  1982. }
  1983. slider.computedW = slider.itemW - slider.boxPadding;
  1984. };
  1985. slider.update = function(pos, action) {
  1986. slider.doMath();
  1987. // update currentSlide and slider.animatingTo if necessary
  1988. if (!carousel) {
  1989. if (pos < slider.currentSlide) {
  1990. slider.currentSlide += 1;
  1991. } else if (pos <= slider.currentSlide && pos !== 0) {
  1992. slider.currentSlide -= 1;
  1993. }
  1994. slider.animatingTo = slider.currentSlide;
  1995. }
  1996. // update controlNav
  1997. if (slider.vars.controlNav && !slider.manualControls) {
  1998. if ((action === "add" && !carousel) || slider.pagingCount > slider.controlNav.length) {
  1999. methods.controlNav.update("add");
  2000. } else if ((action === "remove" && !carousel) || slider.pagingCount < slider.controlNav.length) {
  2001. if (carousel && slider.currentSlide > slider.last) {
  2002. slider.currentSlide -= 1;
  2003. slider.animatingTo -= 1;
  2004. }
  2005. methods.controlNav.update("remove", slider.last);
  2006. }
  2007. }
  2008. // update directionNav
  2009. if (slider.vars.directionNav) {methods.directionNav.update();}
  2010. };
  2011. slider.addSlide = function(obj, pos) {
  2012. var $obj = $(obj);
  2013. slider.count += 1;
  2014. slider.last = slider.count - 1;
  2015. // append new slide
  2016. if (vertical && reverse) {
  2017. (pos !== undefined) ? slider.slides.eq(slider.count - pos).after($obj) : slider.container.prepend($obj);
  2018. } else {
  2019. (pos !== undefined) ? slider.slides.eq(pos).before($obj) : slider.container.append($obj);
  2020. }
  2021. // update currentSlide, animatingTo, controlNav, and directionNav
  2022. slider.update(pos, "add");
  2023. // update slider.slides
  2024. slider.slides = $(slider.vars.selector + ':not(.clone)', slider);
  2025. // re-setup the slider to accomdate new slide
  2026. slider.setup();
  2027. //FlexSlider: added() Callback
  2028. slider.vars.added(slider);
  2029. };
  2030. slider.removeSlide = function(obj) {
  2031. var pos = (isNaN(obj)) ? slider.slides.index($(obj)) : obj;
  2032. // update count
  2033. slider.count -= 1;
  2034. slider.last = slider.count - 1;
  2035. // remove slide
  2036. if (isNaN(obj)) {
  2037. $(obj, slider.slides).remove();
  2038. } else {
  2039. (vertical && reverse) ? slider.slides.eq(slider.last).remove() : slider.slides.eq(obj).remove();
  2040. }
  2041. // update currentSlide, animatingTo, controlNav, and directionNav
  2042. slider.doMath();
  2043. slider.update(pos, "remove");
  2044. // update slider.slides
  2045. slider.slides = $(slider.vars.selector + ':not(.clone)', slider);
  2046. // re-setup the slider to accomdate new slide
  2047. slider.setup();
  2048. // FlexSlider: removed() Callback
  2049. slider.vars.removed(slider);
  2050. };
  2051. //FlexSlider: Initialize
  2052. methods.init();
  2053. };
  2054. // Ensure the slider isn't focussed if the window loses focus.
  2055. $(window).blur(function(e) {
  2056. focused = false;
  2057. }).focus(function(e) {
  2058. focused = true;
  2059. });
  2060. // FlexSlider: Default Settings
  2061. $.flexslider.defaults = {
  2062. namespace: "am-", //{NEW} String: Prefix string attached to the class of every element generated by the plugin
  2063. selector: ".am-slides > li", //{NEW} Selector: Must match a simple pattern. '{container} > {slide}' -- Ignore pattern at your own peril
  2064. animation: "slide", //String: Select your animation type, "fade" or "slide"
  2065. easing: "swing", //{NEW} String: Determines the easing method used in jQuery transitions. jQuery easing plugin is supported!
  2066. direction: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical"
  2067. reverse: false, //{NEW} Boolean: Reverse the animation direction
  2068. animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
  2069. smoothHeight: false, //{NEW} Boolean: Allow height of the slider to animate smoothly in horizontal mode
  2070. startAt: 0, //Integer: The slide that the slider should start on. Array notation (0 = first slide)
  2071. slideshow: true, //Boolean: Animate slider automatically
  2072. slideshowSpeed: 5000, //Integer: Set the speed of the slideshow cycling, in milliseconds
  2073. animationSpeed: 600, //Integer: Set the speed of animations, in milliseconds
  2074. initDelay: 0, //{NEW} Integer: Set an initialization delay, in milliseconds
  2075. randomize: false, //Boolean: Randomize slide order
  2076. fadeFirstSlide: true, //Boolean: Fade in the first slide when animation type is "fade"
  2077. thumbCaptions: false, //Boolean: Whether or not to put captions on thumbnails when using the "thumbnails" controlNav.
  2078. // Usability features
  2079. pauseOnAction: true, //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
  2080. pauseOnHover: false, //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
  2081. pauseInvisible: true, //{NEW} Boolean: Pause the slideshow when tab is invisible, resume when visible. Provides better UX, lower CPU usage.
  2082. useCSS: true, //{NEW} Boolean: Slider will use CSS3 transitions if available
  2083. touch: true, //{NEW} Boolean: Allow touch swipe navigation of the slider on touch-enabled devices
  2084. video: false, //{NEW} Boolean: If using video in the slider, will prevent CSS3 3D Transforms to avoid graphical glitches
  2085. // Primary Controls
  2086. controlNav: true, //Boolean: Create navigation for paging control of each slide? Note: Leave true for manualControls usage
  2087. directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false)
  2088. prevText: " ", //String: Set the text for the "previous" directionNav item
  2089. nextText: " ", //String: Set the text for the "next" directionNav item
  2090. // Secondary Navigation
  2091. keyboard: true, //Boolean: Allow slider navigating via keyboard left/right keys
  2092. multipleKeyboard: false, //{NEW} Boolean: Allow keyboard navigation to affect multiple sliders. Default behavior cuts out keyboard navigation with more than one slider present.
  2093. mousewheel: false, //{UPDATED} Boolean: Requires jquery.mousewheel.js (https://github.com/brandonaaron/jquery-mousewheel) - Allows slider navigating via mousewheel
  2094. pausePlay: false, //Boolean: Create pause/play dynamic element
  2095. pauseText: "Pause", //String: Set the text for the "pause" pausePlay item
  2096. playText: "Play", //String: Set the text for the "play" pausePlay item
  2097. // Special properties
  2098. controlsContainer: "", //{UPDATED} jQuery Object/Selector: Declare which container the navigation elements should be appended too. Default container is the FlexSlider element. Example use would be $(".flexslider-container"). Property is ignored if given element is not found.
  2099. manualControls: "", //{UPDATED} jQuery Object/Selector: Declare custom control navigation. Examples would be $(".flex-control-nav li") or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.
  2100. sync: "", //{NEW} Selector: Mirror the actions performed on this slider with another slider. Use with care.
  2101. asNavFor: "", //{NEW} Selector: Internal property exposed for turning the slider into a thumbnail navigation for another slider
  2102. // Carousel Options
  2103. itemWidth: 0, //{NEW} Integer: Box-model width of individual carousel items, including horizontal borders and padding.
  2104. itemMargin: 0, //{NEW} Integer: Margin between carousel items.
  2105. minItems: 1, //{NEW} Integer: Minimum number of carousel items that should be visible. Items will resize fluidly when below this.
  2106. maxItems: 0, //{NEW} Integer: Maxmimum number of carousel items that should be visible. Items will resize fluidly when above this limit.
  2107. move: 0, //{NEW} Integer: Number of carousel items that should move on animation. If 0, slider will move all visible items.
  2108. allowOneSlide: true, //{NEW} Boolean: Whether or not to allow a slider comprised of a single slide
  2109. // Callback API
  2110. start: function() {
  2111. }, //Callback: function(slider) - Fires when the slider loads the first slide
  2112. before: function() {
  2113. }, //Callback: function(slider) - Fires asynchronously with each slider animation
  2114. after: function() {
  2115. }, //Callback: function(slider) - Fires after each slider animation completes
  2116. end: function() {
  2117. }, //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
  2118. added: function() {
  2119. }, //{NEW} Callback: function(slider) - Fires after a slide is added
  2120. removed: function() {
  2121. }, //{NEW} Callback: function(slider) - Fires after a slide is removed
  2122. init: function() {
  2123. } //{NEW} Callback: function(slider) - Fires after the slider is initially setup
  2124. };
  2125. // FlexSlider: Plugin Function
  2126. $.fn.flexslider = function(options) {
  2127. if (options === undefined) {options = {};}
  2128. if (typeof options === "object") {
  2129. return this.each(function() {
  2130. var $this = $(this),
  2131. selector = (options.selector) ? options.selector : ".am-slides > li",
  2132. $slides = $this.find(selector);
  2133. if (($slides.length === 1 && options.allowOneSlide === true) || $slides.length === 0) {
  2134. $slides.fadeIn(400);
  2135. if (options.start) {options.start($this);}
  2136. } else if ($this.data('flexslider') === undefined) {
  2137. new $.flexslider(this, options);
  2138. }
  2139. });
  2140. } else {
  2141. // Helper strings to quickly pecdrform functions on the slider
  2142. var $slider = $(this).data('flexslider');
  2143. switch (options) {
  2144. case 'play':
  2145. $slider.play();
  2146. break;
  2147. case 'pause':
  2148. $slider.pause();
  2149. break;
  2150. case 'stop':
  2151. $slider.stop();
  2152. break;
  2153. case 'next':
  2154. $slider.flexAnimate($slider.getTarget('next'), true);
  2155. break;
  2156. case 'prev':
  2157. case 'previous':
  2158. $slider.flexAnimate($slider.getTarget('prev'), true);
  2159. break;
  2160. default:
  2161. if (typeof options === 'number') {
  2162. $slider.flexAnimate(options, true);
  2163. }
  2164. }
  2165. }
  2166. };
  2167. // Init code
  2168. UI.ready(function(context) {
  2169. $('[data-am-flexslider]', context).each(function(i, item) {
  2170. var $slider = $(item);
  2171. var options = UI.utils.parseOptions($slider.data('amFlexslider'));
  2172. options.before = function(slider) {
  2173. if (slider._pausedTimer) {
  2174. window.clearTimeout(slider._pausedTimer);
  2175. slider._pausedTimer = null;
  2176. }
  2177. };
  2178. options.after = function(slider) {
  2179. var pauseTime = slider.vars.playAfterPaused;
  2180. if (pauseTime && !isNaN(pauseTime) && !slider.playing) {
  2181. if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {
  2182. slider._pausedTimer = window.setTimeout(function() {
  2183. slider.play();
  2184. }, pauseTime);
  2185. }
  2186. }
  2187. };
  2188. $slider.flexslider(options);
  2189. });
  2190. });
  2191. module.exports = $.flexslider;
  2192. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2193. },{"./core":2}],9:[function(require,module,exports){
  2194. (function (global){
  2195. 'use strict';
  2196. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  2197. var UI = require('./core');
  2198. var dimmer = require('./ui.dimmer');
  2199. var $doc = $(document);
  2200. var supportTransition = UI.support.transition;
  2201. /**
  2202. * @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
  2203. * @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
  2204. */
  2205. var Modal = function(element, options) {
  2206. this.options = $.extend({}, Modal.DEFAULTS, options || {});
  2207. this.$element = $(element);
  2208. this.$dialog = this.$element.find('.am-modal-dialog');
  2209. if (!this.$element.attr('id')) {
  2210. this.$element.attr('id', UI.utils.generateGUID('am-modal'));
  2211. }
  2212. this.isPopup = this.$element.hasClass('am-popup');
  2213. this.isActions = this.$element.hasClass('am-modal-actions');
  2214. this.isPrompt = this.$element.hasClass('am-modal-prompt');
  2215. this.isLoading = this.$element.hasClass('am-modal-loading');
  2216. this.active = this.transitioning = this.relatedTarget = null;
  2217. this.events();
  2218. };
  2219. Modal.DEFAULTS = {
  2220. className: {
  2221. active: 'am-modal-active',
  2222. out: 'am-modal-out'
  2223. },
  2224. selector: {
  2225. modal: '.am-modal',
  2226. active: '.am-modal-active'
  2227. },
  2228. closeViaDimmer: true,
  2229. cancelable: true,
  2230. onConfirm: function() {
  2231. },
  2232. onCancel: function() {
  2233. },
  2234. height: undefined,
  2235. width: undefined,
  2236. duration: 300, // must equal the CSS transition duration
  2237. transitionEnd: supportTransition && supportTransition.end + '.modal.amui'
  2238. };
  2239. Modal.prototype.toggle = function(relatedTarget) {
  2240. return this.active ? this.close() : this.open(relatedTarget);
  2241. };
  2242. Modal.prototype.open = function(relatedTarget) {
  2243. var $element = this.$element;
  2244. var options = this.options;
  2245. var isPopup = this.isPopup;
  2246. var width = options.width;
  2247. var height = options.height;
  2248. var style = {};
  2249. if (this.active) {
  2250. return;
  2251. }
  2252. if (!this.$element.length) {
  2253. return;
  2254. }
  2255. // callback hook
  2256. relatedTarget && (this.relatedTarget = relatedTarget);
  2257. // 判断如果还在动画,就先触发之前的closed事件
  2258. if (this.transitioning) {
  2259. clearTimeout($element.transitionEndTimmer);
  2260. $element.transitionEndTimmer = null;
  2261. $element.trigger(options.transitionEnd).off(options.transitionEnd);
  2262. }
  2263. isPopup && this.$element.show();
  2264. this.active = true;
  2265. $element.trigger($.Event('open.modal.amui', {relatedTarget: relatedTarget}));
  2266. dimmer.open($element);
  2267. $element.show().redraw();
  2268. // apply Modal width/height if set
  2269. if (!isPopup && !this.isActions) {
  2270. if (width) {
  2271. width = parseInt(width, 10);
  2272. style.width = width + 'px';
  2273. style.marginLeft = -parseInt(width / 2) + 'px';
  2274. }
  2275. if (height) {
  2276. height = parseInt(height, 10);
  2277. // style.height = height + 'px';
  2278. style.marginTop = -parseInt(height / 2) + 'px';
  2279. // the background color is styled to $dialog
  2280. // so the height should set to $dialog
  2281. this.$dialog.css({height: height + 'px'});
  2282. } else {
  2283. style.marginTop = -parseInt($element.height() / 2, 10) + 'px';
  2284. }
  2285. $element.css(style);
  2286. }
  2287. $element.
  2288. removeClass(options.className.out).
  2289. addClass(options.className.active);
  2290. this.transitioning = 1;
  2291. var complete = function() {
  2292. $element.trigger($.Event('opened.modal.amui',
  2293. {relatedTarget: relatedTarget}));
  2294. this.transitioning = 0;
  2295. // Prompt auto focus
  2296. if (this.isPrompt) {
  2297. this.$dialog.find('input').eq(0).focus();
  2298. }
  2299. };
  2300. if (!supportTransition) {
  2301. return complete.call(this);
  2302. }
  2303. $element.
  2304. one(options.transitionEnd, $.proxy(complete, this)).
  2305. emulateTransitionEnd(options.duration);
  2306. };
  2307. Modal.prototype.close = function(relatedTarget) {
  2308. if (!this.active) {
  2309. return;
  2310. }
  2311. var $element = this.$element;
  2312. var options = this.options;
  2313. var isPopup = this.isPopup;
  2314. // 判断如果还在动画,就先触发之前的opened事件
  2315. if (this.transitioning) {
  2316. clearTimeout($element.transitionEndTimmer);
  2317. $element.transitionEndTimmer = null;
  2318. $element.trigger(options.transitionEnd).off(options.transitionEnd);
  2319. dimmer.close($element, true);
  2320. }
  2321. this.$element.trigger($.Event('close.modal.amui',
  2322. {relatedTarget: relatedTarget}));
  2323. this.transitioning = 1;
  2324. var complete = function() {
  2325. $element.trigger('closed.modal.amui');
  2326. isPopup && $element.removeClass(options.className.out);
  2327. $element.hide();
  2328. this.transitioning = 0;
  2329. // 不强制关闭 Dimmer,以便多个 Modal 可以共享 Dimmer
  2330. dimmer.close($element, false);
  2331. this.active = false;
  2332. };
  2333. $element.removeClass(options.className.active).
  2334. addClass(options.className.out);
  2335. if (!supportTransition) {
  2336. return complete.call(this);
  2337. }
  2338. $element.one(options.transitionEnd, $.proxy(complete, this)).
  2339. emulateTransitionEnd(options.duration);
  2340. };
  2341. Modal.prototype.events = function() {
  2342. var that = this;
  2343. var $element = this.$element;
  2344. var $ipt = $element.find('.am-modal-prompt-input');
  2345. var getData = function() {
  2346. var data = [];
  2347. $ipt.each(function() {
  2348. data.push($(this).val());
  2349. });
  2350. return (data.length === 0) ? undefined :
  2351. ((data.length === 1) ? data[0] : data);
  2352. };
  2353. // close via Esc key
  2354. if (this.options.cancelable) {
  2355. $element.on('keyup.modal.amui', function(e) {
  2356. if (that.active && e.which === 27) {
  2357. $element.trigger('cancel.modal.amui');
  2358. that.close();
  2359. }
  2360. });
  2361. }
  2362. // Close Modal when dimmer clicked
  2363. if (this.options.closeViaDimmer && !this.isLoading) {
  2364. dimmer.$element.on('click.dimmer.modal.amui', function(e) {
  2365. that.close();
  2366. });
  2367. }
  2368. // Close Modal when button clicked
  2369. $element.find('[data-am-modal-close], .am-modal-btn').
  2370. on('click.close.modal.amui', function(e) {
  2371. e.preventDefault();
  2372. that.close();
  2373. });
  2374. $element.find('[data-am-modal-confirm]').on('click.confirm.modal.amui',
  2375. function() {
  2376. $element.trigger($.Event('confirm.modal.amui', {
  2377. trigger: this
  2378. }));
  2379. });
  2380. $element.find('[data-am-modal-cancel]').
  2381. on('click.cancel.modal.amui', function() {
  2382. $element.trigger($.Event('cancel.modal.amui', {
  2383. trigger: this
  2384. }));
  2385. });
  2386. $element.on('confirm.modal.amui', function(e) {
  2387. e.data = getData();
  2388. that.options.onConfirm.call(that, e);
  2389. }).on('cancel.modal.amui', function(e) {
  2390. e.data = getData();
  2391. that.options.onCancel.call(that, e);
  2392. });
  2393. };
  2394. function Plugin(option, relatedTarget) {
  2395. return this.each(function() {
  2396. var $this = $(this);
  2397. var data = $this.data('amui.modal');
  2398. var options = $.extend({},
  2399. Modal.DEFAULTS, typeof option == 'object' && option);
  2400. if (!data) {
  2401. $this.data('amui.modal', (data = new Modal(this, options)));
  2402. }
  2403. if (typeof option == 'string') {
  2404. data[option] && data[option](relatedTarget);
  2405. } else {
  2406. data.toggle(option && option.relatedTarget || undefined);
  2407. }
  2408. });
  2409. }
  2410. $.fn.modal = Plugin;
  2411. // Init
  2412. $doc.on('click.modal.amui.data-api', '[data-am-modal]', function() {
  2413. var $this = $(this);
  2414. var options = UI.utils.parseOptions($this.attr('data-am-modal'));
  2415. var $target = $(options.target ||
  2416. (this.href && this.href.replace(/.*(?=#[^\s]+$)/, '')));
  2417. var option = $target.data('amui.modal') ? 'toggle' : options;
  2418. Plugin.call($target, option, this);
  2419. });
  2420. $.AMUI.modal = Modal;
  2421. module.exports = Modal;
  2422. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2423. },{"./core":2,"./ui.dimmer":6}],10:[function(require,module,exports){
  2424. (function (global){
  2425. 'use strict';
  2426. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  2427. var UI = require('./core');
  2428. var Hammer = require('./util.hammer');
  2429. var $win = $(window);
  2430. var $doc = $(document);
  2431. var scrollPos;
  2432. /**
  2433. * @via https://github.com/uikit/uikit/blob/master/src/js/offcanvas.js
  2434. * @license https://github.com/uikit/uikit/blob/master/LICENSE.md
  2435. */
  2436. var OffCanvas = function(element, options) {
  2437. this.$element = $(element);
  2438. this.options = $.extend({}, OffCanvas.DEFAULTS, options);
  2439. this.active = null;
  2440. this.bindEvents();
  2441. };
  2442. OffCanvas.DEFAULTS = {
  2443. duration: 300,
  2444. effect: 'overlay' // {push|overlay}, push is too expensive
  2445. };
  2446. OffCanvas.prototype.open = function(relatedElement) {
  2447. var _this = this;
  2448. var $element = this.$element;
  2449. if (!$element.length || $element.hasClass('am-active')) {
  2450. return;
  2451. }
  2452. var effect = this.options.effect;
  2453. var $html = $('html');
  2454. var $body = $('body');
  2455. var $bar = $element.find('.am-offcanvas-bar').first();
  2456. var dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1;
  2457. $bar.addClass('am-offcanvas-bar-' + effect);
  2458. scrollPos = {x: window.scrollX, y: window.scrollY};
  2459. $element.addClass('am-active');
  2460. $body.css({
  2461. width: window.innerWidth,
  2462. height: $win.height()
  2463. }).addClass('am-offcanvas-page');
  2464. if (effect !== 'overlay') {
  2465. $body.css({
  2466. 'margin-left': $bar.outerWidth() * dir
  2467. }).width(); // force redraw
  2468. }
  2469. $html.css('margin-top', scrollPos.y * -1);
  2470. setTimeout(function() {
  2471. $bar.addClass('am-offcanvas-bar-active').width();
  2472. }, 0);
  2473. $element.trigger('open.offcanvas.amui');
  2474. this.active = 1;
  2475. // Close OffCanvas when none content area clicked
  2476. $element.on('click.offcanvas.amui', function(e) {
  2477. var $target = $(e.target);
  2478. if ($target.hasClass('am-offcanvas-bar')) {
  2479. return;
  2480. }
  2481. if ($target.parents('.am-offcanvas-bar').first().length) {
  2482. return;
  2483. }
  2484. // https://developer.mozilla.org/zh-CN/docs/DOM/event.stopImmediatePropagation
  2485. e.stopImmediatePropagation();
  2486. _this.close();
  2487. });
  2488. $html.on('keydown.offcanvas.amui', function(e) {
  2489. (e.keyCode === 27) && _this.close();
  2490. });
  2491. };
  2492. OffCanvas.prototype.close = function(relatedElement) {
  2493. var _this = this;
  2494. var $html = $('html');
  2495. var $body = $('body');
  2496. var $element = this.$element;
  2497. var $bar = $element.find('.am-offcanvas-bar').first();
  2498. if (!$element.length || !this.active || !$element.hasClass('am-active')) {
  2499. return;
  2500. }
  2501. $element.trigger('close.offcanvas.amui');
  2502. function complete() {
  2503. $body.removeClass('am-offcanvas-page').
  2504. css({width: '', height: '', 'margin-left': '', 'margin-right': ''});
  2505. $element.removeClass('am-active');
  2506. $bar.removeClass('am-offcanvas-bar-active');
  2507. $html.css('margin-top', '');
  2508. window.scrollTo(scrollPos.x, scrollPos.y);
  2509. $element.trigger('closed.offcanvas.amui');
  2510. _this.active = 0;
  2511. }
  2512. if (UI.support.transition) {
  2513. setTimeout(function() {
  2514. $bar.removeClass('am-offcanvas-bar-active');
  2515. }, 0);
  2516. $body.css('margin-left', '').one(UI.support.transition.end, function() {
  2517. complete();
  2518. }).emulateTransitionEnd(this.options.duration);
  2519. } else {
  2520. complete();
  2521. }
  2522. $element.off('click.offcanvas.amui');
  2523. $html.off('.offcanvas.amui');
  2524. };
  2525. OffCanvas.prototype.bindEvents = function() {
  2526. var _this = this;
  2527. $doc.on('click.offcanvas.amui', '[data-am-dismiss="offcanvas"]', function(e) {
  2528. e.preventDefault();
  2529. _this.close();
  2530. });
  2531. $win.on('resize.offcanvas.amui orientationchange.offcanvas.amui',
  2532. function() {
  2533. _this.active && _this.close();
  2534. });
  2535. this.$element.hammer().on('swipeleft swipeleft', function(e) {
  2536. e.preventDefault();
  2537. _this.close();
  2538. });
  2539. return this;
  2540. };
  2541. function Plugin(option, relatedElement) {
  2542. return this.each(function() {
  2543. var $this = $(this);
  2544. var data = $this.data('amui.offcanvas');
  2545. var options = $.extend({}, typeof option == 'object' && option);
  2546. if (!data) {
  2547. $this.data('amui.offcanvas', (data = new OffCanvas(this, options)));
  2548. (!option || typeof option == 'object') && data.open(relatedElement);
  2549. }
  2550. if (typeof option == 'string') {
  2551. data[option] && data[option](relatedElement);
  2552. }
  2553. });
  2554. }
  2555. $.fn.offCanvas = Plugin;
  2556. // Init code
  2557. $doc.on('click.offcanvas.amui', '[data-am-offcanvas]', function(e) {
  2558. e.preventDefault();
  2559. var $this = $(this);
  2560. var options = UI.utils.parseOptions($this.data('amOffcanvas'));
  2561. var $target = $(options.target ||
  2562. (this.href && this.href.replace(/.*(?=#[^\s]+$)/, '')));
  2563. var option = $target.data('amui.offcanvas') ? 'open' : options;
  2564. Plugin.call($target, option, this);
  2565. });
  2566. $.AMUI.offcanvas = OffCanvas;
  2567. module.exports = OffCanvas;
  2568. // TODO: 优化动画效果
  2569. // http://dbushell.github.io/Responsive-Off-Canvas-Menu/step4.html
  2570. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2571. },{"./core":2,"./util.hammer":17}],11:[function(require,module,exports){
  2572. (function (global){
  2573. 'use strict';
  2574. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  2575. var UI = require('./core');
  2576. var $w = $(window);
  2577. /**
  2578. * @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
  2579. * @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
  2580. */
  2581. var Popover = function(element, options) {
  2582. this.options = $.extend({}, Popover.DEFAULTS, options || {});
  2583. this.$element = $(element);
  2584. this.active = null;
  2585. this.$popover = (this.options.target && $(this.options.target)) || null;
  2586. this.init();
  2587. this.events();
  2588. };
  2589. Popover.DEFAULTS = {
  2590. theme: undefined,
  2591. trigger: 'click',
  2592. content: '',
  2593. open: false,
  2594. target: undefined,
  2595. tpl: '<div class="am-popover">' +
  2596. '<div class="am-popover-inner"></div>' +
  2597. '<div class="am-popover-caret"></div></div>'
  2598. };
  2599. Popover.prototype.init = function() {
  2600. var me = this;
  2601. var $element = this.$element;
  2602. var $popover;
  2603. if (!this.options.target) {
  2604. this.$popover = this.getPopover();
  2605. this.setContent();
  2606. }
  2607. $popover = this.$popover;
  2608. $popover.appendTo($('body'));
  2609. this.sizePopover();
  2610. function sizePopover() {
  2611. me.sizePopover();
  2612. }
  2613. // TODO: 监听页面内容变化,重新调整位置
  2614. $element.on('open.popover.amui', function() {
  2615. $(window).on('resize.popover.amui', UI.utils.debounce(sizePopover, 50));
  2616. });
  2617. $element.on('close.popover.amui', function() {
  2618. $(window).off('resize.popover.amui', sizePopover);
  2619. });
  2620. this.options.open && this.open();
  2621. };
  2622. Popover.prototype.sizePopover = function sizePopover() {
  2623. var $element = this.$element;
  2624. var $popover = this.$popover;
  2625. if (!$popover || !$popover.length) {
  2626. return;
  2627. }
  2628. var popWidth = $popover.outerWidth();
  2629. var popHeight = $popover.outerHeight();
  2630. var $popCaret = $popover.find('.am-popover-caret');
  2631. var popCaretSize = ($popCaret.outerWidth() / 2) || 8;
  2632. // 取不到 $popCaret.outerHeight() 的值,所以直接加 8
  2633. var popTotalHeight = popHeight + 8; // $popCaret.outerHeight();
  2634. var triggerWidth = $element.outerWidth();
  2635. var triggerHeight = $element.outerHeight();
  2636. var triggerOffset = $element.offset();
  2637. var triggerRect = $element[0].getBoundingClientRect();
  2638. var winHeight = $w.height();
  2639. var winWidth = $w.width();
  2640. var popTop = 0;
  2641. var popLeft = 0;
  2642. var diff = 0;
  2643. var spacing = 2;
  2644. var popPosition = 'top';
  2645. $popover.css({left: '', top: ''}).removeClass('am-popover-left ' +
  2646. 'am-popover-right am-popover-top am-popover-bottom');
  2647. // $popCaret.css({left: '', top: ''});
  2648. if (popTotalHeight - spacing < triggerRect.top + spacing) {
  2649. // Popover on the top of trigger
  2650. popTop = triggerOffset.top - popTotalHeight - spacing;
  2651. } else if (popTotalHeight <
  2652. winHeight - triggerRect.top - triggerRect.height) {
  2653. // On bottom
  2654. popPosition = 'bottom';
  2655. popTop = triggerOffset.top + triggerHeight + popCaretSize + spacing;
  2656. } else { // On middle
  2657. popPosition = 'middle';
  2658. popTop = triggerHeight / 2 + triggerOffset.top - popHeight / 2;
  2659. }
  2660. // Horizontal Position
  2661. if (popPosition === 'top' || popPosition === 'bottom') {
  2662. popLeft = triggerWidth / 2 + triggerOffset.left - popWidth / 2;
  2663. diff = popLeft;
  2664. if (popLeft < 5) {
  2665. popLeft = 5;
  2666. }
  2667. if (popLeft + popWidth > winWidth) {
  2668. popLeft = (winWidth - popWidth - 20);
  2669. // console.log('left %d, win %d, popw %d', popLeft, winWidth, popWidth);
  2670. }
  2671. if (popPosition === 'top') {
  2672. // This is the Popover position, NOT caret position
  2673. // Popover on the Top of trigger, caret on the bottom of Popover
  2674. $popover.addClass('am-popover-top');
  2675. }
  2676. if (popPosition === 'bottom') {
  2677. $popover.addClass('am-popover-bottom');
  2678. }
  2679. diff = diff - popLeft;
  2680. // $popCaret.css({left: (popWidth / 2 - popCaretSize + diff) + 'px'});
  2681. } else if (popPosition === 'middle') {
  2682. popLeft = triggerOffset.left - popWidth - popCaretSize;
  2683. $popover.addClass('am-popover-left');
  2684. if (popLeft < 5) {
  2685. popLeft = triggerOffset.left + triggerWidth + popCaretSize;
  2686. $popover.removeClass('am-popover-left').addClass('am-popover-right');
  2687. }
  2688. if (popLeft + popWidth > winWidth) {
  2689. popLeft = winWidth - popWidth - 5;
  2690. $popover.removeClass('am-popover-left').addClass('am-popover-right');
  2691. }
  2692. // $popCaret.css({top: (popHeight / 2 - popCaretSize / 2) + 'px'});
  2693. }
  2694. // Apply position style
  2695. $popover.css({top: popTop + 'px', left: popLeft + 'px'});
  2696. };
  2697. Popover.prototype.toggle = function() {
  2698. return this[this.active ? 'close' : 'open']();
  2699. };
  2700. Popover.prototype.open = function() {
  2701. var $popover = this.$popover;
  2702. this.$element.trigger('open.popover.amui');
  2703. this.sizePopover();
  2704. $popover.show().addClass('am-active');
  2705. this.active = true;
  2706. };
  2707. Popover.prototype.close = function() {
  2708. var $popover = this.$popover;
  2709. this.$element.trigger('close.popover.amui');
  2710. $popover.
  2711. removeClass('am-active').
  2712. trigger('closed.popover.amui').
  2713. hide();
  2714. this.active = false;
  2715. };
  2716. Popover.prototype.getPopover = function() {
  2717. var uid = UI.utils.generateGUID('am-popover');
  2718. var theme = [];
  2719. if (this.options.theme) {
  2720. $.each(this.options.theme.split(','), function(i, item) {
  2721. theme.push('am-popover-' + $.trim(item));
  2722. });
  2723. }
  2724. return $(this.options.tpl).attr('id', uid).addClass(theme.join(' '));
  2725. };
  2726. Popover.prototype.setContent = function(content) {
  2727. content = content || this.options.content;
  2728. this.$popover && this.$popover.find('.am-popover-inner').empty().
  2729. html(content);
  2730. };
  2731. Popover.prototype.events = function() {
  2732. var eventNS = 'popover.amui';
  2733. var triggers = this.options.trigger.split(' ');
  2734. for (var i = triggers.length; i--;) {
  2735. var trigger = triggers[i];
  2736. if (trigger === 'click') {
  2737. this.$element.on('click.' + eventNS, $.proxy(this.toggle, this));
  2738. } else { // hover or focus
  2739. var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
  2740. var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
  2741. this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this));
  2742. this.$element.on(eventOut + '.' + eventNS, $.proxy(this.close, this));
  2743. }
  2744. }
  2745. };
  2746. function Plugin(option) {
  2747. return this.each(function() {
  2748. var $this = $(this);
  2749. var data = $this.data('amui.popover');
  2750. var options = $.extend({},
  2751. UI.utils.parseOptions($this.attr('data-am-popover')),
  2752. typeof option == 'object' && option);
  2753. if (!data) {
  2754. $this.data('amui.popover', (data = new Popover(this, options)));
  2755. }
  2756. if (typeof option == 'string') {
  2757. data[option] && data[option]();
  2758. }
  2759. });
  2760. }
  2761. $.fn.popover = Plugin;
  2762. // Init code
  2763. UI.ready(function(context) {
  2764. $('[data-am-popover]', context).popover();
  2765. });
  2766. $.AMUI.popover = Popover;
  2767. module.exports = Popover;
  2768. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2769. },{"./core":2}],12:[function(require,module,exports){
  2770. (function (global){
  2771. 'use strict';
  2772. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  2773. var UI = require('./core');
  2774. var Progress = (function() {
  2775. /**
  2776. * NProgress (c) 2013, Rico Sta. Cruz
  2777. * @via http://ricostacruz.com/nprogress
  2778. */
  2779. var NProgress = {};
  2780. var $html = $('html');
  2781. NProgress.version = '0.1.6';
  2782. var Settings = NProgress.settings = {
  2783. minimum: 0.08,
  2784. easing: 'ease',
  2785. positionUsing: '',
  2786. speed: 200,
  2787. trickle: true,
  2788. trickleRate: 0.02,
  2789. trickleSpeed: 800,
  2790. showSpinner: true,
  2791. parent: 'body',
  2792. barSelector: '[role="nprogress-bar"]',
  2793. spinnerSelector: '[role="nprogress-spinner"]',
  2794. template: '<div class="nprogress-bar" role="nprogress-bar">' +
  2795. '<div class="nprogress-peg"></div></div>' +
  2796. '<div class="nprogress-spinner" role="nprogress-spinner">' +
  2797. '<div class="nprogress-spinner-icon"></div></div>'
  2798. };
  2799. /**
  2800. * Updates configuration.
  2801. *
  2802. * NProgress.configure({
  2803. * minimum: 0.1
  2804. * });
  2805. */
  2806. NProgress.configure = function(options) {
  2807. var key, value;
  2808. for (key in options) {
  2809. value = options[key];
  2810. if (value !== undefined && options.hasOwnProperty(key)) Settings[key] = value;
  2811. }
  2812. return this;
  2813. };
  2814. /**
  2815. * Last number.
  2816. */
  2817. NProgress.status = null;
  2818. /**
  2819. * Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
  2820. *
  2821. * NProgress.set(0.4);
  2822. * NProgress.set(1.0);
  2823. */
  2824. NProgress.set = function(n) {
  2825. var started = NProgress.isStarted();
  2826. n = clamp(n, Settings.minimum, 1);
  2827. NProgress.status = (n === 1 ? null : n);
  2828. var progress = NProgress.render(!started),
  2829. bar = progress.querySelector(Settings.barSelector),
  2830. speed = Settings.speed,
  2831. ease = Settings.easing;
  2832. progress.offsetWidth;
  2833. /* Repaint */
  2834. queue(function(next) {
  2835. // Set positionUsing if it hasn't already been set
  2836. if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS();
  2837. // Add transition
  2838. css(bar, barPositionCSS(n, speed, ease));
  2839. if (n === 1) {
  2840. // Fade out
  2841. css(progress, {
  2842. transition: 'none',
  2843. opacity: 1
  2844. });
  2845. progress.offsetWidth;
  2846. /* Repaint */
  2847. setTimeout(function() {
  2848. css(progress, {
  2849. transition: 'all ' + speed + 'ms linear',
  2850. opacity: 0
  2851. });
  2852. setTimeout(function() {
  2853. NProgress.remove();
  2854. next();
  2855. }, speed);
  2856. }, speed);
  2857. } else {
  2858. setTimeout(next, speed);
  2859. }
  2860. });
  2861. return this;
  2862. };
  2863. NProgress.isStarted = function() {
  2864. return typeof NProgress.status === 'number';
  2865. };
  2866. /**
  2867. * Shows the progress bar.
  2868. * This is the same as setting the status to 0%, except that it doesn't go backwards.
  2869. *
  2870. * NProgress.start();
  2871. *
  2872. */
  2873. NProgress.start = function() {
  2874. if (!NProgress.status) NProgress.set(0);
  2875. var work = function() {
  2876. setTimeout(function() {
  2877. if (!NProgress.status) return;
  2878. NProgress.trickle();
  2879. work();
  2880. }, Settings.trickleSpeed);
  2881. };
  2882. if (Settings.trickle) work();
  2883. return this;
  2884. };
  2885. /**
  2886. * Hides the progress bar.
  2887. * This is the *sort of* the same as setting the status to 100%, with the
  2888. * difference being `done()` makes some placebo effect of some realistic motion.
  2889. *
  2890. * NProgress.done();
  2891. *
  2892. * If `true` is passed, it will show the progress bar even if its hidden.
  2893. *
  2894. * NProgress.done(true);
  2895. */
  2896. NProgress.done = function(force) {
  2897. if (!force && !NProgress.status) return this;
  2898. return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
  2899. };
  2900. /**
  2901. * Increments by a random amount.
  2902. */
  2903. NProgress.inc = function(amount) {
  2904. var n = NProgress.status;
  2905. if (!n) {
  2906. return NProgress.start();
  2907. } else {
  2908. if (typeof amount !== 'number') {
  2909. amount = (1 - n) * clamp(Math.random() * n, 0.1, 0.95);
  2910. }
  2911. n = clamp(n + amount, 0, 0.994);
  2912. return NProgress.set(n);
  2913. }
  2914. };
  2915. NProgress.trickle = function() {
  2916. return NProgress.inc(Math.random() * Settings.trickleRate);
  2917. };
  2918. /**
  2919. * (Internal) renders the progress bar markup based on the `template`
  2920. * setting.
  2921. */
  2922. NProgress.render = function(fromStart) {
  2923. if (NProgress.isRendered()) return document.getElementById('nprogress');
  2924. $html.addClass('nprogress-busy');
  2925. var progress = document.createElement('div');
  2926. progress.id = 'nprogress';
  2927. progress.innerHTML = Settings.template;
  2928. var bar = progress.querySelector(Settings.barSelector),
  2929. perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
  2930. parent = document.querySelector(Settings.parent),
  2931. spinner;
  2932. css(bar, {
  2933. transition: 'all 0 linear',
  2934. transform: 'translate3d(' + perc + '%,0,0)'
  2935. });
  2936. if (!Settings.showSpinner) {
  2937. spinner = progress.querySelector(Settings.spinnerSelector);
  2938. spinner && $(spinner).remove();
  2939. }
  2940. if (parent != document.body) {
  2941. $(parent).addClass('nprogress-custom-parent');
  2942. }
  2943. parent.appendChild(progress);
  2944. return progress;
  2945. };
  2946. /**
  2947. * Removes the element. Opposite of render().
  2948. */
  2949. NProgress.remove = function() {
  2950. $html.removeClass('nprogress-busy');
  2951. $(Settings.parent).removeClass('nprogress-custom-parent');
  2952. var progress = document.getElementById('nprogress');
  2953. progress && $(progress).remove();
  2954. };
  2955. /**
  2956. * Checks if the progress bar is rendered.
  2957. */
  2958. NProgress.isRendered = function() {
  2959. return !!document.getElementById('nprogress');
  2960. };
  2961. /**
  2962. * Determine which positioning CSS rule to use.
  2963. */
  2964. NProgress.getPositioningCSS = function() {
  2965. // Sniff on document.body.style
  2966. var bodyStyle = document.body.style;
  2967. // Sniff prefixes
  2968. var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' :
  2969. ('MozTransform' in bodyStyle) ? 'Moz' :
  2970. ('msTransform' in bodyStyle) ? 'ms' :
  2971. ('OTransform' in bodyStyle) ? 'O' : '';
  2972. if (vendorPrefix + 'Perspective' in bodyStyle) {
  2973. // Modern browsers with 3D support, e.g. Webkit, IE10
  2974. return 'translate3d';
  2975. } else if (vendorPrefix + 'Transform' in bodyStyle) {
  2976. // Browsers without 3D support, e.g. IE9
  2977. return 'translate';
  2978. } else {
  2979. // Browsers without translate() support, e.g. IE7-8
  2980. return 'margin';
  2981. }
  2982. };
  2983. /**
  2984. * Helpers
  2985. */
  2986. function clamp(n, min, max) {
  2987. if (n < min) return min;
  2988. if (n > max) return max;
  2989. return n;
  2990. }
  2991. /**
  2992. * (Internal) converts a percentage (`0..1`) to a bar translateX
  2993. * percentage (`-100%..0%`).
  2994. */
  2995. function toBarPerc(n) {
  2996. return (-1 + n) * 100;
  2997. }
  2998. /**
  2999. * (Internal) returns the correct CSS for changing the bar's
  3000. * position given an n percentage, and speed and ease from Settings
  3001. */
  3002. function barPositionCSS(n, speed, ease) {
  3003. var barCSS;
  3004. if (Settings.positionUsing === 'translate3d') {
  3005. barCSS = {transform: 'translate3d(' + toBarPerc(n) + '%,0,0)'};
  3006. } else if (Settings.positionUsing === 'translate') {
  3007. barCSS = {transform: 'translate(' + toBarPerc(n) + '%,0)'};
  3008. } else {
  3009. barCSS = {'margin-left': toBarPerc(n) + '%'};
  3010. }
  3011. barCSS.transition = 'all ' + speed + 'ms ' + ease;
  3012. return barCSS;
  3013. }
  3014. /**
  3015. * (Internal) Queues a function to be executed.
  3016. */
  3017. var queue = (function() {
  3018. var pending = [];
  3019. function next() {
  3020. var fn = pending.shift();
  3021. if (fn) {
  3022. fn(next);
  3023. }
  3024. }
  3025. return function(fn) {
  3026. pending.push(fn);
  3027. if (pending.length == 1) next();
  3028. };
  3029. })();
  3030. /**
  3031. * (Internal) Applies css properties to an element, similar to the jQuery
  3032. * css method.
  3033. *
  3034. * While this helper does assist with vendor prefixed property names, it
  3035. * does not perform any manipulation of values prior to setting styles.
  3036. */
  3037. var css = (function() {
  3038. var cssPrefixes = ['Webkit', 'O', 'Moz', 'ms'],
  3039. cssProps = {};
  3040. function camelCase(string) {
  3041. return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function(match, letter) {
  3042. return letter.toUpperCase();
  3043. });
  3044. }
  3045. function getVendorProp(name) {
  3046. var style = document.body.style;
  3047. if (name in style) return name;
  3048. var i = cssPrefixes.length,
  3049. capName = name.charAt(0).toUpperCase() + name.slice(1),
  3050. vendorName;
  3051. while (i--) {
  3052. vendorName = cssPrefixes[i] + capName;
  3053. if (vendorName in style) return vendorName;
  3054. }
  3055. return name;
  3056. }
  3057. function getStyleProp(name) {
  3058. name = camelCase(name);
  3059. return cssProps[name] || (cssProps[name] = getVendorProp(name));
  3060. }
  3061. function applyCss(element, prop, value) {
  3062. prop = getStyleProp(prop);
  3063. element.style[prop] = value;
  3064. }
  3065. return function(element, properties) {
  3066. var args = arguments,
  3067. prop,
  3068. value;
  3069. if (args.length == 2) {
  3070. for (prop in properties) {
  3071. value = properties[prop];
  3072. if (value !== undefined && properties.hasOwnProperty(prop)) applyCss(element, prop, value);
  3073. }
  3074. } else {
  3075. applyCss(element, args[1], args[2]);
  3076. }
  3077. }
  3078. })();
  3079. return NProgress;
  3080. })();
  3081. $.AMUI.progress = Progress;
  3082. module.exports = Progress;
  3083. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3084. },{"./core":2}],13:[function(require,module,exports){
  3085. (function (global){
  3086. 'use strict';
  3087. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  3088. var UI = require('./core');
  3089. require('./ui.smooth-scroll');
  3090. /**
  3091. * @via https://github.com/uikit/uikit/
  3092. * @license https://github.com/uikit/uikit/blob/master/LICENSE.md
  3093. */
  3094. // ScrollSpyNav Class
  3095. var ScrollSpyNav = function(element, options) {
  3096. this.options = $.extend({}, ScrollSpyNav.DEFAULTS, options);
  3097. this.$element = $(element);
  3098. this.anchors = [];
  3099. this.$links = this.$element.find('a[href^="#"]').each(function(i, link) {
  3100. this.anchors.push($(link).attr('href'));
  3101. }.bind(this));
  3102. this.$targets = $(this.anchors.join(', '));
  3103. var processRAF = function() {
  3104. UI.utils.rAF.call(window, $.proxy(this.process, this));
  3105. }.bind(this);
  3106. this.$window = $(window).on('scroll.scrollspynav.amui', processRAF)
  3107. .on('resize.scrollspynav.amui orientationchange.scrollspynav.amui',
  3108. UI.utils.debounce(processRAF, 50));
  3109. processRAF();
  3110. this.scrollProcess();
  3111. };
  3112. ScrollSpyNav.DEFAULTS = {
  3113. className: {
  3114. active: 'am-active'
  3115. },
  3116. closest: false,
  3117. smooth: true,
  3118. offsetTop: 0
  3119. };
  3120. ScrollSpyNav.prototype.process = function() {
  3121. var scrollTop = this.$window.scrollTop();
  3122. var options = this.options;
  3123. var inViews = [];
  3124. var $links = this.$links;
  3125. var $targets = this.$targets;
  3126. $targets.each(function(i, target) {
  3127. if (UI.utils.isInView(target, options)) {
  3128. inViews.push(target);
  3129. }
  3130. });
  3131. // console.log(inViews.length);
  3132. if (inViews.length) {
  3133. var $target;
  3134. $.each(inViews, function(i, item) {
  3135. if ($(item).offset().top >= scrollTop) {
  3136. $target = $(item);
  3137. return false; // break
  3138. }
  3139. });
  3140. if (!$target) {
  3141. return;
  3142. }
  3143. if (options.closest) {
  3144. $links.closest(options.closest).removeClass(options.className.active);
  3145. $links.filter('a[href="#' + $target.attr('id') + '"]').
  3146. closest(options.closest).addClass(options.className.active);
  3147. } else {
  3148. $links.removeClass(options.className.active).
  3149. filter('a[href="#' + $target.attr('id') + '"]').
  3150. addClass(options.className.active);
  3151. }
  3152. }
  3153. };
  3154. ScrollSpyNav.prototype.scrollProcess = function() {
  3155. var $links = this.$links;
  3156. var options = this.options;
  3157. // smoothScroll
  3158. if (options.smooth) {
  3159. $links.on('click', function(e) {
  3160. e.preventDefault();
  3161. var $this = $(this);
  3162. var $target = $($this.attr('href'));
  3163. if (!$target) {
  3164. return;
  3165. }
  3166. var offsetTop = options.offsetTop &&
  3167. !isNaN(parseInt(options.offsetTop)) && parseInt(options.offsetTop) || 0;
  3168. $(window).smoothScroll({position: $target.offset().top - offsetTop});
  3169. });
  3170. }
  3171. };
  3172. // ScrollSpyNav Plugin
  3173. function Plugin(option) {
  3174. return this.each(function() {
  3175. var $this = $(this);
  3176. var data = $this.data('amui.scrollspynav');
  3177. var options = typeof option == 'object' && option;
  3178. if (!data) {
  3179. $this.data('amui.scrollspynav', (data = new ScrollSpyNav(this, options)));
  3180. }
  3181. if (typeof option == 'string') {
  3182. data[option]();
  3183. }
  3184. });
  3185. }
  3186. $.fn.scrollspynav = Plugin;
  3187. // Init code
  3188. UI.ready(function(context) {
  3189. $('[data-am-scrollspy-nav]', context).each(function() {
  3190. var $this = $(this);
  3191. var options = UI.utils.options($this.data('amScrollspyNav'));
  3192. Plugin.call($this, options);
  3193. });
  3194. });
  3195. $.AMUI.scrollspynav = ScrollSpyNav;
  3196. module.exports = ScrollSpyNav;
  3197. // TODO: 1. 算法改进
  3198. // 2. 多级菜单支持
  3199. // 3. smooth scroll pushState
  3200. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3201. },{"./core":2,"./ui.smooth-scroll":14}],14:[function(require,module,exports){
  3202. (function (global){
  3203. 'use strict';
  3204. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  3205. var UI = require('./core');
  3206. var rAF = UI.utils.rAF;
  3207. var cAF = UI.utils.cancelAF;
  3208. /**
  3209. * Smooth Scroll
  3210. * @param position
  3211. * @via http://mir.aculo.us/2014/01/19/scrolling-dom-elements-to-the-top-a-zepto-plugin/
  3212. */
  3213. // Usage: $(window).smoothScroll([options])
  3214. // only allow one scroll to top operation to be in progress at a time,
  3215. // which is probably what you want
  3216. var smoothScrollInProgress = false;
  3217. var SmoothScroll = function(element, options) {
  3218. options = options || {};
  3219. var $this = $(element);
  3220. var targetY = parseInt(options.position) || SmoothScroll.DEFAULTS.position;
  3221. var initialY = $this.scrollTop();
  3222. var lastY = initialY;
  3223. var delta = targetY - initialY;
  3224. // duration in ms, make it a bit shorter for short distances
  3225. // this is not scientific and you might want to adjust this for
  3226. // your preferences
  3227. var speed = options.speed ||
  3228. Math.min(750, Math.min(1500, Math.abs(initialY - targetY)));
  3229. // temp variables (t will be a position between 0 and 1, y is the calculated scrollTop)
  3230. var start;
  3231. var t;
  3232. var y;
  3233. var cancelScroll = function() {
  3234. abort();
  3235. };
  3236. // abort if already in progress or nothing to scroll
  3237. if (smoothScrollInProgress) {
  3238. return;
  3239. }
  3240. if (delta === 0) {
  3241. return;
  3242. }
  3243. // quint ease-in-out smoothing, from
  3244. // https://github.com/madrobby/scripty2/blob/master/src/effects/transitions/penner.js#L127-L136
  3245. function smooth(pos) {
  3246. if ((pos /= 0.5) < 1) {
  3247. return 0.5 * Math.pow(pos, 5);
  3248. }
  3249. return 0.5 * (Math.pow((pos - 2), 5) + 2);
  3250. }
  3251. function abort() {
  3252. $this.off('touchstart.smoothscroll.amui', cancelScroll);
  3253. smoothScrollInProgress = false;
  3254. }
  3255. // when there's a touch detected while scrolling is in progress, abort
  3256. // the scrolling (emulates native scrolling behavior)
  3257. $this.on('touchstart.smoothscroll.amui', cancelScroll);
  3258. smoothScrollInProgress = true;
  3259. // start rendering away! note the function given to frame
  3260. // is named "render" so we can reference it again further down
  3261. function render(now) {
  3262. if (!smoothScrollInProgress) {
  3263. return;
  3264. }
  3265. if (!start) {
  3266. start = now;
  3267. }
  3268. // calculate t, position of animation in [0..1]
  3269. t = Math.min(1, Math.max((now - start) / speed, 0));
  3270. // calculate the new scrollTop position (don't forget to smooth)
  3271. y = Math.round(initialY + delta * smooth(t));
  3272. // bracket scrollTop so we're never over-scrolling
  3273. if (delta > 0 && y > targetY) {
  3274. y = targetY;
  3275. }
  3276. if (delta < 0 && y < targetY) {
  3277. y = targetY;
  3278. }
  3279. // only actually set scrollTop if there was a change fromt he last frame
  3280. if (lastY != y) {
  3281. $this.scrollTop(y);
  3282. }
  3283. lastY = y;
  3284. // if we're not done yet, queue up an other frame to render,
  3285. // or clean up
  3286. if (y !== targetY) {
  3287. cAF(scrollRAF);
  3288. scrollRAF = rAF(render);
  3289. } else {
  3290. cAF(scrollRAF);
  3291. abort();
  3292. }
  3293. }
  3294. var scrollRAF = rAF(render);
  3295. };
  3296. SmoothScroll.DEFAULTS = {
  3297. position: 0
  3298. };
  3299. $.fn.smoothScroll = function(option) {
  3300. return this.each(function() {
  3301. new SmoothScroll(this, option);
  3302. });
  3303. };
  3304. // Init code
  3305. $(document).on('click.smoothScroll.amui.data-api', '[data-am-smooth-scroll]',
  3306. function(e) {
  3307. e.preventDefault();
  3308. var options = UI.utils.parseOptions($(this).data('amSmoothScroll'));
  3309. $(window).smoothScroll(options);
  3310. });
  3311. module.exports = SmoothScroll;
  3312. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3313. },{"./core":2}],15:[function(require,module,exports){
  3314. (function (global){
  3315. 'use strict';
  3316. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  3317. var UI = require('./core');
  3318. /**
  3319. * @via https://github.com/uikit/uikit/blob/master/src/js/addons/sticky.js
  3320. * @license https://github.com/uikit/uikit/blob/master/LICENSE.md
  3321. */
  3322. // Sticky Class
  3323. var Sticky = function(element, options) {
  3324. var me = this;
  3325. this.options = $.extend({}, Sticky.DEFAULTS, options);
  3326. this.$element = $(element);
  3327. this.sticked = null;
  3328. this.inited = null;
  3329. this.$holder = undefined;
  3330. this.$window = $(window).
  3331. on('scroll.sticky.amui',
  3332. UI.utils.debounce($.proxy(this.checkPosition, this), 10)).
  3333. on('resize.sticky.amui orientationchange.sticky.amui',
  3334. UI.utils.debounce(function() {
  3335. me.reset(true, function() {
  3336. me.checkPosition();
  3337. });
  3338. }, 50)).
  3339. on('load.sticky.amui', $.proxy(this.checkPosition, this));
  3340. // the `.offset()` is diff between jQuery & Zepto.js
  3341. // jQuery: return `top` and `left`
  3342. // Zepto.js: return `top`, `left`, `width`, `height`
  3343. this.offset = this.$element.offset();
  3344. this.init();
  3345. };
  3346. Sticky.DEFAULTS = {
  3347. top: 0,
  3348. bottom: 0,
  3349. animation: '',
  3350. className: {
  3351. sticky: 'am-sticky',
  3352. resetting: 'am-sticky-resetting',
  3353. stickyBtm: 'am-sticky-bottom',
  3354. animationRev: 'am-animation-reverse'
  3355. }
  3356. };
  3357. Sticky.prototype.init = function() {
  3358. var result = this.check();
  3359. if (!result) {
  3360. return false;
  3361. }
  3362. var $element = this.$element;
  3363. var $elementMargin = '';
  3364. $.each($element.css(
  3365. ['marginTop', 'marginRight', 'marginBottom', 'marginLeft']),
  3366. function(name, value) {
  3367. return $elementMargin += ' ' + value;
  3368. });
  3369. var $holder = $('<div class="am-sticky-placeholder"></div>').css({
  3370. height: $element.css('position') != 'absolute' ?
  3371. $element.outerHeight() : '',
  3372. float: $element.css('float') != 'none' ? $element.css('float') : '',
  3373. margin: $elementMargin
  3374. });
  3375. this.$holder = $element.css('margin', 0).wrap($holder).parent();
  3376. this.inited = 1;
  3377. return true;
  3378. };
  3379. Sticky.prototype.reset = function(force, cb) {
  3380. var options = this.options;
  3381. var $element = this.$element;
  3382. var animation = (options.animation) ?
  3383. ' am-animation-' + options.animation : '';
  3384. var complete = function() {
  3385. $element.css({position: '', top: '', width: '', left: '', margin: 0});
  3386. $element.removeClass([
  3387. animation,
  3388. options.className.animationRev,
  3389. options.className.sticky,
  3390. options.className.resetting
  3391. ].join(' '));
  3392. this.animating = false;
  3393. this.sticked = false;
  3394. this.offset = $element.offset();
  3395. cb && cb();
  3396. }.bind(this);
  3397. $element.addClass(options.className.resetting);
  3398. if (!force && options.animation && UI.support.animation) {
  3399. this.animating = true;
  3400. $element.removeClass(animation).one(UI.support.animation.end, function() {
  3401. complete();
  3402. }).width(); // force redraw
  3403. $element.addClass(animation + ' ' + options.className.animationRev);
  3404. } else {
  3405. complete();
  3406. }
  3407. };
  3408. Sticky.prototype.check = function() {
  3409. if (!this.$element.is(':visible')) {
  3410. return false;
  3411. }
  3412. var media = this.options.media;
  3413. if (media) {
  3414. switch (typeof(media)) {
  3415. case 'number':
  3416. if (window.innerWidth < media) {
  3417. return false;
  3418. }
  3419. break;
  3420. case 'string':
  3421. if (window.matchMedia && !window.matchMedia(media).matches) {
  3422. return false;
  3423. }
  3424. break;
  3425. }
  3426. }
  3427. return true;
  3428. };
  3429. Sticky.prototype.checkPosition = function() {
  3430. if (!this.inited) {
  3431. var initialized = this.init();
  3432. if (!initialized) {
  3433. return;
  3434. }
  3435. }
  3436. var options = this.options;
  3437. var scrollTop = this.$window.scrollTop();
  3438. var offsetTop = options.top;
  3439. var offsetBottom = options.bottom;
  3440. var $element = this.$element;
  3441. var animation = (options.animation) ?
  3442. ' am-animation-' + options.animation : '';
  3443. var className = [options.className.sticky, animation].join(' ');
  3444. if (typeof offsetBottom == 'function') {
  3445. offsetBottom = offsetBottom(this.$element);
  3446. }
  3447. var checkResult = (scrollTop > this.$holder.offset().top);
  3448. if (!this.sticked && checkResult) {
  3449. $element.addClass(className);
  3450. } else if (this.sticked && !checkResult) {
  3451. this.reset();
  3452. }
  3453. this.$holder.height($element.is(':visible') ? $element.height() : 0);
  3454. if (checkResult) {
  3455. $element.css({
  3456. top: offsetTop,
  3457. left: this.$holder.offset().left,
  3458. width: this.$holder.width()
  3459. });
  3460. /*
  3461. if (offsetBottom) {
  3462. // (底部边距 + 元素高度 > 窗口高度) 时定位到底部
  3463. if ((offsetBottom + this.offset.height > $(window).height()) &&
  3464. (scrollTop + $(window).height() >= scrollHeight - offsetBottom)) {
  3465. $element.addClass(options.className.stickyBtm).
  3466. css({top: $(window).height() - offsetBottom - this.offset.height});
  3467. } else {
  3468. $element.removeClass(options.className.stickyBtm).css({top: offsetTop});
  3469. }
  3470. }
  3471. */
  3472. }
  3473. this.sticked = checkResult;
  3474. };
  3475. // Sticky Plugin
  3476. function Plugin(option) {
  3477. return this.each(function() {
  3478. var $this = $(this);
  3479. var data = $this.data('amui.sticky');
  3480. var options = typeof option == 'object' && option;
  3481. if (!data) {
  3482. $this.data('amui.sticky', (data = new Sticky(this, options)));
  3483. }
  3484. if (typeof option == 'string') {
  3485. data[option]();
  3486. }
  3487. });
  3488. }
  3489. $.fn.sticky = Plugin;
  3490. // Init code
  3491. $(window).on('load', function() {
  3492. $('[data-am-sticky]').each(function() {
  3493. var $this = $(this);
  3494. var options = UI.utils.options($this.attr('data-am-sticky'));
  3495. Plugin.call($this, options);
  3496. });
  3497. });
  3498. $.AMUI.sticky = Sticky;
  3499. module.exports = Sticky;
  3500. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3501. },{"./core":2}],16:[function(require,module,exports){
  3502. (function (global){
  3503. 'use strict';
  3504. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  3505. require('./core');
  3506. var cookie = {
  3507. get: function(name) {
  3508. var cookieName = encodeURIComponent(name) + '=';
  3509. var cookieStart = document.cookie.indexOf(cookieName);
  3510. var cookieValue = null;
  3511. var cookieEnd;
  3512. if (cookieStart > -1) {
  3513. cookieEnd = document.cookie.indexOf(';', cookieStart);
  3514. if (cookieEnd == -1) {
  3515. cookieEnd = document.cookie.length;
  3516. }
  3517. cookieValue = decodeURIComponent(document.cookie.substring(cookieStart +
  3518. cookieName.length, cookieEnd));
  3519. }
  3520. return cookieValue;
  3521. },
  3522. set: function(name, value, expires, path, domain, secure) {
  3523. var cookieText = encodeURIComponent(name) + '=' +
  3524. encodeURIComponent(value);
  3525. if (expires instanceof Date) {
  3526. cookieText += '; expires=' + expires.toUTCString();
  3527. }
  3528. if (path) {
  3529. cookieText += '; path=' + path;
  3530. }
  3531. if (domain) {
  3532. cookieText += '; domain=' + domain;
  3533. }
  3534. if (secure) {
  3535. cookieText += '; secure';
  3536. }
  3537. document.cookie = cookieText;
  3538. },
  3539. unset: function(name, path, domain, secure) {
  3540. this.set(name, '', new Date(0), path, domain, secure);
  3541. }
  3542. };
  3543. $.AMUI.utils.cookie = cookie;
  3544. module.exports = cookie;
  3545. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3546. },{"./core":2}],17:[function(require,module,exports){
  3547. (function (global){
  3548. /*! Hammer.JS - v2.0.4 - 2014-09-28
  3549. * http://hammerjs.github.io/
  3550. *
  3551. * Copyright (c) 2014 Jorik Tangelder;
  3552. * Licensed under the MIT license */
  3553. 'use strict';
  3554. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  3555. var UI = require('./core');
  3556. var VENDOR_PREFIXES = ['', 'webkit', 'moz', 'MS', 'ms', 'o'];
  3557. var TEST_ELEMENT = document.createElement('div');
  3558. var TYPE_FUNCTION = 'function';
  3559. var round = Math.round;
  3560. var abs = Math.abs;
  3561. var now = Date.now;
  3562. /**
  3563. * set a timeout with a given scope
  3564. * @param {Function} fn
  3565. * @param {Number} timeout
  3566. * @param {Object} context
  3567. * @returns {number}
  3568. */
  3569. function setTimeoutContext(fn, timeout, context) {
  3570. return setTimeout(bindFn(fn, context), timeout);
  3571. }
  3572. /**
  3573. * if the argument is an array, we want to execute the fn on each entry
  3574. * if it aint an array we don't want to do a thing.
  3575. * this is used by all the methods that accept a single and array argument.
  3576. * @param {*|Array} arg
  3577. * @param {String} fn
  3578. * @param {Object} [context]
  3579. * @returns {Boolean}
  3580. */
  3581. function invokeArrayArg(arg, fn, context) {
  3582. if (Array.isArray(arg)) {
  3583. each(arg, context[fn], context);
  3584. return true;
  3585. }
  3586. return false;
  3587. }
  3588. /**
  3589. * walk objects and arrays
  3590. * @param {Object} obj
  3591. * @param {Function} iterator
  3592. * @param {Object} context
  3593. */
  3594. function each(obj, iterator, context) {
  3595. var i;
  3596. if (!obj) {
  3597. return;
  3598. }
  3599. if (obj.forEach) {
  3600. obj.forEach(iterator, context);
  3601. } else if (obj.length !== undefined) {
  3602. i = 0;
  3603. while (i < obj.length) {
  3604. iterator.call(context, obj[i], i, obj);
  3605. i++;
  3606. }
  3607. } else {
  3608. for (i in obj) {
  3609. obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
  3610. }
  3611. }
  3612. }
  3613. /**
  3614. * extend object.
  3615. * means that properties in dest will be overwritten by the ones in src.
  3616. * @param {Object} dest
  3617. * @param {Object} src
  3618. * @param {Boolean} [merge]
  3619. * @returns {Object} dest
  3620. */
  3621. function extend(dest, src, merge) {
  3622. var keys = Object.keys(src);
  3623. var i = 0;
  3624. while (i < keys.length) {
  3625. if (!merge || (merge && dest[keys[i]] === undefined)) {
  3626. dest[keys[i]] = src[keys[i]];
  3627. }
  3628. i++;
  3629. }
  3630. return dest;
  3631. }
  3632. /**
  3633. * merge the values from src in the dest.
  3634. * means that properties that exist in dest will not be overwritten by src
  3635. * @param {Object} dest
  3636. * @param {Object} src
  3637. * @returns {Object} dest
  3638. */
  3639. function merge(dest, src) {
  3640. return extend(dest, src, true);
  3641. }
  3642. /**
  3643. * simple class inheritance
  3644. * @param {Function} child
  3645. * @param {Function} base
  3646. * @param {Object} [properties]
  3647. */
  3648. function inherit(child, base, properties) {
  3649. var baseP = base.prototype,
  3650. childP;
  3651. childP = child.prototype = Object.create(baseP);
  3652. childP.constructor = child;
  3653. childP._super = baseP;
  3654. if (properties) {
  3655. extend(childP, properties);
  3656. }
  3657. }
  3658. /**
  3659. * simple function bind
  3660. * @param {Function} fn
  3661. * @param {Object} context
  3662. * @returns {Function}
  3663. */
  3664. function bindFn(fn, context) {
  3665. return function boundFn() {
  3666. return fn.apply(context, arguments);
  3667. };
  3668. }
  3669. /**
  3670. * let a boolean value also be a function that must return a boolean
  3671. * this first item in args will be used as the context
  3672. * @param {Boolean|Function} val
  3673. * @param {Array} [args]
  3674. * @returns {Boolean}
  3675. */
  3676. function boolOrFn(val, args) {
  3677. if (typeof val == TYPE_FUNCTION) {
  3678. return val.apply(args ? args[0] || undefined : undefined, args);
  3679. }
  3680. return val;
  3681. }
  3682. /**
  3683. * use the val2 when val1 is undefined
  3684. * @param {*} val1
  3685. * @param {*} val2
  3686. * @returns {*}
  3687. */
  3688. function ifUndefined(val1, val2) {
  3689. return (val1 === undefined) ? val2 : val1;
  3690. }
  3691. /**
  3692. * addEventListener with multiple events at once
  3693. * @param {EventTarget} target
  3694. * @param {String} types
  3695. * @param {Function} handler
  3696. */
  3697. function addEventListeners(target, types, handler) {
  3698. each(splitStr(types), function(type) {
  3699. target.addEventListener(type, handler, false);
  3700. });
  3701. }
  3702. /**
  3703. * removeEventListener with multiple events at once
  3704. * @param {EventTarget} target
  3705. * @param {String} types
  3706. * @param {Function} handler
  3707. */
  3708. function removeEventListeners(target, types, handler) {
  3709. each(splitStr(types), function(type) {
  3710. target.removeEventListener(type, handler, false);
  3711. });
  3712. }
  3713. /**
  3714. * find if a node is in the given parent
  3715. * @method hasParent
  3716. * @param {HTMLElement} node
  3717. * @param {HTMLElement} parent
  3718. * @return {Boolean} found
  3719. */
  3720. function hasParent(node, parent) {
  3721. while (node) {
  3722. if (node == parent) {
  3723. return true;
  3724. }
  3725. node = node.parentNode;
  3726. }
  3727. return false;
  3728. }
  3729. /**
  3730. * small indexOf wrapper
  3731. * @param {String} str
  3732. * @param {String} find
  3733. * @returns {Boolean} found
  3734. */
  3735. function inStr(str, find) {
  3736. return str.indexOf(find) > -1;
  3737. }
  3738. /**
  3739. * split string on whitespace
  3740. * @param {String} str
  3741. * @returns {Array} words
  3742. */
  3743. function splitStr(str) {
  3744. return str.trim().split(/\s+/g);
  3745. }
  3746. /**
  3747. * find if a array contains the object using indexOf or a simple polyFill
  3748. * @param {Array} src
  3749. * @param {String} find
  3750. * @param {String} [findByKey]
  3751. * @return {Boolean|Number} false when not found, or the index
  3752. */
  3753. function inArray(src, find, findByKey) {
  3754. if (src.indexOf && !findByKey) {
  3755. return src.indexOf(find);
  3756. } else {
  3757. var i = 0;
  3758. while (i < src.length) {
  3759. if ((findByKey && src[i][findByKey] == find) || (!findByKey && src[i] === find)) {
  3760. return i;
  3761. }
  3762. i++;
  3763. }
  3764. return -1;
  3765. }
  3766. }
  3767. /**
  3768. * convert array-like objects to real arrays
  3769. * @param {Object} obj
  3770. * @returns {Array}
  3771. */
  3772. function toArray(obj) {
  3773. return Array.prototype.slice.call(obj, 0);
  3774. }
  3775. /**
  3776. * unique array with objects based on a key (like 'id') or just by the array's value
  3777. * @param {Array} src [{id:1},{id:2},{id:1}]
  3778. * @param {String} [key]
  3779. * @param {Boolean} [sort=False]
  3780. * @returns {Array} [{id:1},{id:2}]
  3781. */
  3782. function uniqueArray(src, key, sort) {
  3783. var results = [];
  3784. var values = [];
  3785. var i = 0;
  3786. while (i < src.length) {
  3787. var val = key ? src[i][key] : src[i];
  3788. if (inArray(values, val) < 0) {
  3789. results.push(src[i]);
  3790. }
  3791. values[i] = val;
  3792. i++;
  3793. }
  3794. if (sort) {
  3795. if (!key) {
  3796. results = results.sort();
  3797. } else {
  3798. results = results.sort(function sortUniqueArray(a, b) {
  3799. return a[key] > b[key];
  3800. });
  3801. }
  3802. }
  3803. return results;
  3804. }
  3805. /**
  3806. * get the prefixed property
  3807. * @param {Object} obj
  3808. * @param {String} property
  3809. * @returns {String|Undefined} prefixed
  3810. */
  3811. function prefixed(obj, property) {
  3812. var prefix, prop;
  3813. var camelProp = property[0].toUpperCase() + property.slice(1);
  3814. var i = 0;
  3815. while (i < VENDOR_PREFIXES.length) {
  3816. prefix = VENDOR_PREFIXES[i];
  3817. prop = (prefix) ? prefix + camelProp : property;
  3818. if (prop in obj) {
  3819. return prop;
  3820. }
  3821. i++;
  3822. }
  3823. return undefined;
  3824. }
  3825. /**
  3826. * get a unique id
  3827. * @returns {number} uniqueId
  3828. */
  3829. var _uniqueId = 1;
  3830. function uniqueId() {
  3831. return _uniqueId++;
  3832. }
  3833. /**
  3834. * get the window object of an element
  3835. * @param {HTMLElement} element
  3836. * @returns {DocumentView|Window}
  3837. */
  3838. function getWindowForElement(element) {
  3839. var doc = element.ownerDocument;
  3840. return (doc.defaultView || doc.parentWindow);
  3841. }
  3842. var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
  3843. var SUPPORT_TOUCH = ('ontouchstart' in window);
  3844. var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined;
  3845. var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
  3846. var INPUT_TYPE_TOUCH = 'touch';
  3847. var INPUT_TYPE_PEN = 'pen';
  3848. var INPUT_TYPE_MOUSE = 'mouse';
  3849. var INPUT_TYPE_KINECT = 'kinect';
  3850. var COMPUTE_INTERVAL = 25;
  3851. var INPUT_START = 1;
  3852. var INPUT_MOVE = 2;
  3853. var INPUT_END = 4;
  3854. var INPUT_CANCEL = 8;
  3855. var DIRECTION_NONE = 1;
  3856. var DIRECTION_LEFT = 2;
  3857. var DIRECTION_RIGHT = 4;
  3858. var DIRECTION_UP = 8;
  3859. var DIRECTION_DOWN = 16;
  3860. var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
  3861. var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
  3862. var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
  3863. var PROPS_XY = ['x', 'y'];
  3864. var PROPS_CLIENT_XY = ['clientX', 'clientY'];
  3865. /**
  3866. * create new input type manager
  3867. * @param {Manager} manager
  3868. * @param {Function} callback
  3869. * @returns {Input}
  3870. * @constructor
  3871. */
  3872. function Input(manager, callback) {
  3873. var self = this;
  3874. this.manager = manager;
  3875. this.callback = callback;
  3876. this.element = manager.element;
  3877. this.target = manager.options.inputTarget;
  3878. // smaller wrapper around the handler, for the scope and the enabled state of the manager,
  3879. // so when disabled the input events are completely bypassed.
  3880. this.domHandler = function(ev) {
  3881. if (boolOrFn(manager.options.enable, [manager])) {
  3882. self.handler(ev);
  3883. }
  3884. };
  3885. this.init();
  3886. }
  3887. Input.prototype = {
  3888. /**
  3889. * should handle the inputEvent data and trigger the callback
  3890. * @virtual
  3891. */
  3892. handler: function() {
  3893. },
  3894. /**
  3895. * bind the events
  3896. */
  3897. init: function() {
  3898. this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
  3899. this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
  3900. this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
  3901. },
  3902. /**
  3903. * unbind the events
  3904. */
  3905. destroy: function() {
  3906. this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
  3907. this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
  3908. this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
  3909. }
  3910. };
  3911. /**
  3912. * create new input type manager
  3913. * called by the Manager constructor
  3914. * @param {Hammer} manager
  3915. * @returns {Input}
  3916. */
  3917. function createInputInstance(manager) {
  3918. var Type;
  3919. var inputClass = manager.options.inputClass;
  3920. if (inputClass) {
  3921. Type = inputClass;
  3922. } else if (SUPPORT_POINTER_EVENTS) {
  3923. Type = PointerEventInput;
  3924. } else if (SUPPORT_ONLY_TOUCH) {
  3925. Type = TouchInput;
  3926. } else if (!SUPPORT_TOUCH) {
  3927. Type = MouseInput;
  3928. } else {
  3929. Type = TouchMouseInput;
  3930. }
  3931. return new (Type)(manager, inputHandler);
  3932. }
  3933. /**
  3934. * handle input events
  3935. * @param {Manager} manager
  3936. * @param {String} eventType
  3937. * @param {Object} input
  3938. */
  3939. function inputHandler(manager, eventType, input) {
  3940. var pointersLen = input.pointers.length;
  3941. var changedPointersLen = input.changedPointers.length;
  3942. var isFirst = (eventType & INPUT_START && (pointersLen - changedPointersLen === 0));
  3943. var isFinal = (eventType & (INPUT_END | INPUT_CANCEL) && (pointersLen - changedPointersLen === 0));
  3944. input.isFirst = !!isFirst;
  3945. input.isFinal = !!isFinal;
  3946. if (isFirst) {
  3947. manager.session = {};
  3948. }
  3949. // source event is the normalized value of the domEvents
  3950. // like 'touchstart, mouseup, pointerdown'
  3951. input.eventType = eventType;
  3952. // compute scale, rotation etc
  3953. computeInputData(manager, input);
  3954. // emit secret event
  3955. manager.emit('hammer.input', input);
  3956. manager.recognize(input);
  3957. manager.session.prevInput = input;
  3958. }
  3959. /**
  3960. * extend the data with some usable properties like scale, rotate, velocity etc
  3961. * @param {Object} manager
  3962. * @param {Object} input
  3963. */
  3964. function computeInputData(manager, input) {
  3965. var session = manager.session;
  3966. var pointers = input.pointers;
  3967. var pointersLength = pointers.length;
  3968. // store the first input to calculate the distance and direction
  3969. if (!session.firstInput) {
  3970. session.firstInput = simpleCloneInputData(input);
  3971. }
  3972. // to compute scale and rotation we need to store the multiple touches
  3973. if (pointersLength > 1 && !session.firstMultiple) {
  3974. session.firstMultiple = simpleCloneInputData(input);
  3975. } else if (pointersLength === 1) {
  3976. session.firstMultiple = false;
  3977. }
  3978. var firstInput = session.firstInput;
  3979. var firstMultiple = session.firstMultiple;
  3980. var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
  3981. var center = input.center = getCenter(pointers);
  3982. input.timeStamp = now();
  3983. input.deltaTime = input.timeStamp - firstInput.timeStamp;
  3984. input.angle = getAngle(offsetCenter, center);
  3985. input.distance = getDistance(offsetCenter, center);
  3986. computeDeltaXY(session, input);
  3987. input.offsetDirection = getDirection(input.deltaX, input.deltaY);
  3988. input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
  3989. input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
  3990. computeIntervalInputData(session, input);
  3991. // find the correct target
  3992. var target = manager.element;
  3993. if (hasParent(input.srcEvent.target, target)) {
  3994. target = input.srcEvent.target;
  3995. }
  3996. input.target = target;
  3997. }
  3998. function computeDeltaXY(session, input) {
  3999. var center = input.center;
  4000. var offset = session.offsetDelta || {};
  4001. var prevDelta = session.prevDelta || {};
  4002. var prevInput = session.prevInput || {};
  4003. if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
  4004. prevDelta = session.prevDelta = {
  4005. x: prevInput.deltaX || 0,
  4006. y: prevInput.deltaY || 0
  4007. };
  4008. offset = session.offsetDelta = {
  4009. x: center.x,
  4010. y: center.y
  4011. };
  4012. }
  4013. input.deltaX = prevDelta.x + (center.x - offset.x);
  4014. input.deltaY = prevDelta.y + (center.y - offset.y);
  4015. }
  4016. /**
  4017. * velocity is calculated every x ms
  4018. * @param {Object} session
  4019. * @param {Object} input
  4020. */
  4021. function computeIntervalInputData(session, input) {
  4022. var last = session.lastInterval || input,
  4023. deltaTime = input.timeStamp - last.timeStamp,
  4024. velocity, velocityX, velocityY, direction;
  4025. if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
  4026. var deltaX = last.deltaX - input.deltaX;
  4027. var deltaY = last.deltaY - input.deltaY;
  4028. var v = getVelocity(deltaTime, deltaX, deltaY);
  4029. velocityX = v.x;
  4030. velocityY = v.y;
  4031. velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y;
  4032. direction = getDirection(deltaX, deltaY);
  4033. session.lastInterval = input;
  4034. } else {
  4035. // use latest velocity info if it doesn't overtake a minimum period
  4036. velocity = last.velocity;
  4037. velocityX = last.velocityX;
  4038. velocityY = last.velocityY;
  4039. direction = last.direction;
  4040. }
  4041. input.velocity = velocity;
  4042. input.velocityX = velocityX;
  4043. input.velocityY = velocityY;
  4044. input.direction = direction;
  4045. }
  4046. /**
  4047. * create a simple clone from the input used for storage of firstInput and firstMultiple
  4048. * @param {Object} input
  4049. * @returns {Object} clonedInputData
  4050. */
  4051. function simpleCloneInputData(input) {
  4052. // make a simple copy of the pointers because we will get a reference if we don't
  4053. // we only need clientXY for the calculations
  4054. var pointers = [];
  4055. var i = 0;
  4056. while (i < input.pointers.length) {
  4057. pointers[i] = {
  4058. clientX: round(input.pointers[i].clientX),
  4059. clientY: round(input.pointers[i].clientY)
  4060. };
  4061. i++;
  4062. }
  4063. return {
  4064. timeStamp: now(),
  4065. pointers: pointers,
  4066. center: getCenter(pointers),
  4067. deltaX: input.deltaX,
  4068. deltaY: input.deltaY
  4069. };
  4070. }
  4071. /**
  4072. * get the center of all the pointers
  4073. * @param {Array} pointers
  4074. * @return {Object} center contains `x` and `y` properties
  4075. */
  4076. function getCenter(pointers) {
  4077. var pointersLength = pointers.length;
  4078. // no need to loop when only one touch
  4079. if (pointersLength === 1) {
  4080. return {
  4081. x: round(pointers[0].clientX),
  4082. y: round(pointers[0].clientY)
  4083. };
  4084. }
  4085. var x = 0, y = 0, i = 0;
  4086. while (i < pointersLength) {
  4087. x += pointers[i].clientX;
  4088. y += pointers[i].clientY;
  4089. i++;
  4090. }
  4091. return {
  4092. x: round(x / pointersLength),
  4093. y: round(y / pointersLength)
  4094. };
  4095. }
  4096. /**
  4097. * calculate the velocity between two points. unit is in px per ms.
  4098. * @param {Number} deltaTime
  4099. * @param {Number} x
  4100. * @param {Number} y
  4101. * @return {Object} velocity `x` and `y`
  4102. */
  4103. function getVelocity(deltaTime, x, y) {
  4104. return {
  4105. x: x / deltaTime || 0,
  4106. y: y / deltaTime || 0
  4107. };
  4108. }
  4109. /**
  4110. * get the direction between two points
  4111. * @param {Number} x
  4112. * @param {Number} y
  4113. * @return {Number} direction
  4114. */
  4115. function getDirection(x, y) {
  4116. if (x === y) {
  4117. return DIRECTION_NONE;
  4118. }
  4119. if (abs(x) >= abs(y)) {
  4120. return x > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
  4121. }
  4122. return y > 0 ? DIRECTION_UP : DIRECTION_DOWN;
  4123. }
  4124. /**
  4125. * calculate the absolute distance between two points
  4126. * @param {Object} p1 {x, y}
  4127. * @param {Object} p2 {x, y}
  4128. * @param {Array} [props] containing x and y keys
  4129. * @return {Number} distance
  4130. */
  4131. function getDistance(p1, p2, props) {
  4132. if (!props) {
  4133. props = PROPS_XY;
  4134. }
  4135. var x = p2[props[0]] - p1[props[0]],
  4136. y = p2[props[1]] - p1[props[1]];
  4137. return Math.sqrt((x * x) + (y * y));
  4138. }
  4139. /**
  4140. * calculate the angle between two coordinates
  4141. * @param {Object} p1
  4142. * @param {Object} p2
  4143. * @param {Array} [props] containing x and y keys
  4144. * @return {Number} angle
  4145. */
  4146. function getAngle(p1, p2, props) {
  4147. if (!props) {
  4148. props = PROPS_XY;
  4149. }
  4150. var x = p2[props[0]] - p1[props[0]],
  4151. y = p2[props[1]] - p1[props[1]];
  4152. return Math.atan2(y, x) * 180 / Math.PI;
  4153. }
  4154. /**
  4155. * calculate the rotation degrees between two pointersets
  4156. * @param {Array} start array of pointers
  4157. * @param {Array} end array of pointers
  4158. * @return {Number} rotation
  4159. */
  4160. function getRotation(start, end) {
  4161. return getAngle(end[1], end[0], PROPS_CLIENT_XY) - getAngle(start[1], start[0], PROPS_CLIENT_XY);
  4162. }
  4163. /**
  4164. * calculate the scale factor between two pointersets
  4165. * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
  4166. * @param {Array} start array of pointers
  4167. * @param {Array} end array of pointers
  4168. * @return {Number} scale
  4169. */
  4170. function getScale(start, end) {
  4171. return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
  4172. }
  4173. var MOUSE_INPUT_MAP = {
  4174. mousedown: INPUT_START,
  4175. mousemove: INPUT_MOVE,
  4176. mouseup: INPUT_END
  4177. };
  4178. var MOUSE_ELEMENT_EVENTS = 'mousedown';
  4179. var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
  4180. /**
  4181. * Mouse events input
  4182. * @constructor
  4183. * @extends Input
  4184. */
  4185. function MouseInput() {
  4186. this.evEl = MOUSE_ELEMENT_EVENTS;
  4187. this.evWin = MOUSE_WINDOW_EVENTS;
  4188. this.allow = true; // used by Input.TouchMouse to disable mouse events
  4189. this.pressed = false; // mousedown state
  4190. Input.apply(this, arguments);
  4191. }
  4192. inherit(MouseInput, Input, {
  4193. /**
  4194. * handle mouse events
  4195. * @param {Object} ev
  4196. */
  4197. handler: function MEhandler(ev) {
  4198. var eventType = MOUSE_INPUT_MAP[ev.type];
  4199. // on start we want to have the left mouse button down
  4200. if (eventType & INPUT_START && ev.button === 0) {
  4201. this.pressed = true;
  4202. }
  4203. if (eventType & INPUT_MOVE && ev.which !== 1) {
  4204. eventType = INPUT_END;
  4205. }
  4206. // mouse must be down, and mouse events are allowed (see the TouchMouse input)
  4207. if (!this.pressed || !this.allow) {
  4208. return;
  4209. }
  4210. if (eventType & INPUT_END) {
  4211. this.pressed = false;
  4212. }
  4213. this.callback(this.manager, eventType, {
  4214. pointers: [ev],
  4215. changedPointers: [ev],
  4216. pointerType: INPUT_TYPE_MOUSE,
  4217. srcEvent: ev
  4218. });
  4219. }
  4220. });
  4221. var POINTER_INPUT_MAP = {
  4222. pointerdown: INPUT_START,
  4223. pointermove: INPUT_MOVE,
  4224. pointerup: INPUT_END,
  4225. pointercancel: INPUT_CANCEL,
  4226. pointerout: INPUT_CANCEL
  4227. };
  4228. // in IE10 the pointer types is defined as an enum
  4229. var IE10_POINTER_TYPE_ENUM = {
  4230. 2: INPUT_TYPE_TOUCH,
  4231. 3: INPUT_TYPE_PEN,
  4232. 4: INPUT_TYPE_MOUSE,
  4233. 5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816
  4234. };
  4235. var POINTER_ELEMENT_EVENTS = 'pointerdown';
  4236. var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
  4237. // IE10 has prefixed support, and case-sensitive
  4238. if (window.MSPointerEvent) {
  4239. POINTER_ELEMENT_EVENTS = 'MSPointerDown';
  4240. POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
  4241. }
  4242. /**
  4243. * Pointer events input
  4244. * @constructor
  4245. * @extends Input
  4246. */
  4247. function PointerEventInput() {
  4248. this.evEl = POINTER_ELEMENT_EVENTS;
  4249. this.evWin = POINTER_WINDOW_EVENTS;
  4250. Input.apply(this, arguments);
  4251. this.store = (this.manager.session.pointerEvents = []);
  4252. }
  4253. inherit(PointerEventInput, Input, {
  4254. /**
  4255. * handle mouse events
  4256. * @param {Object} ev
  4257. */
  4258. handler: function PEhandler(ev) {
  4259. var store = this.store;
  4260. var removePointer = false;
  4261. var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
  4262. var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
  4263. var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
  4264. var isTouch = (pointerType == INPUT_TYPE_TOUCH);
  4265. // get index of the event in the store
  4266. var storeIndex = inArray(store, ev.pointerId, 'pointerId');
  4267. // start and mouse must be down
  4268. if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
  4269. if (storeIndex < 0) {
  4270. store.push(ev);
  4271. storeIndex = store.length - 1;
  4272. }
  4273. } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
  4274. removePointer = true;
  4275. }
  4276. // it not found, so the pointer hasn't been down (so it's probably a hover)
  4277. if (storeIndex < 0) {
  4278. return;
  4279. }
  4280. // update the event in the store
  4281. store[storeIndex] = ev;
  4282. this.callback(this.manager, eventType, {
  4283. pointers: store,
  4284. changedPointers: [ev],
  4285. pointerType: pointerType,
  4286. srcEvent: ev
  4287. });
  4288. if (removePointer) {
  4289. // remove from the store
  4290. store.splice(storeIndex, 1);
  4291. }
  4292. }
  4293. });
  4294. var SINGLE_TOUCH_INPUT_MAP = {
  4295. touchstart: INPUT_START,
  4296. touchmove: INPUT_MOVE,
  4297. touchend: INPUT_END,
  4298. touchcancel: INPUT_CANCEL
  4299. };
  4300. var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
  4301. var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
  4302. /**
  4303. * Touch events input
  4304. * @constructor
  4305. * @extends Input
  4306. */
  4307. function SingleTouchInput() {
  4308. this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
  4309. this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
  4310. this.started = false;
  4311. Input.apply(this, arguments);
  4312. }
  4313. inherit(SingleTouchInput, Input, {
  4314. handler: function TEhandler(ev) {
  4315. var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
  4316. // should we handle the touch events?
  4317. if (type === INPUT_START) {
  4318. this.started = true;
  4319. }
  4320. if (!this.started) {
  4321. return;
  4322. }
  4323. var touches = normalizeSingleTouches.call(this, ev, type);
  4324. // when done, reset the started state
  4325. if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
  4326. this.started = false;
  4327. }
  4328. this.callback(this.manager, type, {
  4329. pointers: touches[0],
  4330. changedPointers: touches[1],
  4331. pointerType: INPUT_TYPE_TOUCH,
  4332. srcEvent: ev
  4333. });
  4334. }
  4335. });
  4336. /**
  4337. * @this {TouchInput}
  4338. * @param {Object} ev
  4339. * @param {Number} type flag
  4340. * @returns {undefined|Array} [all, changed]
  4341. */
  4342. function normalizeSingleTouches(ev, type) {
  4343. var all = toArray(ev.touches);
  4344. var changed = toArray(ev.changedTouches);
  4345. if (type & (INPUT_END | INPUT_CANCEL)) {
  4346. all = uniqueArray(all.concat(changed), 'identifier', true);
  4347. }
  4348. return [all, changed];
  4349. }
  4350. var TOUCH_INPUT_MAP = {
  4351. touchstart: INPUT_START,
  4352. touchmove: INPUT_MOVE,
  4353. touchend: INPUT_END,
  4354. touchcancel: INPUT_CANCEL
  4355. };
  4356. var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
  4357. /**
  4358. * Multi-user touch events input
  4359. * @constructor
  4360. * @extends Input
  4361. */
  4362. function TouchInput() {
  4363. this.evTarget = TOUCH_TARGET_EVENTS;
  4364. this.targetIds = {};
  4365. Input.apply(this, arguments);
  4366. }
  4367. inherit(TouchInput, Input, {
  4368. handler: function MTEhandler(ev) {
  4369. var type = TOUCH_INPUT_MAP[ev.type];
  4370. var touches = getTouches.call(this, ev, type);
  4371. if (!touches) {
  4372. return;
  4373. }
  4374. this.callback(this.manager, type, {
  4375. pointers: touches[0],
  4376. changedPointers: touches[1],
  4377. pointerType: INPUT_TYPE_TOUCH,
  4378. srcEvent: ev
  4379. });
  4380. }
  4381. });
  4382. /**
  4383. * @this {TouchInput}
  4384. * @param {Object} ev
  4385. * @param {Number} type flag
  4386. * @returns {undefined|Array} [all, changed]
  4387. */
  4388. function getTouches(ev, type) {
  4389. var allTouches = toArray(ev.touches);
  4390. var targetIds = this.targetIds;
  4391. // when there is only one touch, the process can be simplified
  4392. if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
  4393. targetIds[allTouches[0].identifier] = true;
  4394. return [allTouches, allTouches];
  4395. }
  4396. var i,
  4397. targetTouches,
  4398. changedTouches = toArray(ev.changedTouches),
  4399. changedTargetTouches = [],
  4400. target = this.target;
  4401. // get target touches from touches
  4402. targetTouches = allTouches.filter(function(touch) {
  4403. return hasParent(touch.target, target);
  4404. });
  4405. // collect touches
  4406. if (type === INPUT_START) {
  4407. i = 0;
  4408. while (i < targetTouches.length) {
  4409. targetIds[targetTouches[i].identifier] = true;
  4410. i++;
  4411. }
  4412. }
  4413. // filter changed touches to only contain touches that exist in the collected target ids
  4414. i = 0;
  4415. while (i < changedTouches.length) {
  4416. if (targetIds[changedTouches[i].identifier]) {
  4417. changedTargetTouches.push(changedTouches[i]);
  4418. }
  4419. // cleanup removed touches
  4420. if (type & (INPUT_END | INPUT_CANCEL)) {
  4421. delete targetIds[changedTouches[i].identifier];
  4422. }
  4423. i++;
  4424. }
  4425. if (!changedTargetTouches.length) {
  4426. return;
  4427. }
  4428. return [
  4429. // merge targetTouches with changedTargetTouches so it contains ALL touches, including 'end' and 'cancel'
  4430. uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true),
  4431. changedTargetTouches
  4432. ];
  4433. }
  4434. /**
  4435. * Combined touch and mouse input
  4436. *
  4437. * Touch has a higher priority then mouse, and while touching no mouse events are allowed.
  4438. * This because touch devices also emit mouse events while doing a touch.
  4439. *
  4440. * @constructor
  4441. * @extends Input
  4442. */
  4443. function TouchMouseInput() {
  4444. Input.apply(this, arguments);
  4445. var handler = bindFn(this.handler, this);
  4446. this.touch = new TouchInput(this.manager, handler);
  4447. this.mouse = new MouseInput(this.manager, handler);
  4448. }
  4449. inherit(TouchMouseInput, Input, {
  4450. /**
  4451. * handle mouse and touch events
  4452. * @param {Hammer} manager
  4453. * @param {String} inputEvent
  4454. * @param {Object} inputData
  4455. */
  4456. handler: function TMEhandler(manager, inputEvent, inputData) {
  4457. var isTouch = (inputData.pointerType == INPUT_TYPE_TOUCH),
  4458. isMouse = (inputData.pointerType == INPUT_TYPE_MOUSE);
  4459. // when we're in a touch event, so block all upcoming mouse events
  4460. // most mobile browser also emit mouseevents, right after touchstart
  4461. if (isTouch) {
  4462. this.mouse.allow = false;
  4463. } else if (isMouse && !this.mouse.allow) {
  4464. return;
  4465. }
  4466. // reset the allowMouse when we're done
  4467. if (inputEvent & (INPUT_END | INPUT_CANCEL)) {
  4468. this.mouse.allow = true;
  4469. }
  4470. this.callback(manager, inputEvent, inputData);
  4471. },
  4472. /**
  4473. * remove the event listeners
  4474. */
  4475. destroy: function destroy() {
  4476. this.touch.destroy();
  4477. this.mouse.destroy();
  4478. }
  4479. });
  4480. var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
  4481. var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
  4482. // magical touchAction value
  4483. var TOUCH_ACTION_COMPUTE = 'compute';
  4484. var TOUCH_ACTION_AUTO = 'auto';
  4485. var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented
  4486. var TOUCH_ACTION_NONE = 'none';
  4487. var TOUCH_ACTION_PAN_X = 'pan-x';
  4488. var TOUCH_ACTION_PAN_Y = 'pan-y';
  4489. /**
  4490. * Touch Action
  4491. * sets the touchAction property or uses the js alternative
  4492. * @param {Manager} manager
  4493. * @param {String} value
  4494. * @constructor
  4495. */
  4496. function TouchAction(manager, value) {
  4497. this.manager = manager;
  4498. this.set(value);
  4499. }
  4500. TouchAction.prototype = {
  4501. /**
  4502. * set the touchAction value on the element or enable the polyfill
  4503. * @param {String} value
  4504. */
  4505. set: function(value) {
  4506. // find out the touch-action by the event handlers
  4507. if (value == TOUCH_ACTION_COMPUTE) {
  4508. value = this.compute();
  4509. }
  4510. if (NATIVE_TOUCH_ACTION) {
  4511. this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
  4512. }
  4513. this.actions = value.toLowerCase().trim();
  4514. },
  4515. /**
  4516. * just re-set the touchAction value
  4517. */
  4518. update: function() {
  4519. this.set(this.manager.options.touchAction);
  4520. },
  4521. /**
  4522. * compute the value for the touchAction property based on the recognizer's settings
  4523. * @returns {String} value
  4524. */
  4525. compute: function() {
  4526. var actions = [];
  4527. each(this.manager.recognizers, function(recognizer) {
  4528. if (boolOrFn(recognizer.options.enable, [recognizer])) {
  4529. actions = actions.concat(recognizer.getTouchAction());
  4530. }
  4531. });
  4532. return cleanTouchActions(actions.join(' '));
  4533. },
  4534. /**
  4535. * this method is called on each input cycle and provides the preventing of the browser behavior
  4536. * @param {Object} input
  4537. */
  4538. preventDefaults: function(input) {
  4539. // not needed with native support for the touchAction property
  4540. if (NATIVE_TOUCH_ACTION) {
  4541. return;
  4542. }
  4543. var srcEvent = input.srcEvent;
  4544. var direction = input.offsetDirection;
  4545. // if the touch action did prevented once this session
  4546. if (this.manager.session.prevented) {
  4547. srcEvent.preventDefault();
  4548. return;
  4549. }
  4550. var actions = this.actions;
  4551. var hasNone = inStr(actions, TOUCH_ACTION_NONE);
  4552. var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
  4553. var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
  4554. if (hasNone ||
  4555. (hasPanY && direction & DIRECTION_HORIZONTAL) ||
  4556. (hasPanX && direction & DIRECTION_VERTICAL)) {
  4557. return this.preventSrc(srcEvent);
  4558. }
  4559. },
  4560. /**
  4561. * call preventDefault to prevent the browser's default behavior (scrolling in most cases)
  4562. * @param {Object} srcEvent
  4563. */
  4564. preventSrc: function(srcEvent) {
  4565. this.manager.session.prevented = true;
  4566. srcEvent.preventDefault();
  4567. }
  4568. };
  4569. /**
  4570. * when the touchActions are collected they are not a valid value, so we need to clean things up. *
  4571. * @param {String} actions
  4572. * @returns {*}
  4573. */
  4574. function cleanTouchActions(actions) {
  4575. // none
  4576. if (inStr(actions, TOUCH_ACTION_NONE)) {
  4577. return TOUCH_ACTION_NONE;
  4578. }
  4579. var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
  4580. var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
  4581. // pan-x and pan-y can be combined
  4582. if (hasPanX && hasPanY) {
  4583. return TOUCH_ACTION_PAN_X + ' ' + TOUCH_ACTION_PAN_Y;
  4584. }
  4585. // pan-x OR pan-y
  4586. if (hasPanX || hasPanY) {
  4587. return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
  4588. }
  4589. // manipulation
  4590. if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
  4591. return TOUCH_ACTION_MANIPULATION;
  4592. }
  4593. return TOUCH_ACTION_AUTO;
  4594. }
  4595. /**
  4596. * Recognizer flow explained; *
  4597. * All recognizers have the initial state of POSSIBLE when a input session starts.
  4598. * The definition of a input session is from the first input until the last input, with all it's movement in it. *
  4599. * Example session for mouse-input: mousedown -> mousemove -> mouseup
  4600. *
  4601. * On each recognizing cycle (see Manager.recognize) the .recognize() method is executed
  4602. * which determines with state it should be.
  4603. *
  4604. * If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to
  4605. * POSSIBLE to give it another change on the next cycle.
  4606. *
  4607. * Possible
  4608. * |
  4609. * +-----+---------------+
  4610. * | |
  4611. * +-----+-----+ |
  4612. * | | |
  4613. * Failed Cancelled |
  4614. * +-------+------+
  4615. * | |
  4616. * Recognized Began
  4617. * |
  4618. * Changed
  4619. * |
  4620. * Ended/Recognized
  4621. */
  4622. var STATE_POSSIBLE = 1;
  4623. var STATE_BEGAN = 2;
  4624. var STATE_CHANGED = 4;
  4625. var STATE_ENDED = 8;
  4626. var STATE_RECOGNIZED = STATE_ENDED;
  4627. var STATE_CANCELLED = 16;
  4628. var STATE_FAILED = 32;
  4629. /**
  4630. * Recognizer
  4631. * Every recognizer needs to extend from this class.
  4632. * @constructor
  4633. * @param {Object} options
  4634. */
  4635. function Recognizer(options) {
  4636. this.id = uniqueId();
  4637. this.manager = null;
  4638. this.options = merge(options || {}, this.defaults);
  4639. // default is enable true
  4640. this.options.enable = ifUndefined(this.options.enable, true);
  4641. this.state = STATE_POSSIBLE;
  4642. this.simultaneous = {};
  4643. this.requireFail = [];
  4644. }
  4645. Recognizer.prototype = {
  4646. /**
  4647. * @virtual
  4648. * @type {Object}
  4649. */
  4650. defaults: {},
  4651. /**
  4652. * set options
  4653. * @param {Object} options
  4654. * @return {Recognizer}
  4655. */
  4656. set: function(options) {
  4657. extend(this.options, options);
  4658. // also update the touchAction, in case something changed about the directions/enabled state
  4659. this.manager && this.manager.touchAction.update();
  4660. return this;
  4661. },
  4662. /**
  4663. * recognize simultaneous with an other recognizer.
  4664. * @param {Recognizer} otherRecognizer
  4665. * @returns {Recognizer} this
  4666. */
  4667. recognizeWith: function(otherRecognizer) {
  4668. if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
  4669. return this;
  4670. }
  4671. var simultaneous = this.simultaneous;
  4672. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  4673. if (!simultaneous[otherRecognizer.id]) {
  4674. simultaneous[otherRecognizer.id] = otherRecognizer;
  4675. otherRecognizer.recognizeWith(this);
  4676. }
  4677. return this;
  4678. },
  4679. /**
  4680. * drop the simultaneous link. it doesnt remove the link on the other recognizer.
  4681. * @param {Recognizer} otherRecognizer
  4682. * @returns {Recognizer} this
  4683. */
  4684. dropRecognizeWith: function(otherRecognizer) {
  4685. if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
  4686. return this;
  4687. }
  4688. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  4689. delete this.simultaneous[otherRecognizer.id];
  4690. return this;
  4691. },
  4692. /**
  4693. * recognizer can only run when an other is failing
  4694. * @param {Recognizer} otherRecognizer
  4695. * @returns {Recognizer} this
  4696. */
  4697. requireFailure: function(otherRecognizer) {
  4698. if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
  4699. return this;
  4700. }
  4701. var requireFail = this.requireFail;
  4702. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  4703. if (inArray(requireFail, otherRecognizer) === -1) {
  4704. requireFail.push(otherRecognizer);
  4705. otherRecognizer.requireFailure(this);
  4706. }
  4707. return this;
  4708. },
  4709. /**
  4710. * drop the requireFailure link. it does not remove the link on the other recognizer.
  4711. * @param {Recognizer} otherRecognizer
  4712. * @returns {Recognizer} this
  4713. */
  4714. dropRequireFailure: function(otherRecognizer) {
  4715. if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
  4716. return this;
  4717. }
  4718. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  4719. var index = inArray(this.requireFail, otherRecognizer);
  4720. if (index > -1) {
  4721. this.requireFail.splice(index, 1);
  4722. }
  4723. return this;
  4724. },
  4725. /**
  4726. * has require failures boolean
  4727. * @returns {boolean}
  4728. */
  4729. hasRequireFailures: function() {
  4730. return this.requireFail.length > 0;
  4731. },
  4732. /**
  4733. * if the recognizer can recognize simultaneous with an other recognizer
  4734. * @param {Recognizer} otherRecognizer
  4735. * @returns {Boolean}
  4736. */
  4737. canRecognizeWith: function(otherRecognizer) {
  4738. return !!this.simultaneous[otherRecognizer.id];
  4739. },
  4740. /**
  4741. * You should use `tryEmit` instead of `emit` directly to check
  4742. * that all the needed recognizers has failed before emitting.
  4743. * @param {Object} input
  4744. */
  4745. emit: function(input) {
  4746. var self = this;
  4747. var state = this.state;
  4748. function emit(withState) {
  4749. self.manager.emit(self.options.event + (withState ? stateStr(state) : ''), input);
  4750. }
  4751. // 'panstart' and 'panmove'
  4752. if (state < STATE_ENDED) {
  4753. emit(true);
  4754. }
  4755. emit(); // simple 'eventName' events
  4756. // panend and pancancel
  4757. if (state >= STATE_ENDED) {
  4758. emit(true);
  4759. }
  4760. },
  4761. /**
  4762. * Check that all the require failure recognizers has failed,
  4763. * if true, it emits a gesture event,
  4764. * otherwise, setup the state to FAILED.
  4765. * @param {Object} input
  4766. */
  4767. tryEmit: function(input) {
  4768. if (this.canEmit()) {
  4769. return this.emit(input);
  4770. }
  4771. // it's failing anyway
  4772. this.state = STATE_FAILED;
  4773. },
  4774. /**
  4775. * can we emit?
  4776. * @returns {boolean}
  4777. */
  4778. canEmit: function() {
  4779. var i = 0;
  4780. while (i < this.requireFail.length) {
  4781. if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
  4782. return false;
  4783. }
  4784. i++;
  4785. }
  4786. return true;
  4787. },
  4788. /**
  4789. * update the recognizer
  4790. * @param {Object} inputData
  4791. */
  4792. recognize: function(inputData) {
  4793. // make a new copy of the inputData
  4794. // so we can change the inputData without messing up the other recognizers
  4795. var inputDataClone = extend({}, inputData);
  4796. // is is enabled and allow recognizing?
  4797. if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
  4798. this.reset();
  4799. this.state = STATE_FAILED;
  4800. return;
  4801. }
  4802. // reset when we've reached the end
  4803. if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
  4804. this.state = STATE_POSSIBLE;
  4805. }
  4806. this.state = this.process(inputDataClone);
  4807. // the recognizer has recognized a gesture
  4808. // so trigger an event
  4809. if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
  4810. this.tryEmit(inputDataClone);
  4811. }
  4812. },
  4813. /**
  4814. * return the state of the recognizer
  4815. * the actual recognizing happens in this method
  4816. * @virtual
  4817. * @param {Object} inputData
  4818. * @returns {Const} STATE
  4819. */
  4820. process: function(inputData) {
  4821. }, // jshint ignore:line
  4822. /**
  4823. * return the preferred touch-action
  4824. * @virtual
  4825. * @returns {Array}
  4826. */
  4827. getTouchAction: function() {
  4828. },
  4829. /**
  4830. * called when the gesture isn't allowed to recognize
  4831. * like when another is being recognized or it is disabled
  4832. * @virtual
  4833. */
  4834. reset: function() {
  4835. }
  4836. };
  4837. /**
  4838. * get a usable string, used as event postfix
  4839. * @param {Const} state
  4840. * @returns {String} state
  4841. */
  4842. function stateStr(state) {
  4843. if (state & STATE_CANCELLED) {
  4844. return 'cancel';
  4845. } else if (state & STATE_ENDED) {
  4846. return 'end';
  4847. } else if (state & STATE_CHANGED) {
  4848. return 'move';
  4849. } else if (state & STATE_BEGAN) {
  4850. return 'start';
  4851. }
  4852. return '';
  4853. }
  4854. /**
  4855. * direction cons to string
  4856. * @param {Const} direction
  4857. * @returns {String}
  4858. */
  4859. function directionStr(direction) {
  4860. if (direction == DIRECTION_DOWN) {
  4861. return 'down';
  4862. } else if (direction == DIRECTION_UP) {
  4863. return 'up';
  4864. } else if (direction == DIRECTION_LEFT) {
  4865. return 'left';
  4866. } else if (direction == DIRECTION_RIGHT) {
  4867. return 'right';
  4868. }
  4869. return '';
  4870. }
  4871. /**
  4872. * get a recognizer by name if it is bound to a manager
  4873. * @param {Recognizer|String} otherRecognizer
  4874. * @param {Recognizer} recognizer
  4875. * @returns {Recognizer}
  4876. */
  4877. function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
  4878. var manager = recognizer.manager;
  4879. if (manager) {
  4880. return manager.get(otherRecognizer);
  4881. }
  4882. return otherRecognizer;
  4883. }
  4884. /**
  4885. * This recognizer is just used as a base for the simple attribute recognizers.
  4886. * @constructor
  4887. * @extends Recognizer
  4888. */
  4889. function AttrRecognizer() {
  4890. Recognizer.apply(this, arguments);
  4891. }
  4892. inherit(AttrRecognizer, Recognizer, {
  4893. /**
  4894. * @namespace
  4895. * @memberof AttrRecognizer
  4896. */
  4897. defaults: {
  4898. /**
  4899. * @type {Number}
  4900. * @default 1
  4901. */
  4902. pointers: 1
  4903. },
  4904. /**
  4905. * Used to check if it the recognizer receives valid input, like input.distance > 10.
  4906. * @memberof AttrRecognizer
  4907. * @param {Object} input
  4908. * @returns {Boolean} recognized
  4909. */
  4910. attrTest: function(input) {
  4911. var optionPointers = this.options.pointers;
  4912. return optionPointers === 0 || input.pointers.length === optionPointers;
  4913. },
  4914. /**
  4915. * Process the input and return the state for the recognizer
  4916. * @memberof AttrRecognizer
  4917. * @param {Object} input
  4918. * @returns {*} State
  4919. */
  4920. process: function(input) {
  4921. var state = this.state;
  4922. var eventType = input.eventType;
  4923. var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
  4924. var isValid = this.attrTest(input);
  4925. // on cancel input and we've recognized before, return STATE_CANCELLED
  4926. if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
  4927. return state | STATE_CANCELLED;
  4928. } else if (isRecognized || isValid) {
  4929. if (eventType & INPUT_END) {
  4930. return state | STATE_ENDED;
  4931. } else if (!(state & STATE_BEGAN)) {
  4932. return STATE_BEGAN;
  4933. }
  4934. return state | STATE_CHANGED;
  4935. }
  4936. return STATE_FAILED;
  4937. }
  4938. });
  4939. /**
  4940. * Pan
  4941. * Recognized when the pointer is down and moved in the allowed direction.
  4942. * @constructor
  4943. * @extends AttrRecognizer
  4944. */
  4945. function PanRecognizer() {
  4946. AttrRecognizer.apply(this, arguments);
  4947. this.pX = null;
  4948. this.pY = null;
  4949. }
  4950. inherit(PanRecognizer, AttrRecognizer, {
  4951. /**
  4952. * @namespace
  4953. * @memberof PanRecognizer
  4954. */
  4955. defaults: {
  4956. event: 'pan',
  4957. threshold: 10,
  4958. pointers: 1,
  4959. direction: DIRECTION_ALL
  4960. },
  4961. getTouchAction: function() {
  4962. var direction = this.options.direction;
  4963. var actions = [];
  4964. if (direction & DIRECTION_HORIZONTAL) {
  4965. actions.push(TOUCH_ACTION_PAN_Y);
  4966. }
  4967. if (direction & DIRECTION_VERTICAL) {
  4968. actions.push(TOUCH_ACTION_PAN_X);
  4969. }
  4970. return actions;
  4971. },
  4972. directionTest: function(input) {
  4973. var options = this.options;
  4974. var hasMoved = true;
  4975. var distance = input.distance;
  4976. var direction = input.direction;
  4977. var x = input.deltaX;
  4978. var y = input.deltaY;
  4979. // lock to axis?
  4980. if (!(direction & options.direction)) {
  4981. if (options.direction & DIRECTION_HORIZONTAL) {
  4982. direction = (x === 0) ? DIRECTION_NONE : (x < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT;
  4983. hasMoved = x != this.pX;
  4984. distance = Math.abs(input.deltaX);
  4985. } else {
  4986. direction = (y === 0) ? DIRECTION_NONE : (y < 0) ? DIRECTION_UP : DIRECTION_DOWN;
  4987. hasMoved = y != this.pY;
  4988. distance = Math.abs(input.deltaY);
  4989. }
  4990. }
  4991. input.direction = direction;
  4992. return hasMoved && distance > options.threshold && direction & options.direction;
  4993. },
  4994. attrTest: function(input) {
  4995. return AttrRecognizer.prototype.attrTest.call(this, input) &&
  4996. (this.state & STATE_BEGAN || (!(this.state & STATE_BEGAN) && this.directionTest(input)));
  4997. },
  4998. emit: function(input) {
  4999. this.pX = input.deltaX;
  5000. this.pY = input.deltaY;
  5001. var direction = directionStr(input.direction);
  5002. if (direction) {
  5003. this.manager.emit(this.options.event + direction, input);
  5004. }
  5005. this._super.emit.call(this, input);
  5006. }
  5007. });
  5008. /**
  5009. * Pinch
  5010. * Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out).
  5011. * @constructor
  5012. * @extends AttrRecognizer
  5013. */
  5014. function PinchRecognizer() {
  5015. AttrRecognizer.apply(this, arguments);
  5016. }
  5017. inherit(PinchRecognizer, AttrRecognizer, {
  5018. /**
  5019. * @namespace
  5020. * @memberof PinchRecognizer
  5021. */
  5022. defaults: {
  5023. event: 'pinch',
  5024. threshold: 0,
  5025. pointers: 2
  5026. },
  5027. getTouchAction: function() {
  5028. return [TOUCH_ACTION_NONE];
  5029. },
  5030. attrTest: function(input) {
  5031. return this._super.attrTest.call(this, input) &&
  5032. (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
  5033. },
  5034. emit: function(input) {
  5035. this._super.emit.call(this, input);
  5036. if (input.scale !== 1) {
  5037. var inOut = input.scale < 1 ? 'in' : 'out';
  5038. this.manager.emit(this.options.event + inOut, input);
  5039. }
  5040. }
  5041. });
  5042. /**
  5043. * Press
  5044. * Recognized when the pointer is down for x ms without any movement.
  5045. * @constructor
  5046. * @extends Recognizer
  5047. */
  5048. function PressRecognizer() {
  5049. Recognizer.apply(this, arguments);
  5050. this._timer = null;
  5051. this._input = null;
  5052. }
  5053. inherit(PressRecognizer, Recognizer, {
  5054. /**
  5055. * @namespace
  5056. * @memberof PressRecognizer
  5057. */
  5058. defaults: {
  5059. event: 'press',
  5060. pointers: 1,
  5061. time: 500, // minimal time of the pointer to be pressed
  5062. threshold: 5 // a minimal movement is ok, but keep it low
  5063. },
  5064. getTouchAction: function() {
  5065. return [TOUCH_ACTION_AUTO];
  5066. },
  5067. process: function(input) {
  5068. var options = this.options;
  5069. var validPointers = input.pointers.length === options.pointers;
  5070. var validMovement = input.distance < options.threshold;
  5071. var validTime = input.deltaTime > options.time;
  5072. this._input = input;
  5073. // we only allow little movement
  5074. // and we've reached an end event, so a tap is possible
  5075. if (!validMovement || !validPointers || (input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime)) {
  5076. this.reset();
  5077. } else if (input.eventType & INPUT_START) {
  5078. this.reset();
  5079. this._timer = setTimeoutContext(function() {
  5080. this.state = STATE_RECOGNIZED;
  5081. this.tryEmit();
  5082. }, options.time, this);
  5083. } else if (input.eventType & INPUT_END) {
  5084. return STATE_RECOGNIZED;
  5085. }
  5086. return STATE_FAILED;
  5087. },
  5088. reset: function() {
  5089. clearTimeout(this._timer);
  5090. },
  5091. emit: function(input) {
  5092. if (this.state !== STATE_RECOGNIZED) {
  5093. return;
  5094. }
  5095. if (input && (input.eventType & INPUT_END)) {
  5096. this.manager.emit(this.options.event + 'up', input);
  5097. } else {
  5098. this._input.timeStamp = now();
  5099. this.manager.emit(this.options.event, this._input);
  5100. }
  5101. }
  5102. });
  5103. /**
  5104. * Rotate
  5105. * Recognized when two or more pointer are moving in a circular motion.
  5106. * @constructor
  5107. * @extends AttrRecognizer
  5108. */
  5109. function RotateRecognizer() {
  5110. AttrRecognizer.apply(this, arguments);
  5111. }
  5112. inherit(RotateRecognizer, AttrRecognizer, {
  5113. /**
  5114. * @namespace
  5115. * @memberof RotateRecognizer
  5116. */
  5117. defaults: {
  5118. event: 'rotate',
  5119. threshold: 0,
  5120. pointers: 2
  5121. },
  5122. getTouchAction: function() {
  5123. return [TOUCH_ACTION_NONE];
  5124. },
  5125. attrTest: function(input) {
  5126. return this._super.attrTest.call(this, input) &&
  5127. (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
  5128. }
  5129. });
  5130. /**
  5131. * Swipe
  5132. * Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction.
  5133. * @constructor
  5134. * @extends AttrRecognizer
  5135. */
  5136. function SwipeRecognizer() {
  5137. AttrRecognizer.apply(this, arguments);
  5138. }
  5139. inherit(SwipeRecognizer, AttrRecognizer, {
  5140. /**
  5141. * @namespace
  5142. * @memberof SwipeRecognizer
  5143. */
  5144. defaults: {
  5145. event: 'swipe',
  5146. threshold: 10,
  5147. velocity: 0.65,
  5148. direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
  5149. pointers: 1
  5150. },
  5151. getTouchAction: function() {
  5152. return PanRecognizer.prototype.getTouchAction.call(this);
  5153. },
  5154. attrTest: function(input) {
  5155. var direction = this.options.direction;
  5156. var velocity;
  5157. if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
  5158. velocity = input.velocity;
  5159. } else if (direction & DIRECTION_HORIZONTAL) {
  5160. velocity = input.velocityX;
  5161. } else if (direction & DIRECTION_VERTICAL) {
  5162. velocity = input.velocityY;
  5163. }
  5164. return this._super.attrTest.call(this, input) &&
  5165. direction & input.direction &&
  5166. input.distance > this.options.threshold &&
  5167. abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
  5168. },
  5169. emit: function(input) {
  5170. var direction = directionStr(input.direction);
  5171. if (direction) {
  5172. this.manager.emit(this.options.event + direction, input);
  5173. }
  5174. this.manager.emit(this.options.event, input);
  5175. }
  5176. });
  5177. /**
  5178. * A tap is ecognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur
  5179. * between the given interval and position. The delay option can be used to recognize multi-taps without firing
  5180. * a single tap.
  5181. *
  5182. * The eventData from the emitted event contains the property `tapCount`, which contains the amount of
  5183. * multi-taps being recognized.
  5184. * @constructor
  5185. * @extends Recognizer
  5186. */
  5187. function TapRecognizer() {
  5188. Recognizer.apply(this, arguments);
  5189. // previous time and center,
  5190. // used for tap counting
  5191. this.pTime = false;
  5192. this.pCenter = false;
  5193. this._timer = null;
  5194. this._input = null;
  5195. this.count = 0;
  5196. }
  5197. inherit(TapRecognizer, Recognizer, {
  5198. /**
  5199. * @namespace
  5200. * @memberof PinchRecognizer
  5201. */
  5202. defaults: {
  5203. event: 'tap',
  5204. pointers: 1,
  5205. taps: 1,
  5206. interval: 300, // max time between the multi-tap taps
  5207. time: 250, // max time of the pointer to be down (like finger on the screen)
  5208. threshold: 2, // a minimal movement is ok, but keep it low
  5209. posThreshold: 10 // a multi-tap can be a bit off the initial position
  5210. },
  5211. getTouchAction: function() {
  5212. return [TOUCH_ACTION_MANIPULATION];
  5213. },
  5214. process: function(input) {
  5215. var options = this.options;
  5216. var validPointers = input.pointers.length === options.pointers;
  5217. var validMovement = input.distance < options.threshold;
  5218. var validTouchTime = input.deltaTime < options.time;
  5219. this.reset();
  5220. if ((input.eventType & INPUT_START) && (this.count === 0)) {
  5221. return this.failTimeout();
  5222. }
  5223. // we only allow little movement
  5224. // and we've reached an end event, so a tap is possible
  5225. if (validMovement && validTouchTime && validPointers) {
  5226. if (input.eventType != INPUT_END) {
  5227. return this.failTimeout();
  5228. }
  5229. var validInterval = this.pTime ? (input.timeStamp - this.pTime < options.interval) : true;
  5230. var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
  5231. this.pTime = input.timeStamp;
  5232. this.pCenter = input.center;
  5233. if (!validMultiTap || !validInterval) {
  5234. this.count = 1;
  5235. } else {
  5236. this.count += 1;
  5237. }
  5238. this._input = input;
  5239. // if tap count matches we have recognized it,
  5240. // else it has began recognizing...
  5241. var tapCount = this.count % options.taps;
  5242. if (tapCount === 0) {
  5243. // no failing requirements, immediately trigger the tap event
  5244. // or wait as long as the multitap interval to trigger
  5245. if (!this.hasRequireFailures()) {
  5246. return STATE_RECOGNIZED;
  5247. } else {
  5248. this._timer = setTimeoutContext(function() {
  5249. this.state = STATE_RECOGNIZED;
  5250. this.tryEmit();
  5251. }, options.interval, this);
  5252. return STATE_BEGAN;
  5253. }
  5254. }
  5255. }
  5256. return STATE_FAILED;
  5257. },
  5258. failTimeout: function() {
  5259. this._timer = setTimeoutContext(function() {
  5260. this.state = STATE_FAILED;
  5261. }, this.options.interval, this);
  5262. return STATE_FAILED;
  5263. },
  5264. reset: function() {
  5265. clearTimeout(this._timer);
  5266. },
  5267. emit: function() {
  5268. if (this.state == STATE_RECOGNIZED) {
  5269. this._input.tapCount = this.count;
  5270. this.manager.emit(this.options.event, this._input);
  5271. }
  5272. }
  5273. });
  5274. /**
  5275. * Simple way to create an manager with a default set of recognizers.
  5276. * @param {HTMLElement} element
  5277. * @param {Object} [options]
  5278. * @constructor
  5279. */
  5280. function Hammer(element, options) {
  5281. options = options || {};
  5282. options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
  5283. return new Manager(element, options);
  5284. }
  5285. /**
  5286. * @const {string}
  5287. */
  5288. Hammer.VERSION = '2.0.4';
  5289. /**
  5290. * default settings
  5291. * @namespace
  5292. */
  5293. Hammer.defaults = {
  5294. /**
  5295. * set if DOM events are being triggered.
  5296. * But this is slower and unused by simple implementations, so disabled by default.
  5297. * @type {Boolean}
  5298. * @default false
  5299. */
  5300. domEvents: false,
  5301. /**
  5302. * The value for the touchAction property/fallback.
  5303. * When set to `compute` it will magically set the correct value based on the added recognizers.
  5304. * @type {String}
  5305. * @default compute
  5306. */
  5307. touchAction: TOUCH_ACTION_COMPUTE,
  5308. /**
  5309. * @type {Boolean}
  5310. * @default true
  5311. */
  5312. enable: true,
  5313. /**
  5314. * EXPERIMENTAL FEATURE -- can be removed/changed
  5315. * Change the parent input target element.
  5316. * If Null, then it is being set the to main element.
  5317. * @type {Null|EventTarget}
  5318. * @default null
  5319. */
  5320. inputTarget: null,
  5321. /**
  5322. * force an input class
  5323. * @type {Null|Function}
  5324. * @default null
  5325. */
  5326. inputClass: null,
  5327. /**
  5328. * Default recognizer setup when calling `Hammer()`
  5329. * When creating a new Manager these will be skipped.
  5330. * @type {Array}
  5331. */
  5332. preset: [
  5333. // RecognizerClass, options, [recognizeWith, ...], [requireFailure, ...]
  5334. [RotateRecognizer, {enable: false}],
  5335. [PinchRecognizer, {enable: false}, ['rotate']],
  5336. [SwipeRecognizer, {direction: DIRECTION_HORIZONTAL}],
  5337. [PanRecognizer, {direction: DIRECTION_HORIZONTAL}, ['swipe']],
  5338. [TapRecognizer],
  5339. [TapRecognizer, {event: 'doubletap', taps: 2}, ['tap']],
  5340. [PressRecognizer]
  5341. ],
  5342. /**
  5343. * Some CSS properties can be used to improve the working of Hammer.
  5344. * Add them to this method and they will be set when creating a new Manager.
  5345. * @namespace
  5346. */
  5347. cssProps: {
  5348. /**
  5349. * Disables text selection to improve the dragging gesture. Mainly for desktop browsers.
  5350. * @type {String}
  5351. * @default 'none'
  5352. */
  5353. userSelect: 'none',
  5354. /**
  5355. * Disable the Windows Phone grippers when pressing an element.
  5356. * @type {String}
  5357. * @default 'none'
  5358. */
  5359. touchSelect: 'none',
  5360. /**
  5361. * Disables the default callout shown when you touch and hold a touch target.
  5362. * On iOS, when you touch and hold a touch target such as a link, Safari displays
  5363. * a callout containing information about the link. This property allows you to disable that callout.
  5364. * @type {String}
  5365. * @default 'none'
  5366. */
  5367. touchCallout: 'none',
  5368. /**
  5369. * Specifies whether zooming is enabled. Used by IE10>
  5370. * @type {String}
  5371. * @default 'none'
  5372. */
  5373. contentZooming: 'none',
  5374. /**
  5375. * Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers.
  5376. * @type {String}
  5377. * @default 'none'
  5378. */
  5379. userDrag: 'none',
  5380. /**
  5381. * Overrides the highlight color shown when the user taps a link or a JavaScript
  5382. * clickable element in iOS. This property obeys the alpha value, if specified.
  5383. * @type {String}
  5384. * @default 'rgba(0,0,0,0)'
  5385. */
  5386. tapHighlightColor: 'rgba(0,0,0,0)'
  5387. }
  5388. };
  5389. var STOP = 1;
  5390. var FORCED_STOP = 2;
  5391. /**
  5392. * Manager
  5393. * @param {HTMLElement} element
  5394. * @param {Object} [options]
  5395. * @constructor
  5396. */
  5397. function Manager(element, options) {
  5398. options = options || {};
  5399. this.options = merge(options, Hammer.defaults);
  5400. this.options.inputTarget = this.options.inputTarget || element;
  5401. this.handlers = {};
  5402. this.session = {};
  5403. this.recognizers = [];
  5404. this.element = element;
  5405. this.input = createInputInstance(this);
  5406. this.touchAction = new TouchAction(this, this.options.touchAction);
  5407. toggleCssProps(this, true);
  5408. each(options.recognizers, function(item) {
  5409. var recognizer = this.add(new (item[0])(item[1]));
  5410. item[2] && recognizer.recognizeWith(item[2]);
  5411. item[3] && recognizer.requireFailure(item[3]);
  5412. }, this);
  5413. }
  5414. Manager.prototype = {
  5415. /**
  5416. * set options
  5417. * @param {Object} options
  5418. * @returns {Manager}
  5419. */
  5420. set: function(options) {
  5421. extend(this.options, options);
  5422. // Options that need a little more setup
  5423. if (options.touchAction) {
  5424. this.touchAction.update();
  5425. }
  5426. if (options.inputTarget) {
  5427. // Clean up existing event listeners and reinitialize
  5428. this.input.destroy();
  5429. this.input.target = options.inputTarget;
  5430. this.input.init();
  5431. }
  5432. return this;
  5433. },
  5434. /**
  5435. * stop recognizing for this session.
  5436. * This session will be discarded, when a new [input]start event is fired.
  5437. * When forced, the recognizer cycle is stopped immediately.
  5438. * @param {Boolean} [force]
  5439. */
  5440. stop: function(force) {
  5441. this.session.stopped = force ? FORCED_STOP : STOP;
  5442. },
  5443. /**
  5444. * run the recognizers!
  5445. * called by the inputHandler function on every movement of the pointers (touches)
  5446. * it walks through all the recognizers and tries to detect the gesture that is being made
  5447. * @param {Object} inputData
  5448. */
  5449. recognize: function(inputData) {
  5450. var session = this.session;
  5451. if (session.stopped) {
  5452. return;
  5453. }
  5454. // run the touch-action polyfill
  5455. this.touchAction.preventDefaults(inputData);
  5456. var recognizer;
  5457. var recognizers = this.recognizers;
  5458. // this holds the recognizer that is being recognized.
  5459. // so the recognizer's state needs to be BEGAN, CHANGED, ENDED or RECOGNIZED
  5460. // if no recognizer is detecting a thing, it is set to `null`
  5461. var curRecognizer = session.curRecognizer;
  5462. // reset when the last recognizer is recognized
  5463. // or when we're in a new session
  5464. if (!curRecognizer || (curRecognizer && curRecognizer.state & STATE_RECOGNIZED)) {
  5465. curRecognizer = session.curRecognizer = null;
  5466. }
  5467. var i = 0;
  5468. while (i < recognizers.length) {
  5469. recognizer = recognizers[i];
  5470. // find out if we are allowed try to recognize the input for this one.
  5471. // 1. allow if the session is NOT forced stopped (see the .stop() method)
  5472. // 2. allow if we still haven't recognized a gesture in this session, or the this recognizer is the one
  5473. // that is being recognized.
  5474. // 3. allow if the recognizer is allowed to run simultaneous with the current recognized recognizer.
  5475. // this can be setup with the `recognizeWith()` method on the recognizer.
  5476. if (session.stopped !== FORCED_STOP && ( // 1
  5477. !curRecognizer || recognizer == curRecognizer || // 2
  5478. recognizer.canRecognizeWith(curRecognizer))) { // 3
  5479. recognizer.recognize(inputData);
  5480. } else {
  5481. recognizer.reset();
  5482. }
  5483. // if the recognizer has been recognizing the input as a valid gesture, we want to store this one as the
  5484. // current active recognizer. but only if we don't already have an active recognizer
  5485. if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
  5486. curRecognizer = session.curRecognizer = recognizer;
  5487. }
  5488. i++;
  5489. }
  5490. },
  5491. /**
  5492. * get a recognizer by its event name.
  5493. * @param {Recognizer|String} recognizer
  5494. * @returns {Recognizer|Null}
  5495. */
  5496. get: function(recognizer) {
  5497. if (recognizer instanceof Recognizer) {
  5498. return recognizer;
  5499. }
  5500. var recognizers = this.recognizers;
  5501. for (var i = 0; i < recognizers.length; i++) {
  5502. if (recognizers[i].options.event == recognizer) {
  5503. return recognizers[i];
  5504. }
  5505. }
  5506. return null;
  5507. },
  5508. /**
  5509. * add a recognizer to the manager
  5510. * existing recognizers with the same event name will be removed
  5511. * @param {Recognizer} recognizer
  5512. * @returns {Recognizer|Manager}
  5513. */
  5514. add: function(recognizer) {
  5515. if (invokeArrayArg(recognizer, 'add', this)) {
  5516. return this;
  5517. }
  5518. // remove existing
  5519. var existing = this.get(recognizer.options.event);
  5520. if (existing) {
  5521. this.remove(existing);
  5522. }
  5523. this.recognizers.push(recognizer);
  5524. recognizer.manager = this;
  5525. this.touchAction.update();
  5526. return recognizer;
  5527. },
  5528. /**
  5529. * remove a recognizer by name or instance
  5530. * @param {Recognizer|String} recognizer
  5531. * @returns {Manager}
  5532. */
  5533. remove: function(recognizer) {
  5534. if (invokeArrayArg(recognizer, 'remove', this)) {
  5535. return this;
  5536. }
  5537. var recognizers = this.recognizers;
  5538. recognizer = this.get(recognizer);
  5539. recognizers.splice(inArray(recognizers, recognizer), 1);
  5540. this.touchAction.update();
  5541. return this;
  5542. },
  5543. /**
  5544. * bind event
  5545. * @param {String} events
  5546. * @param {Function} handler
  5547. * @returns {EventEmitter} this
  5548. */
  5549. on: function(events, handler) {
  5550. var handlers = this.handlers;
  5551. each(splitStr(events), function(event) {
  5552. handlers[event] = handlers[event] || [];
  5553. handlers[event].push(handler);
  5554. });
  5555. return this;
  5556. },
  5557. /**
  5558. * unbind event, leave emit blank to remove all handlers
  5559. * @param {String} events
  5560. * @param {Function} [handler]
  5561. * @returns {EventEmitter} this
  5562. */
  5563. off: function(events, handler) {
  5564. var handlers = this.handlers;
  5565. each(splitStr(events), function(event) {
  5566. if (!handler) {
  5567. delete handlers[event];
  5568. } else {
  5569. handlers[event].splice(inArray(handlers[event], handler), 1);
  5570. }
  5571. });
  5572. return this;
  5573. },
  5574. /**
  5575. * emit event to the listeners
  5576. * @param {String} event
  5577. * @param {Object} data
  5578. */
  5579. emit: function(event, data) {
  5580. // we also want to trigger dom events
  5581. if (this.options.domEvents) {
  5582. triggerDomEvent(event, data);
  5583. }
  5584. // no handlers, so skip it all
  5585. var handlers = this.handlers[event] && this.handlers[event].slice();
  5586. if (!handlers || !handlers.length) {
  5587. return;
  5588. }
  5589. data.type = event;
  5590. data.preventDefault = function() {
  5591. data.srcEvent.preventDefault();
  5592. };
  5593. var i = 0;
  5594. while (i < handlers.length) {
  5595. handlers[i](data);
  5596. i++;
  5597. }
  5598. },
  5599. /**
  5600. * destroy the manager and unbinds all events
  5601. * it doesn't unbind dom events, that is the user own responsibility
  5602. */
  5603. destroy: function() {
  5604. this.element && toggleCssProps(this, false);
  5605. this.handlers = {};
  5606. this.session = {};
  5607. this.input.destroy();
  5608. this.element = null;
  5609. }
  5610. };
  5611. /**
  5612. * add/remove the css properties as defined in manager.options.cssProps
  5613. * @param {Manager} manager
  5614. * @param {Boolean} add
  5615. */
  5616. function toggleCssProps(manager, add) {
  5617. var element = manager.element;
  5618. each(manager.options.cssProps, function(value, name) {
  5619. element.style[prefixed(element.style, name)] = add ? value : '';
  5620. });
  5621. }
  5622. /**
  5623. * trigger dom event
  5624. * @param {String} event
  5625. * @param {Object} data
  5626. */
  5627. function triggerDomEvent(event, data) {
  5628. var gestureEvent = document.createEvent('Event');
  5629. gestureEvent.initEvent(event, true, true);
  5630. gestureEvent.gesture = data;
  5631. data.target.dispatchEvent(gestureEvent);
  5632. }
  5633. extend(Hammer, {
  5634. INPUT_START: INPUT_START,
  5635. INPUT_MOVE: INPUT_MOVE,
  5636. INPUT_END: INPUT_END,
  5637. INPUT_CANCEL: INPUT_CANCEL,
  5638. STATE_POSSIBLE: STATE_POSSIBLE,
  5639. STATE_BEGAN: STATE_BEGAN,
  5640. STATE_CHANGED: STATE_CHANGED,
  5641. STATE_ENDED: STATE_ENDED,
  5642. STATE_RECOGNIZED: STATE_RECOGNIZED,
  5643. STATE_CANCELLED: STATE_CANCELLED,
  5644. STATE_FAILED: STATE_FAILED,
  5645. DIRECTION_NONE: DIRECTION_NONE,
  5646. DIRECTION_LEFT: DIRECTION_LEFT,
  5647. DIRECTION_RIGHT: DIRECTION_RIGHT,
  5648. DIRECTION_UP: DIRECTION_UP,
  5649. DIRECTION_DOWN: DIRECTION_DOWN,
  5650. DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
  5651. DIRECTION_VERTICAL: DIRECTION_VERTICAL,
  5652. DIRECTION_ALL: DIRECTION_ALL,
  5653. Manager: Manager,
  5654. Input: Input,
  5655. TouchAction: TouchAction,
  5656. TouchInput: TouchInput,
  5657. MouseInput: MouseInput,
  5658. PointerEventInput: PointerEventInput,
  5659. TouchMouseInput: TouchMouseInput,
  5660. SingleTouchInput: SingleTouchInput,
  5661. Recognizer: Recognizer,
  5662. AttrRecognizer: AttrRecognizer,
  5663. Tap: TapRecognizer,
  5664. Pan: PanRecognizer,
  5665. Swipe: SwipeRecognizer,
  5666. Pinch: PinchRecognizer,
  5667. Rotate: RotateRecognizer,
  5668. Press: PressRecognizer,
  5669. on: addEventListeners,
  5670. off: removeEventListeners,
  5671. each: each,
  5672. merge: merge,
  5673. extend: extend,
  5674. inherit: inherit,
  5675. bindFn: bindFn,
  5676. prefixed: prefixed
  5677. });
  5678. // jquery.hammer.js
  5679. // This jQuery plugin is just a small wrapper around the Hammer() class.
  5680. // It also extends the Manager.emit method by triggering jQuery events.
  5681. // $(element).hammer(options).bind("pan", myPanHandler);
  5682. // The Hammer instance is stored at $element.data("hammer").
  5683. // https://github.com/hammerjs/jquery.hammer.js
  5684. (function($, Hammer) {
  5685. function hammerify(el, options) {
  5686. var $el = $(el);
  5687. if (!$el.data('hammer')) {
  5688. $el.data('hammer', new Hammer($el[0], options));
  5689. }
  5690. }
  5691. $.fn.hammer = function(options) {
  5692. return this.each(function() {
  5693. hammerify(this, options);
  5694. });
  5695. };
  5696. // extend the emit method to also trigger jQuery events
  5697. Hammer.Manager.prototype.emit = (function(originalEmit) {
  5698. return function(type, data) {
  5699. originalEmit.call(this, type, data);
  5700. $(this.element).trigger({
  5701. type: type,
  5702. gesture: data
  5703. });
  5704. };
  5705. })(Hammer.Manager.prototype.emit);
  5706. })($, Hammer);
  5707. $.AMUI.Hammer = Hammer;
  5708. module.exports = Hammer;
  5709. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5710. },{"./core":2}]},{},[1]);