amazeui.js 430 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918
  1. /*! Amaze UI v2.4.0 | by Amaze UI Team | (c) 2015 AllMobilize, Inc. | Licensed under MIT | 2015-06-01T09:54:08+0800 */
  2. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.AMUI = f()}})(function(){var define,module,exports;return (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(_dereq_,module,exports){
  3. (function (global){
  4. 'use strict';
  5. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  6. _dereq_(2);
  7. _dereq_(30);
  8. _dereq_(3);
  9. _dereq_(4);
  10. _dereq_(5);
  11. _dereq_(6);
  12. _dereq_(7);
  13. _dereq_(8);
  14. _dereq_(9);
  15. _dereq_(10);
  16. _dereq_(11);
  17. _dereq_(12);
  18. _dereq_(13);
  19. _dereq_(14);
  20. _dereq_(15);
  21. _dereq_(16);
  22. _dereq_(17);
  23. _dereq_(18);
  24. _dereq_(19);
  25. _dereq_(20);
  26. _dereq_(21);
  27. _dereq_(22);
  28. _dereq_(23);
  29. _dereq_(24);
  30. _dereq_(25);
  31. _dereq_(26);
  32. _dereq_(27);
  33. _dereq_(28);
  34. _dereq_(29);
  35. _dereq_(31);
  36. _dereq_(32);
  37. _dereq_(33);
  38. _dereq_(34);
  39. _dereq_(35);
  40. _dereq_(36);
  41. _dereq_(37);
  42. _dereq_(38);
  43. _dereq_(39);
  44. _dereq_(40);
  45. _dereq_(41);
  46. _dereq_(42);
  47. _dereq_(43);
  48. _dereq_(44);
  49. _dereq_(45);
  50. _dereq_(46);
  51. _dereq_(47);
  52. _dereq_(48);
  53. _dereq_(49);
  54. _dereq_(50);
  55. _dereq_(51);
  56. _dereq_(52);
  57. module.exports = $.AMUI;
  58. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  59. },{"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"2":2,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"3":3,"30":30,"31":31,"32":32,"33":33,"34":34,"35":35,"36":36,"37":37,"38":38,"39":39,"4":4,"40":40,"41":41,"42":42,"43":43,"44":44,"45":45,"46":46,"47":47,"48":48,"49":49,"5":5,"50":50,"51":51,"52":52,"6":6,"7":7,"8":8,"9":9}],2:[function(_dereq_,module,exports){
  60. (function (global){
  61. 'use strict';
  62. /* jshint -W040 */
  63. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  64. if (typeof $ === 'undefined') {
  65. throw new Error('Amaze UI 2.x requires jQuery :-(\n' +
  66. '\u7231\u4e0a\u4e00\u5339\u91ce\u9a6c\uff0c\u53ef\u4f60' +
  67. '\u7684\u5bb6\u91cc\u6ca1\u6709\u8349\u539f\u2026');
  68. }
  69. var UI = $.AMUI || {};
  70. var $win = $(window);
  71. var doc = window.document;
  72. var $html = $('html');
  73. UI.VERSION = '2.4.0';
  74. UI.support = {};
  75. UI.support.transition = (function() {
  76. var transitionEnd = (function() {
  77. // https://developer.mozilla.org/en-US/docs/Web/Events/transitionend#Browser_compatibility
  78. var element = doc.body || doc.documentElement;
  79. var transEndEventNames = {
  80. WebkitTransition: 'webkitTransitionEnd',
  81. MozTransition: 'transitionend',
  82. OTransition: 'oTransitionEnd otransitionend',
  83. transition: 'transitionend'
  84. };
  85. for (var name in transEndEventNames) {
  86. if (element.style[name] !== undefined) {
  87. return transEndEventNames[name];
  88. }
  89. }
  90. })();
  91. return transitionEnd && {end: transitionEnd};
  92. })();
  93. UI.support.animation = (function() {
  94. var animationEnd = (function() {
  95. var element = doc.body || doc.documentElement;
  96. var animEndEventNames = {
  97. WebkitAnimation: 'webkitAnimationEnd',
  98. MozAnimation: 'animationend',
  99. OAnimation: 'oAnimationEnd oanimationend',
  100. animation: 'animationend'
  101. };
  102. for (var name in animEndEventNames) {
  103. if (element.style[name] !== undefined) {
  104. return animEndEventNames[name];
  105. }
  106. }
  107. })();
  108. return animationEnd && {end: animationEnd};
  109. })();
  110. /* jshint -W069 */
  111. UI.support.touch = (
  112. ('ontouchstart' in window &&
  113. navigator.userAgent.toLowerCase().match(/mobile|tablet/)) ||
  114. (window.DocumentTouch && document instanceof window.DocumentTouch) ||
  115. (window.navigator['msPointerEnabled'] &&
  116. window.navigator['msMaxTouchPoints'] > 0) || //IE 10
  117. (window.navigator['pointerEnabled'] &&
  118. window.navigator['maxTouchPoints'] > 0) || //IE >=11
  119. false);
  120. // https://developer.mozilla.org/zh-CN/docs/DOM/MutationObserver
  121. UI.support.mutationobserver = (window.MutationObserver ||
  122. window.WebKitMutationObserver || null);
  123. // https://github.com/Modernizr/Modernizr/blob/924c7611c170ef2dc502582e5079507aff61e388/feature-detects/forms/validation.js#L20
  124. UI.support.formValidation = (typeof document.createElement('form').
  125. checkValidity === 'function');
  126. UI.utils = {};
  127. /**
  128. * Debounce function
  129. * @param {function} func Function to be debounced
  130. * @param {number} wait Function execution threshold in milliseconds
  131. * @param {bool} immediate Whether the function should be called at
  132. * the beginning of the delay instead of the
  133. * end. Default is false.
  134. * @desc Executes a function when it stops being invoked for n seconds
  135. * @via _.debounce() http://underscorejs.org
  136. */
  137. UI.utils.debounce = function(func, wait, immediate) {
  138. var timeout;
  139. return function() {
  140. var context = this;
  141. var args = arguments;
  142. var later = function() {
  143. timeout = null;
  144. if (!immediate) {
  145. func.apply(context, args);
  146. }
  147. };
  148. var callNow = immediate && !timeout;
  149. clearTimeout(timeout);
  150. timeout = setTimeout(later, wait);
  151. if (callNow) {
  152. func.apply(context, args);
  153. }
  154. };
  155. };
  156. UI.utils.isInView = function(element, options) {
  157. var $element = $(element);
  158. var visible = !!($element.width() || $element.height()) &&
  159. $element.css('display') !== 'none';
  160. if (!visible) {
  161. return false;
  162. }
  163. var windowLeft = $win.scrollLeft();
  164. var windowTop = $win.scrollTop();
  165. var offset = $element.offset();
  166. var left = offset.left;
  167. var top = offset.top;
  168. options = $.extend({topOffset: 0, leftOffset: 0}, options);
  169. return (top + $element.height() >= windowTop &&
  170. top - options.topOffset <= windowTop + $win.height() &&
  171. left + $element.width() >= windowLeft &&
  172. left - options.leftOffset <= windowLeft + $win.width());
  173. };
  174. /* jshint -W054 */
  175. UI.utils.parseOptions = UI.utils.options = function(string) {
  176. if ($.isPlainObject(string)) {
  177. return string;
  178. }
  179. var start = (string ? string.indexOf('{') : -1);
  180. var options = {};
  181. if (start != -1) {
  182. try {
  183. options = (new Function('',
  184. 'var json = ' + string.substr(start) +
  185. '; return JSON.parse(JSON.stringify(json));'))();
  186. } catch (e) {
  187. }
  188. }
  189. return options;
  190. };
  191. /* jshint +W054 */
  192. UI.utils.generateGUID = function(namespace) {
  193. var uid = namespace + '-' || 'am-';
  194. do {
  195. uid += Math.random().toString(36).substring(2, 7);
  196. } while (document.getElementById(uid));
  197. return uid;
  198. };
  199. // http://blog.alexmaccaw.com/css-transitions
  200. $.fn.emulateTransitionEnd = function(duration) {
  201. var called = false;
  202. var $el = this;
  203. $(this).one(UI.support.transition.end, function() {
  204. called = true;
  205. });
  206. var callback = function() {
  207. if (!called) {
  208. $($el).trigger(UI.support.transition.end);
  209. }
  210. $el.transitionEndTimmer = undefined;
  211. };
  212. this.transitionEndTimmer = setTimeout(callback, duration);
  213. return this;
  214. };
  215. $.fn.redraw = function() {
  216. $(this).each(function() {
  217. /* jshint unused:false */
  218. var redraw = this.offsetHeight;
  219. });
  220. return this;
  221. };
  222. /* jshint unused:true */
  223. $.fn.transitionEnd = function(callback) {
  224. var endEvent = UI.support.transition.end;
  225. var dom = this;
  226. function fireCallBack(e) {
  227. callback.call(this, e);
  228. endEvent && dom.off(endEvent, fireCallBack);
  229. }
  230. if (callback && endEvent) {
  231. dom.on(endEvent, fireCallBack);
  232. }
  233. return this;
  234. };
  235. $.fn.removeClassRegEx = function() {
  236. return this.each(function(regex) {
  237. var classes = $(this).attr('class');
  238. if (!classes || !regex) {
  239. return false;
  240. }
  241. var classArray = [];
  242. classes = classes.split(' ');
  243. for (var i = 0, len = classes.length; i < len; i++) {
  244. if (!classes[i].match(regex)) {
  245. classArray.push(classes[i]);
  246. }
  247. }
  248. $(this).attr('class', classArray.join(' '));
  249. });
  250. };
  251. //
  252. $.fn.alterClass = function(removals, additions) {
  253. var self = this;
  254. if (removals.indexOf('*') === -1) {
  255. // Use native jQuery methods if there is no wildcard matching
  256. self.removeClass(removals);
  257. return !additions ? self : self.addClass(additions);
  258. }
  259. var classPattern = new RegExp('\\s' +
  260. removals.
  261. replace(/\*/g, '[A-Za-z0-9-_]+').
  262. split(' ').
  263. join('\\s|\\s') +
  264. '\\s', 'g');
  265. self.each(function(i, it) {
  266. var cn = ' ' + it.className + ' ';
  267. while (classPattern.test(cn)) {
  268. cn = cn.replace(classPattern, ' ');
  269. }
  270. it.className = $.trim(cn);
  271. });
  272. return !additions ? self : self.addClass(additions);
  273. };
  274. // handle multiple browsers for requestAnimationFrame()
  275. // http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
  276. // https://github.com/gnarf/jquery-requestAnimationFrame
  277. UI.utils.rAF = (function() {
  278. return window.requestAnimationFrame ||
  279. window.webkitRequestAnimationFrame ||
  280. window.mozRequestAnimationFrame ||
  281. window.oRequestAnimationFrame ||
  282. // if all else fails, use setTimeout
  283. function(callback) {
  284. return window.setTimeout(callback, 1000 / 60); // shoot for 60 fps
  285. };
  286. })();
  287. // handle multiple browsers for cancelAnimationFrame()
  288. UI.utils.cancelAF = (function() {
  289. return window.cancelAnimationFrame ||
  290. window.webkitCancelAnimationFrame ||
  291. window.mozCancelAnimationFrame ||
  292. window.oCancelAnimationFrame ||
  293. function(id) {
  294. window.clearTimeout(id);
  295. };
  296. })();
  297. // via http://davidwalsh.name/detect-scrollbar-width
  298. UI.utils.measureScrollbar = function() {
  299. if (document.body.clientWidth >= window.innerWidth) {
  300. return 0;
  301. }
  302. // if ($html.width() >= window.innerWidth) return;
  303. // var scrollbarWidth = window.innerWidth - $html.width();
  304. var $measure = $('<div ' +
  305. 'style="width: 100px;height: 100px;overflow: scroll;' +
  306. 'position: absolute;top: -9999px;"></div>');
  307. $(document.body).append($measure);
  308. var scrollbarWidth = $measure[0].offsetWidth - $measure[0].clientWidth;
  309. $measure.remove();
  310. return scrollbarWidth;
  311. };
  312. UI.utils.imageLoader = function($image, callback) {
  313. function loaded() {
  314. callback($image[0]);
  315. }
  316. function bindLoad() {
  317. this.one('load', loaded);
  318. if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
  319. var src = this.attr('src');
  320. var param = src.match(/\?/) ? '&' : '?';
  321. param += 'random=' + (new Date()).getTime();
  322. this.attr('src', src + param);
  323. }
  324. }
  325. if (!$image.attr('src')) {
  326. loaded();
  327. return;
  328. }
  329. if ($image[0].complete || $image[0].readyState === 4) {
  330. loaded();
  331. } else {
  332. bindLoad.call($image);
  333. }
  334. };
  335. /**
  336. * https://github.com/cho45/micro-template.js
  337. * (c) cho45 http://cho45.github.com/mit-license
  338. */
  339. /* jshint -W109 */
  340. UI.template = function(id, data) {
  341. var me = UI.template;
  342. if (!me.cache[id]) {
  343. me.cache[id] = (function() {
  344. var name = id;
  345. var string = /^[\w\-]+$/.test(id) ?
  346. me.get(id) : (name = 'template(string)', id); // no warnings
  347. var line = 1;
  348. var body = ('try { ' + (me.variable ?
  349. 'var ' + me.variable + ' = this.stash;' : 'with (this.stash) { ') +
  350. "this.ret += '" +
  351. string.
  352. replace(/<%/g, '\x11').replace(/%>/g, '\x13'). // if you want other tag, just edit this line
  353. replace(/'(?![^\x11\x13]+?\x13)/g, '\\x27').
  354. replace(/^\s*|\s*$/g, '').
  355. replace(/\n/g, function() {
  356. return "';\nthis.line = " + (++line) + "; this.ret += '\\n";
  357. }).
  358. replace(/\x11-(.+?)\x13/g, "' + ($1) + '").
  359. replace(/\x11=(.+?)\x13/g, "' + this.escapeHTML($1) + '").
  360. replace(/\x11(.+?)\x13/g, "'; $1; this.ret += '") +
  361. "'; " + (me.variable ? "" : "}") + "return this.ret;" +
  362. "} catch (e) { throw 'TemplateError: ' + e + ' (on " + name +
  363. "' + ' line ' + this.line + ')'; } " +
  364. "//@ sourceURL=" + name + "\n" // source map
  365. ).replace(/this\.ret \+= '';/g, '');
  366. /* jshint -W054 */
  367. var func = new Function(body);
  368. var map = {
  369. '&': '&amp;',
  370. '<': '&lt;',
  371. '>': '&gt;',
  372. '\x22': '&#x22;',
  373. '\x27': '&#x27;'
  374. };
  375. var escapeHTML = function(string) {
  376. return ('' + string).replace(/[&<>\'\"]/g, function(_) {
  377. return map[_];
  378. });
  379. };
  380. return function(stash) {
  381. return func.call(me.context = {
  382. escapeHTML: escapeHTML,
  383. line: 1,
  384. ret: '',
  385. stash: stash
  386. });
  387. };
  388. })();
  389. }
  390. return data ? me.cache[id](data) : me.cache[id];
  391. };
  392. /* jshint +W109 */
  393. /* jshint +W054 */
  394. UI.template.cache = {};
  395. UI.template.get = function(id) {
  396. if (id) {
  397. var element = document.getElementById(id);
  398. return element && element.innerHTML || '';
  399. }
  400. };
  401. // Dom mutation watchers
  402. UI.DOMWatchers = [];
  403. UI.DOMReady = false;
  404. UI.ready = function(callback) {
  405. UI.DOMWatchers.push(callback);
  406. if (UI.DOMReady) {
  407. // console.log('Ready call');
  408. callback(document);
  409. }
  410. };
  411. UI.DOMObserve = function(elements, options, callback) {
  412. var Observer = UI.support.mutationobserver;
  413. if (!Observer) {
  414. return;
  415. }
  416. options = $.isPlainObject(options) ?
  417. options : {childList: true, subtree: true};
  418. callback = typeof callback === 'function' && callback || function() {
  419. };
  420. $(elements).each(function() {
  421. var element = this;
  422. var $element = $(element);
  423. if ($element.data('am.observer')) {
  424. return;
  425. }
  426. try {
  427. var observer = new Observer(UI.utils.debounce(
  428. function(mutations, instance) {
  429. callback.call(element, mutations, instance);
  430. // trigger this event manually if MutationObserver not supported
  431. $element.trigger('changed.dom.amui');
  432. }, 50));
  433. observer.observe(element, options);
  434. $element.data('am.observer', observer);
  435. } catch (e) {
  436. }
  437. });
  438. };
  439. $.fn.DOMObserve = function(options, callback) {
  440. return this.each(function() {
  441. UI.DOMObserve(this, options, callback);
  442. });
  443. };
  444. if (UI.support.touch) {
  445. $html.addClass('am-touch');
  446. }
  447. $(document).on('changed.dom.amui', function(e) {
  448. var element = e.target;
  449. // TODO: just call changed element's watcher
  450. // every watcher callback should have a key
  451. // use like this: <div data-am-observe='key1, key2'>
  452. // get keys via $(element).data('amObserve')
  453. // call functions store with these keys
  454. $.each(UI.DOMWatchers, function(i, watcher) {
  455. watcher(element);
  456. });
  457. });
  458. $(function() {
  459. var $body = $('body');
  460. UI.DOMReady = true;
  461. // Run default init
  462. $.each(UI.DOMWatchers, function(i, watcher) {
  463. watcher(document);
  464. });
  465. // watches DOM
  466. UI.DOMObserve('[data-am-observe]');
  467. $html.removeClass('no-js').addClass('js');
  468. UI.support.animation && $html.addClass('cssanimations');
  469. // iOS standalone mode
  470. if (window.navigator.standalone) {
  471. $html.addClass('am-standalone');
  472. }
  473. $('.am-topbar-fixed-top').length &&
  474. $body.addClass('am-with-topbar-fixed-top');
  475. $('.am-topbar-fixed-bottom').length &&
  476. $body.addClass('am-with-topbar-fixed-bottom');
  477. // Remove responsive classes in .am-layout
  478. var $layout = $('.am-layout');
  479. $layout.find('[class*="md-block-grid"]').alterClass('md-block-grid-*');
  480. $layout.find('[class*="lg-block-grid"]').alterClass('lg-block-grid');
  481. // widgets not in .am-layout
  482. $('[data-am-widget]').each(function() {
  483. var $widget = $(this);
  484. // console.log($widget.parents('.am-layout').length)
  485. if ($widget.parents('.am-layout').length === 0) {
  486. $widget.addClass('am-no-layout');
  487. }
  488. });
  489. });
  490. $.AMUI = UI;
  491. module.exports = UI;
  492. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  493. },{}],3:[function(_dereq_,module,exports){
  494. (function (global){
  495. 'use strict';
  496. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  497. _dereq_(2);
  498. /* jshint -W101, -W106 */
  499. /* Add to Homescreen v3.0.8 ~ (c) 2014 Matteo Spinelli ~ @license: http://cubiq.org/license */
  500. // Check if document is loaded, needed by autostart
  501. var _DOMReady = false;
  502. if (document.readyState === 'complete') {
  503. _DOMReady = true;
  504. } else {
  505. window.addEventListener('load', loaded, false);
  506. }
  507. function loaded() {
  508. window.removeEventListener('load', loaded, false);
  509. _DOMReady = true;
  510. }
  511. // regex used to detect if app has been added to the homescreen
  512. var _reSmartURL = /\/ath(\/)?$/;
  513. var _reQueryString = /([\?&]ath=[^&]*$|&ath=[^&]*(&))/;
  514. // singleton
  515. var _instance;
  516. function ath(options) {
  517. _instance = _instance || new ath.Class(options);
  518. return _instance;
  519. }
  520. // message in all supported languages
  521. ath.intl = {
  522. en_us: {
  523. message: 'To add this web app to the home screen: tap %icon and then <strong>%action</strong>.',
  524. action: {
  525. ios: 'Add to Home Screen',
  526. android: 'Add to homescreen',
  527. windows: 'pin to start'
  528. }
  529. },
  530. zh_cn: {
  531. message: '如要把应用程式加至主屏幕,请点击%icon, 然后<strong>%action</strong>',
  532. action: {ios: '加至主屏幕', android: '加至主屏幕', windows: '按住启动'}
  533. },
  534. zh_tw: {
  535. message: '如要把應用程式加至主屏幕, 請點擊%icon, 然後<strong>%action</strong>.',
  536. action: {ios: '加至主屏幕', android: '加至主屏幕', windows: '按住啟動'}
  537. }
  538. };
  539. // Add 2 characters language support (Android mostly)
  540. for (var lang in ath.intl) {
  541. ath.intl[lang.substr(0, 2)] = ath.intl[lang];
  542. }
  543. // default options
  544. ath.defaults = {
  545. appID: 'org.cubiq.addtohome', // local storage name (no need to change)
  546. fontSize: 15, // base font size, used to properly resize the popup based on viewport scale factor
  547. debug: false, // override browser checks
  548. modal: false, // prevent further actions until the message is closed
  549. mandatory: false, // you can't proceed if you don't add the app to the homescreen
  550. autostart: true, // show the message automatically
  551. skipFirstVisit: false, // show only to returning visitors (ie: skip the first time you visit)
  552. startDelay: 1, // display the message after that many seconds from page load
  553. lifespan: 15, // life of the message in seconds
  554. displayPace: 1440, // minutes before the message is shown again (0: display every time, default 24 hours)
  555. maxDisplayCount: 0, // absolute maximum number of times the message will be shown to the user (0: no limit)
  556. icon: true, // add touch icon to the message
  557. message: '', // the message can be customized
  558. validLocation: [], // list of pages where the message will be shown (array of regexes)
  559. onInit: null, // executed on instance creation
  560. onShow: null, // executed when the message is shown
  561. onRemove: null, // executed when the message is removed
  562. onAdd: null, // when the application is launched the first time from the homescreen (guesstimate)
  563. onPrivate: null, // executed if user is in private mode
  564. detectHomescreen: false // try to detect if the site has been added to the homescreen (false | true | 'hash' | 'queryString' | 'smartURL')
  565. };
  566. // browser info and capability
  567. var _ua = window.navigator.userAgent;
  568. var _nav = window.navigator;
  569. _extend(ath, {
  570. hasToken: document.location.hash == '#ath' || _reSmartURL.test(document.location.href) || _reQueryString.test(document.location.search),
  571. isRetina: window.devicePixelRatio && window.devicePixelRatio > 1,
  572. isIDevice: (/iphone|ipod|ipad/i).test(_ua),
  573. isMobileChrome: _ua.indexOf('Android') > -1 && (/Chrome\/[.0-9]*/).test(_ua),
  574. isMobileIE: _ua.indexOf('Windows Phone') > -1,
  575. language: _nav.language && _nav.language.toLowerCase().replace('-', '_') || ''
  576. });
  577. // falls back to en_us if language is unsupported
  578. ath.language = ath.language && ath.language in ath.intl ? ath.language : 'en_us';
  579. ath.isMobileSafari = ath.isIDevice && _ua.indexOf('Safari') > -1 && _ua.indexOf('CriOS') < 0;
  580. ath.OS = ath.isIDevice ? 'ios' : ath.isMobileChrome ? 'android' : ath.isMobileIE ? 'windows' : 'unsupported';
  581. ath.OSVersion = _ua.match(/(OS|Android) (\d+[_\.]\d+)/);
  582. ath.OSVersion = ath.OSVersion && ath.OSVersion[2] ? +ath.OSVersion[2].replace('_', '.') : 0;
  583. ath.isStandalone = window.navigator.standalone || ( ath.isMobileChrome && ( screen.height - document.documentElement.clientHeight < 40 ) ); // TODO: check the lame polyfill
  584. ath.isTablet = (ath.isMobileSafari && _ua.indexOf('iPad') > -1) || (ath.isMobileChrome && _ua.indexOf('Mobile') < 0);
  585. ath.isCompatible = (ath.isMobileSafari && ath.OSVersion >= 6) || ath.isMobileChrome; // TODO: add winphone
  586. var _defaultSession = {
  587. lastDisplayTime: 0, // last time we displayed the message
  588. returningVisitor: false, // is this the first time you visit
  589. displayCount: 0, // number of times the message has been shown
  590. optedout: false, // has the user opted out
  591. added: false // has been actually added to the homescreen
  592. };
  593. ath.removeSession = function(appID) {
  594. try {
  595. localStorage.removeItem(appID || ath.defaults.appID);
  596. } catch (e) {
  597. // we are most likely in private mode
  598. }
  599. };
  600. ath.Class = function(options) {
  601. // merge default options with user config
  602. this.options = _extend({}, ath.defaults);
  603. _extend(this.options, options);
  604. // normalize some options
  605. this.options.mandatory = this.options.mandatory && ( 'standalone' in window.navigator || this.options.debug );
  606. this.options.modal = this.options.modal || this.options.mandatory;
  607. if (this.options.mandatory) {
  608. this.options.startDelay = -0.5; // make the popup hasty
  609. }
  610. this.options.detectHomescreen = this.options.detectHomescreen === true ? 'hash' : this.options.detectHomescreen;
  611. // setup the debug environment
  612. if (this.options.debug) {
  613. ath.isCompatible = true;
  614. ath.OS = typeof this.options.debug == 'string' ? this.options.debug : ath.OS == 'unsupported' ? 'android' : ath.OS;
  615. ath.OSVersion = ath.OS == 'ios' ? '8' : '4';
  616. }
  617. // the element the message will be appended to
  618. this.container = document.documentElement;
  619. // load session
  620. this.session = localStorage.getItem(this.options.appID);
  621. this.session = this.session ? JSON.parse(this.session) : undefined;
  622. // user most likely came from a direct link containing our token, we don't need it and we remove it
  623. if (ath.hasToken && ( !ath.isCompatible || !this.session )) {
  624. ath.hasToken = false;
  625. _removeToken();
  626. }
  627. // the device is not supported
  628. if (!ath.isCompatible) {
  629. return;
  630. }
  631. this.session = this.session || _defaultSession;
  632. // check if we can use the local storage
  633. try {
  634. localStorage.setItem(this.options.appID, JSON.stringify(this.session));
  635. ath.hasLocalStorage = true;
  636. } catch (e) {
  637. // we are most likely in private mode
  638. ath.hasLocalStorage = false;
  639. if (this.options.onPrivate) {
  640. this.options.onPrivate.call(this);
  641. }
  642. }
  643. // check if this is a valid location
  644. var isValidLocation = !this.options.validLocation.length;
  645. for (var i = this.options.validLocation.length; i--;) {
  646. if (this.options.validLocation[i].test(document.location.href)) {
  647. isValidLocation = true;
  648. break;
  649. }
  650. }
  651. // check compatibility with old versions of add to homescreen. Opt-out if an old session is found
  652. if (localStorage.getItem('addToHome')) {
  653. this.optOut();
  654. }
  655. // critical errors:
  656. // user opted out, already added to the homescreen, not a valid location
  657. if (this.session.optedout || this.session.added || !isValidLocation) {
  658. return;
  659. }
  660. // check if the app is in stand alone mode
  661. if (ath.isStandalone) {
  662. // execute the onAdd event if we haven't already
  663. if (!this.session.added) {
  664. this.session.added = true;
  665. this.updateSession();
  666. if (this.options.onAdd && ath.hasLocalStorage) { // double check on localstorage to avoid multiple calls to the custom event
  667. this.options.onAdd.call(this);
  668. }
  669. }
  670. return;
  671. }
  672. // (try to) check if the page has been added to the homescreen
  673. if (this.options.detectHomescreen) {
  674. // the URL has the token, we are likely coming from the homescreen
  675. if (ath.hasToken) {
  676. _removeToken(); // we don't actually need the token anymore, we remove it to prevent redistribution
  677. // this is called the first time the user opens the app from the homescreen
  678. if (!this.session.added) {
  679. this.session.added = true;
  680. this.updateSession();
  681. if (this.options.onAdd && ath.hasLocalStorage) { // double check on localstorage to avoid multiple calls to the custom event
  682. this.options.onAdd.call(this);
  683. }
  684. }
  685. return;
  686. }
  687. // URL doesn't have the token, so add it
  688. if (this.options.detectHomescreen == 'hash') {
  689. history.replaceState('', window.document.title, document.location.href + '#ath');
  690. } else if (this.options.detectHomescreen == 'smartURL') {
  691. history.replaceState('', window.document.title, document.location.href.replace(/(\/)?$/, '/ath$1'));
  692. } else {
  693. history.replaceState('', window.document.title, document.location.href + (document.location.search ? '&' : '?' ) + 'ath=');
  694. }
  695. }
  696. // check if this is a returning visitor
  697. if (!this.session.returningVisitor) {
  698. this.session.returningVisitor = true;
  699. this.updateSession();
  700. // we do not show the message if this is your first visit
  701. if (this.options.skipFirstVisit) {
  702. return;
  703. }
  704. }
  705. // we do no show the message in private mode
  706. if (!ath.hasLocalStorage) {
  707. return;
  708. }
  709. // all checks passed, ready to display
  710. this.ready = true;
  711. if (this.options.onInit) {
  712. this.options.onInit.call(this);
  713. }
  714. if (this.options.autostart) {
  715. this.show();
  716. }
  717. };
  718. ath.Class.prototype = {
  719. // event type to method conversion
  720. events: {
  721. load: '_delayedShow',
  722. error: '_delayedShow',
  723. orientationchange: 'resize',
  724. resize: 'resize',
  725. scroll: 'resize',
  726. click: 'remove',
  727. touchmove: '_preventDefault',
  728. transitionend: '_removeElements',
  729. webkitTransitionEnd: '_removeElements',
  730. MSTransitionEnd: '_removeElements'
  731. },
  732. handleEvent: function(e) {
  733. var type = this.events[e.type];
  734. if (type) {
  735. this[type](e);
  736. }
  737. },
  738. show: function(force) {
  739. // in autostart mode wait for the document to be ready
  740. if (this.options.autostart && !_DOMReady) {
  741. setTimeout(this.show.bind(this), 50);
  742. return;
  743. }
  744. // message already on screen
  745. if (this.shown) {
  746. return;
  747. }
  748. var now = Date.now();
  749. var lastDisplayTime = this.session.lastDisplayTime;
  750. if (force !== true) {
  751. // this is needed if autostart is disabled and you programmatically call the show() method
  752. if (!this.ready) {
  753. return;
  754. }
  755. // we obey the display pace (prevent the message to popup too often)
  756. if (now - lastDisplayTime < this.options.displayPace * 60000) {
  757. return;
  758. }
  759. // obey the maximum number of display count
  760. if (this.options.maxDisplayCount && this.session.displayCount >= this.options.maxDisplayCount) {
  761. return;
  762. }
  763. }
  764. this.shown = true;
  765. // increment the display count
  766. this.session.lastDisplayTime = now;
  767. this.session.displayCount++;
  768. this.updateSession();
  769. // try to get the highest resolution application icon
  770. if (!this.applicationIcon) {
  771. if (ath.OS == 'ios') {
  772. this.applicationIcon = document.querySelector('head link[rel^=apple-touch-icon][sizes="152x152"],head link[rel^=apple-touch-icon][sizes="144x144"],head link[rel^=apple-touch-icon][sizes="120x120"],head link[rel^=apple-touch-icon][sizes="114x114"],head link[rel^=apple-touch-icon]');
  773. } else {
  774. this.applicationIcon = document.querySelector('head link[rel^="shortcut icon"][sizes="196x196"],head link[rel^=apple-touch-icon]');
  775. }
  776. }
  777. var message = '';
  778. if (this.options.message in ath.intl) { // you can force the locale
  779. message = ath.intl[this.options.message].message.replace('%action', ath.intl[this.options.message].action[ath.OS]);
  780. } else if (this.options.message !== '') { // or use a custom message
  781. message = this.options.message;
  782. } else { // otherwise we use our message
  783. message = ath.intl[ath.language].message.replace('%action', ath.intl[ath.language].action[ath.OS]);
  784. }
  785. // add the action icon
  786. message = '<p>' + message.replace('%icon', '<span class="ath-action-icon">icon</span>') + '</p>';
  787. // create the message container
  788. this.viewport = document.createElement('div');
  789. this.viewport.className = 'ath-viewport';
  790. if (this.options.modal) {
  791. this.viewport.className += ' ath-modal';
  792. }
  793. if (this.options.mandatory) {
  794. this.viewport.className += ' ath-mandatory';
  795. }
  796. this.viewport.style.position = 'absolute';
  797. // create the actual message element
  798. this.element = document.createElement('div');
  799. this.element.className = 'ath-container ath-' + ath.OS + ' ath-' + ath.OS + (ath.OSVersion + '').substr(0, 1) + ' ath-' + (ath.isTablet ? 'tablet' : 'phone');
  800. this.element.style.cssText = '-webkit-transition-property:-webkit-transform,opacity;-webkit-transition-duration:0;-webkit-transform:translate3d(0,0,0);transition-property:transform,opacity;transition-duration:0;transform:translate3d(0,0,0);-webkit-transition-timing-function:ease-out';
  801. this.element.style.webkitTransform = 'translate3d(0,-' + window.innerHeight + 'px,0)';
  802. this.element.style.webkitTransitionDuration = '0s';
  803. // add the application icon
  804. if (this.options.icon && this.applicationIcon) {
  805. this.element.className += ' ath-icon';
  806. this.img = document.createElement('img');
  807. this.img.className = 'ath-application-icon';
  808. this.img.addEventListener('load', this, false);
  809. this.img.addEventListener('error', this, false);
  810. this.img.src = this.applicationIcon.href;
  811. this.element.appendChild(this.img);
  812. }
  813. this.element.innerHTML += message;
  814. // we are not ready to show, place the message out of sight
  815. this.viewport.style.left = '-99999em';
  816. // attach all elements to the DOM
  817. this.viewport.appendChild(this.element);
  818. this.container.appendChild(this.viewport);
  819. // if we don't have to wait for an image to load, show the message right away
  820. if (!this.img) {
  821. this._delayedShow();
  822. }
  823. },
  824. _delayedShow: function(e) {
  825. setTimeout(this._show.bind(this), this.options.startDelay * 1000 + 500);
  826. },
  827. _show: function() {
  828. var that = this;
  829. // update the viewport size and orientation
  830. this.updateViewport();
  831. // reposition/resize the message on orientation change
  832. window.addEventListener('resize', this, false);
  833. window.addEventListener('scroll', this, false);
  834. window.addEventListener('orientationchange', this, false);
  835. if (this.options.modal) {
  836. // lock any other interaction
  837. document.addEventListener('touchmove', this, true);
  838. }
  839. // Enable closing after 1 second
  840. if (!this.options.mandatory) {
  841. setTimeout(function() {
  842. that.element.addEventListener('click', that, true);
  843. }, 1000);
  844. }
  845. // kick the animation
  846. setTimeout(function() {
  847. that.element.style.webkitTransform = 'translate3d(0,0,0)';
  848. that.element.style.webkitTransitionDuration = '1.2s';
  849. }, 0);
  850. // set the destroy timer
  851. if (this.options.lifespan) {
  852. this.removeTimer = setTimeout(this.remove.bind(this), this.options.lifespan * 1000);
  853. }
  854. // fire the custom onShow event
  855. if (this.options.onShow) {
  856. this.options.onShow.call(this);
  857. }
  858. },
  859. remove: function() {
  860. clearTimeout(this.removeTimer);
  861. // clear up the event listeners
  862. if (this.img) {
  863. this.img.removeEventListener('load', this, false);
  864. this.img.removeEventListener('error', this, false);
  865. }
  866. window.removeEventListener('resize', this, false);
  867. window.removeEventListener('scroll', this, false);
  868. window.removeEventListener('orientationchange', this, false);
  869. document.removeEventListener('touchmove', this, true);
  870. this.element.removeEventListener('click', this, true);
  871. // remove the message element on transition end
  872. this.element.addEventListener('transitionend', this, false);
  873. this.element.addEventListener('webkitTransitionEnd', this, false);
  874. this.element.addEventListener('MSTransitionEnd', this, false);
  875. // start the fade out animation
  876. this.element.style.webkitTransitionDuration = '0.3s';
  877. this.element.style.opacity = '0';
  878. },
  879. _removeElements: function() {
  880. this.element.removeEventListener('transitionend', this, false);
  881. this.element.removeEventListener('webkitTransitionEnd', this, false);
  882. this.element.removeEventListener('MSTransitionEnd', this, false);
  883. // remove the message from the DOM
  884. this.container.removeChild(this.viewport);
  885. this.shown = false;
  886. // fire the custom onRemove event
  887. if (this.options.onRemove) {
  888. this.options.onRemove.call(this);
  889. }
  890. },
  891. updateViewport: function() {
  892. if (!this.shown) {
  893. return;
  894. }
  895. this.viewport.style.width = window.innerWidth + 'px';
  896. this.viewport.style.height = window.innerHeight + 'px';
  897. this.viewport.style.left = window.scrollX + 'px';
  898. this.viewport.style.top = window.scrollY + 'px';
  899. var clientWidth = document.documentElement.clientWidth;
  900. this.orientation = clientWidth > document.documentElement.clientHeight ? 'landscape' : 'portrait';
  901. var screenWidth = ath.OS == 'ios' ? this.orientation == 'portrait' ? screen.width : screen.height : screen.width;
  902. this.scale = screen.width > clientWidth ? 1 : screenWidth / window.innerWidth;
  903. this.element.style.fontSize = this.options.fontSize / this.scale + 'px';
  904. },
  905. resize: function() {
  906. clearTimeout(this.resizeTimer);
  907. this.resizeTimer = setTimeout(this.updateViewport.bind(this), 100);
  908. },
  909. updateSession: function() {
  910. if (ath.hasLocalStorage === false) {
  911. return;
  912. }
  913. localStorage.setItem(this.options.appID, JSON.stringify(this.session));
  914. },
  915. clearSession: function() {
  916. this.session = _defaultSession;
  917. this.updateSession();
  918. },
  919. optOut: function() {
  920. this.session.optedout = true;
  921. this.updateSession();
  922. },
  923. optIn: function() {
  924. this.session.optedout = false;
  925. this.updateSession();
  926. },
  927. clearDisplayCount: function() {
  928. this.session.displayCount = 0;
  929. this.updateSession();
  930. },
  931. _preventDefault: function(e) {
  932. e.preventDefault();
  933. e.stopPropagation();
  934. }
  935. };
  936. // utility
  937. function _extend(target, obj) {
  938. for (var i in obj) {
  939. target[i] = obj[i];
  940. }
  941. return target;
  942. }
  943. function _removeToken() {
  944. if (document.location.hash == '#ath') {
  945. history.replaceState('', window.document.title, document.location.href.split('#')[0]);
  946. }
  947. if (_reSmartURL.test(document.location.href)) {
  948. history.replaceState('', window.document.title, document.location.href.replace(_reSmartURL, '$1'));
  949. }
  950. if (_reQueryString.test(document.location.search)) {
  951. history.replaceState('', window.document.title, document.location.href.replace(_reQueryString, '$2'));
  952. }
  953. }
  954. /* jshint +W101, +W106 */
  955. $.AMUI.addToHomescreen = ath;
  956. module.exports = ath;
  957. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  958. },{"2":2}],4:[function(_dereq_,module,exports){
  959. (function (global){
  960. 'use strict';
  961. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  962. var UI = _dereq_(2);
  963. /**
  964. * @via https://github.com/Minwe/bootstrap/blob/master/js/alert.js
  965. * @copyright Copyright 2013 Twitter, Inc.
  966. * @license Apache 2.0
  967. */
  968. // Alert Class
  969. // NOTE: removeElement option is unavailable now
  970. var Alert = function(element, options) {
  971. var _this = this;
  972. this.options = $.extend({}, Alert.DEFAULTS, options);
  973. this.$element = $(element);
  974. this.$element.
  975. addClass('am-fade am-in').
  976. on('click.alert.amui', '.am-close', function() {
  977. _this.close.call(this);
  978. });
  979. };
  980. Alert.DEFAULTS = {
  981. removeElement: true
  982. };
  983. Alert.prototype.close = function() {
  984. var $this = $(this);
  985. var $target = $this.hasClass('am-alert') ?
  986. $this :
  987. $this.parent('.am-alert');
  988. $target.trigger('close.alert.amui');
  989. $target.removeClass('am-in');
  990. function processAlert() {
  991. $target.trigger('closed.alert.amui').remove();
  992. }
  993. UI.support.transition && $target.hasClass('am-fade') ?
  994. $target.
  995. one(UI.support.transition.end, processAlert).
  996. emulateTransitionEnd(200) : processAlert();
  997. };
  998. // Alert Plugin
  999. $.fn.alert = function(option) {
  1000. return this.each(function() {
  1001. var $this = $(this);
  1002. var data = $this.data('amui.alert');
  1003. var options = typeof option == 'object' && option;
  1004. if (!data) {
  1005. $this.data('amui.alert', (data = new Alert(this, options || {})));
  1006. }
  1007. if (typeof option == 'string') {
  1008. data[option].call($this);
  1009. }
  1010. });
  1011. };
  1012. // Init code
  1013. $(document).on('click.alert.amui.data-api', '[data-am-alert]', function(e) {
  1014. var $target = $(e.target);
  1015. $(this).addClass('am-fade am-in');
  1016. $target.is('.am-close') && $(this).alert('close');
  1017. });
  1018. $.AMUI.alert = Alert;
  1019. module.exports = Alert;
  1020. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1021. },{"2":2}],5:[function(_dereq_,module,exports){
  1022. (function (global){
  1023. 'use strict';
  1024. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  1025. var UI = _dereq_(2);
  1026. /**
  1027. * @via https://github.com/twbs/bootstrap/blob/master/js/button.js
  1028. * @copyright (c) 2011-2014 Twitter, Inc
  1029. * @license The MIT License
  1030. */
  1031. var Button = function(element, options) {
  1032. this.$element = $(element);
  1033. this.options = $.extend({}, Button.DEFAULTS, options);
  1034. this.isLoading = false;
  1035. this.hasSpinner = false;
  1036. };
  1037. Button.DEFAULTS = {
  1038. loadingText: 'loading...',
  1039. className: {
  1040. loading: 'am-btn-loading',
  1041. disabled: 'am-disabled'
  1042. },
  1043. spinner: undefined
  1044. };
  1045. Button.prototype.setState = function(state) {
  1046. var disabled = 'disabled';
  1047. var $element = this.$element;
  1048. var options = this.options;
  1049. var val = $element.is('input') ? 'val' : 'html';
  1050. var loadingClassName = options.className.disabled + ' ' +
  1051. options.className.loading;
  1052. state = state + 'Text';
  1053. if (!options.resetText) {
  1054. options.resetText = $element[val]();
  1055. }
  1056. // add spinner for element with html()
  1057. if (UI.support.animation && options.spinner &&
  1058. val === 'html' && !this.hasSpinner) {
  1059. options.loadingText = '<span class="am-icon-' +
  1060. options.spinner +
  1061. ' am-icon-spin"></span>' + options.loadingText;
  1062. this.hasSpinner = true;
  1063. }
  1064. $element[val](options[state]);
  1065. // push to event loop to allow forms to submit
  1066. setTimeout($.proxy(function() {
  1067. if (state == 'loadingText') {
  1068. $element.addClass(loadingClassName).attr(disabled, disabled);
  1069. this.isLoading = true;
  1070. } else if (this.isLoading) {
  1071. $element.removeClass(loadingClassName).removeAttr(disabled);
  1072. this.isLoading = false;
  1073. }
  1074. }, this), 0);
  1075. };
  1076. Button.prototype.toggle = function() {
  1077. var changed = true;
  1078. var $element = this.$element;
  1079. var $parent = this.$element.parent('.am-btn-group');
  1080. if ($parent.length) {
  1081. var $input = this.$element.find('input');
  1082. if ($input.prop('type') == 'radio') {
  1083. if ($input.prop('checked') && $element.hasClass('am-active')) {
  1084. changed = false;
  1085. } else {
  1086. $parent.find('.am-active').removeClass('am-active');
  1087. }
  1088. }
  1089. if (changed) {
  1090. $input.prop('checked',
  1091. !$element.hasClass('am-active')).trigger('change');
  1092. }
  1093. }
  1094. if (changed) {
  1095. $element.toggleClass('am-active');
  1096. if (!$element.hasClass('am-active')) {
  1097. $element.blur();
  1098. }
  1099. }
  1100. };
  1101. // Button plugin
  1102. function Plugin(option) {
  1103. return this.each(function() {
  1104. var $this = $(this);
  1105. var data = $this.data('amui.button');
  1106. var options = typeof option == 'object' && option || {};
  1107. if (!data) {
  1108. $this.data('amui.button', (data = new Button(this, options)));
  1109. }
  1110. if (option == 'toggle') {
  1111. data.toggle();
  1112. } else if (typeof option == 'string') {
  1113. data.setState(option);
  1114. }
  1115. });
  1116. }
  1117. $.fn.button = Plugin;
  1118. // Init code
  1119. $(document).on('click.button.amui.data-api', '[data-am-button]', function(e) {
  1120. var $btn = $(e.target);
  1121. if (!$btn.hasClass('am-btn')) {
  1122. $btn = $btn.closest('.am-btn');
  1123. }
  1124. Plugin.call($btn, 'toggle');
  1125. e.preventDefault();
  1126. });
  1127. UI.ready(function(context) {
  1128. $('[data-am-loading]', context).each(function() {
  1129. $(this).button(UI.utils.parseOptions($(this).data('amLoading')));
  1130. });
  1131. });
  1132. $.AMUI.button = Button;
  1133. module.exports = Button;
  1134. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1135. },{"2":2}],6:[function(_dereq_,module,exports){
  1136. (function (global){
  1137. 'use strict';
  1138. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  1139. var UI = _dereq_(2);
  1140. /**
  1141. * @via https://github.com/twbs/bootstrap/blob/master/js/collapse.js
  1142. * @copyright (c) 2011-2014 Twitter, Inc
  1143. * @license The MIT License
  1144. */
  1145. var Collapse = function(element, options) {
  1146. this.$element = $(element);
  1147. this.options = $.extend({}, Collapse.DEFAULTS, options);
  1148. this.transitioning = null;
  1149. if (this.options.parent) {
  1150. this.$parent = $(this.options.parent);
  1151. }
  1152. if (this.options.toggle) {
  1153. this.toggle();
  1154. }
  1155. };
  1156. Collapse.DEFAULTS = {
  1157. toggle: true
  1158. };
  1159. Collapse.prototype.open = function() {
  1160. if (this.transitioning || this.$element.hasClass('am-in')) {
  1161. return;
  1162. }
  1163. var startEvent = $.Event('open.collapse.amui');
  1164. this.$element.trigger(startEvent);
  1165. if (startEvent.isDefaultPrevented()) {
  1166. return;
  1167. }
  1168. var actives = this.$parent && this.$parent.find('> .am-panel > .am-in');
  1169. if (actives && actives.length) {
  1170. var hasData = actives.data('amui.collapse');
  1171. if (hasData && hasData.transitioning) {
  1172. return;
  1173. }
  1174. Plugin.call(actives, 'close');
  1175. hasData || actives.data('amui.collapse', null);
  1176. }
  1177. this.$element
  1178. .removeClass('am-collapse')
  1179. .addClass('am-collapsing').height(0);
  1180. this.transitioning = 1;
  1181. var complete = function() {
  1182. this.$element.
  1183. removeClass('am-collapsing').
  1184. addClass('am-collapse am-in').
  1185. height('');
  1186. this.transitioning = 0;
  1187. this.$element.trigger('opened.collapse.amui');
  1188. };
  1189. if (!UI.support.transition) {
  1190. return complete.call(this);
  1191. }
  1192. var scrollHeight = this.$element[0].scrollHeight;
  1193. this.$element
  1194. .one(UI.support.transition.end, $.proxy(complete, this))
  1195. .emulateTransitionEnd(300).
  1196. css({height: scrollHeight}); // 当折叠的容器有 padding 时,如果用 height() 只能设置内容的宽度
  1197. };
  1198. Collapse.prototype.close = function() {
  1199. if (this.transitioning || !this.$element.hasClass('am-in')) {
  1200. return;
  1201. }
  1202. var startEvent = $.Event('close.collapse.amui');
  1203. this.$element.trigger(startEvent);
  1204. if (startEvent.isDefaultPrevented()) {
  1205. return;
  1206. }
  1207. this.$element.height(this.$element.height()).redraw();
  1208. this.$element.addClass('am-collapsing').
  1209. removeClass('am-collapse am-in');
  1210. this.transitioning = 1;
  1211. var complete = function() {
  1212. this.transitioning = 0;
  1213. this.$element.trigger('closed.collapse.amui').
  1214. removeClass('am-collapsing').
  1215. addClass('am-collapse');
  1216. // css({height: '0'});
  1217. };
  1218. if (!UI.support.transition) {
  1219. return complete.call(this);
  1220. }
  1221. this.$element.height(0)
  1222. .one(UI.support.transition.end, $.proxy(complete, this))
  1223. .emulateTransitionEnd(300);
  1224. };
  1225. Collapse.prototype.toggle = function() {
  1226. this[this.$element.hasClass('am-in') ? 'close' : 'open']();
  1227. };
  1228. // Collapse Plugin
  1229. function Plugin(option) {
  1230. return this.each(function() {
  1231. var $this = $(this);
  1232. var data = $this.data('amui.collapse');
  1233. var options = $.extend({}, Collapse.DEFAULTS,
  1234. UI.utils.options($this.attr('data-am-collapse')),
  1235. typeof option == 'object' && option);
  1236. if (!data && options.toggle && option == 'open') {
  1237. option = !option;
  1238. }
  1239. if (!data) {
  1240. $this.data('amui.collapse', (data = new Collapse(this, options)));
  1241. }
  1242. if (typeof option == 'string') {
  1243. data[option]();
  1244. }
  1245. });
  1246. }
  1247. $.fn.collapse = Plugin;
  1248. // Init code
  1249. $(document).on('click.collapse.amui.data-api', '[data-am-collapse]',
  1250. function(e) {
  1251. var href;
  1252. var $this = $(this);
  1253. var options = UI.utils.options($this.attr('data-am-collapse'));
  1254. var target = options.target ||
  1255. e.preventDefault() ||
  1256. (href = $this.attr('href')) &&
  1257. href.replace(/.*(?=#[^\s]+$)/, '');
  1258. var $target = $(target);
  1259. var data = $target.data('amui.collapse');
  1260. var option = data ? 'toggle' : options;
  1261. var parent = options.parent;
  1262. var $parent = parent && $(parent);
  1263. if (!data || !data.transitioning) {
  1264. if ($parent) {
  1265. // '[data-am-collapse*="{parent: \'' + parent + '"]
  1266. $parent.find('[data-am-collapse]').not($this).addClass('am-collapsed');
  1267. }
  1268. $this[$target.hasClass('am-in') ? 'addClass' :
  1269. 'removeClass']('am-collapsed');
  1270. }
  1271. Plugin.call($target, option);
  1272. });
  1273. $.AMUI.collapse = Collapse;
  1274. module.exports = Collapse;
  1275. // TODO: 更好的 target 选择方式
  1276. // 折叠的容器必须没有 border/padding 才能正常处理,否则动画会有一些小问题
  1277. // 寻找更好的未知高度 transition 动画解决方案,max-height 之类的就算了
  1278. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1279. },{"2":2}],7:[function(_dereq_,module,exports){
  1280. (function (global){
  1281. 'use strict';
  1282. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  1283. var UI = _dereq_(2);
  1284. var $doc = $(document);
  1285. /**
  1286. * bootstrap-datepicker.js
  1287. * @via http://www.eyecon.ro/bootstrap-datepicker
  1288. * @license http://www.apache.org/licenses/LICENSE-2.0
  1289. */
  1290. var Datepicker = function(element, options) {
  1291. this.$element = $(element);
  1292. this.options = $.extend({}, Datepicker.DEFAULTS, options);
  1293. this.format = DPGlobal.parseFormat(this.options.format);
  1294. this.$element.data('date', this.options.date);
  1295. this.language = this.getLocale(this.options.locale);
  1296. this.theme = this.options.theme;
  1297. this.$picker = $(DPGlobal.template).appendTo('body').on({
  1298. click: $.proxy(this.click, this)
  1299. // mousedown: $.proxy(this.mousedown, this)
  1300. });
  1301. this.isInput = this.$element.is('input');
  1302. this.component = this.$element.is('.am-datepicker-date') ?
  1303. this.$element.find('.am-datepicker-add-on') : false;
  1304. if (this.isInput) {
  1305. this.$element.on({
  1306. 'click.datepicker.amui': $.proxy(this.open, this),
  1307. // blur: $.proxy(this.close, this),
  1308. 'keyup.datepicker.amui': $.proxy(this.update, this)
  1309. });
  1310. } else {
  1311. if (this.component) {
  1312. this.component.on('click.datepicker.amui', $.proxy(this.open, this));
  1313. } else {
  1314. this.$element.on('click.datepicker.amui', $.proxy(this.open, this));
  1315. }
  1316. }
  1317. this.minViewMode = this.options.minViewMode;
  1318. if (typeof this.minViewMode === 'string') {
  1319. switch (this.minViewMode) {
  1320. case 'months':
  1321. this.minViewMode = 1;
  1322. break;
  1323. case 'years':
  1324. this.minViewMode = 2;
  1325. break;
  1326. default:
  1327. this.minViewMode = 0;
  1328. break;
  1329. }
  1330. }
  1331. this.viewMode = this.options.viewMode;
  1332. if (typeof this.viewMode === 'string') {
  1333. switch (this.viewMode) {
  1334. case 'months':
  1335. this.viewMode = 1;
  1336. break;
  1337. case 'years':
  1338. this.viewMode = 2;
  1339. break;
  1340. default:
  1341. this.viewMode = 0;
  1342. break;
  1343. }
  1344. }
  1345. this.startViewMode = this.viewMode;
  1346. this.weekStart = ((this.options.weekStart ||
  1347. Datepicker.locales[this.language].weekStart || 0) % 7);
  1348. this.weekEnd = ((this.weekStart + 6) % 7);
  1349. this.onRender = this.options.onRender;
  1350. this.setTheme();
  1351. this.fillDow();
  1352. this.fillMonths();
  1353. this.update();
  1354. this.showMode();
  1355. };
  1356. Datepicker.DEFAULTS = {
  1357. locale: 'zh_CN',
  1358. format: 'yyyy-mm-dd',
  1359. weekStart: undefined,
  1360. viewMode: 0,
  1361. minViewMode: 0,
  1362. date: '',
  1363. theme: '',
  1364. autoClose: 1,
  1365. onRender: function(date) {
  1366. return '';
  1367. }
  1368. };
  1369. Datepicker.prototype.open = function(e) {
  1370. this.$picker.show();
  1371. this.height = this.component ?
  1372. this.component.outerHeight() : this.$element.outerHeight();
  1373. this.place();
  1374. $(window).on('resize.datepicker.amui', $.proxy(this.place, this));
  1375. if (e) {
  1376. e.stopPropagation();
  1377. e.preventDefault();
  1378. }
  1379. var that = this;
  1380. $doc.on('mousedown.datapicker.amui touchstart.datepicker.amui', function(ev) {
  1381. if ($(ev.target).closest('.am-datepicker').length === 0) {
  1382. that.close();
  1383. }
  1384. });
  1385. this.$element.trigger({
  1386. type: 'open.datepicker.amui',
  1387. date: this.date
  1388. });
  1389. };
  1390. Datepicker.prototype.close = function() {
  1391. this.$picker.hide();
  1392. $(window).off('resize.datepicker.amui', this.place);
  1393. this.viewMode = this.startViewMode;
  1394. this.showMode();
  1395. if (!this.isInput) {
  1396. $(document).off('mousedown.datapicker.amui touchstart.datepicker.amui', this.close);
  1397. }
  1398. // this.set();
  1399. this.$element.trigger({
  1400. type: 'close.datepicker.amui',
  1401. date: this.date
  1402. });
  1403. };
  1404. Datepicker.prototype.set = function() {
  1405. var formated = DPGlobal.formatDate(this.date, this.format);
  1406. if (!this.isInput) {
  1407. if (this.component) {
  1408. this.$element.find('input').prop('value', formated);
  1409. }
  1410. this.$element.data('date', formated);
  1411. } else {
  1412. this.$element.prop('value', formated);
  1413. }
  1414. };
  1415. Datepicker.prototype.setValue = function(newDate) {
  1416. if (typeof newDate === 'string') {
  1417. this.date = DPGlobal.parseDate(newDate, this.format);
  1418. } else {
  1419. this.date = new Date(newDate);
  1420. }
  1421. this.set();
  1422. this.viewDate = new Date(this.date.getFullYear(),
  1423. this.date.getMonth(), 1, 0, 0, 0, 0);
  1424. this.fill();
  1425. };
  1426. Datepicker.prototype.place = function() {
  1427. var offset = this.component ?
  1428. this.component.offset() : this.$element.offset();
  1429. var $width = this.component ?
  1430. this.component.width() : this.$element.width();
  1431. var top = offset.top + this.height;
  1432. var left = offset.left;
  1433. var right = $doc.width() - offset.left - $width;
  1434. var isOutView = this.isOutView();
  1435. this.$picker.removeClass('am-datepicker-right');
  1436. this.$picker.removeClass('am-datepicker-up');
  1437. if ($doc.width() > 640) {
  1438. if (isOutView.outRight) {
  1439. this.$picker.addClass('am-datepicker-right');
  1440. this.$picker.css({
  1441. top: top,
  1442. left: 'auto',
  1443. right: right
  1444. });
  1445. return;
  1446. }
  1447. if (isOutView.outBottom) {
  1448. this.$picker.addClass('am-datepicker-up');
  1449. top = offset.top - this.$picker.outerHeight(true);
  1450. }
  1451. } else {
  1452. left = 0;
  1453. }
  1454. this.$picker.css({
  1455. top: top,
  1456. left: left
  1457. });
  1458. };
  1459. Datepicker.prototype.update = function(newDate) {
  1460. this.date = DPGlobal.parseDate(
  1461. typeof newDate === 'string' ? newDate : (this.isInput ?
  1462. this.$element.prop('value') : this.$element.data('date')),
  1463. this.format
  1464. );
  1465. this.viewDate = new Date(this.date.getFullYear(),
  1466. this.date.getMonth(), 1, 0, 0, 0, 0);
  1467. this.fill();
  1468. };
  1469. // Days of week
  1470. Datepicker.prototype.fillDow = function() {
  1471. var dowCount = this.weekStart;
  1472. var html = '<tr>';
  1473. while (dowCount < this.weekStart + 7) {
  1474. // NOTE: do % then add 1
  1475. html += '<th class="am-datepicker-dow">' +
  1476. Datepicker.locales[this.language].daysMin[(dowCount++) % 7] +
  1477. '</th>';
  1478. }
  1479. html += '</tr>';
  1480. this.$picker.find('.am-datepicker-days thead').append(html);
  1481. };
  1482. Datepicker.prototype.fillMonths = function() {
  1483. var html = '';
  1484. var i = 0;
  1485. while (i < 12) {
  1486. html += '<span class="am-datepicker-month">' +
  1487. Datepicker.locales[this.language].monthsShort[i++] + '</span>';
  1488. }
  1489. this.$picker.find('.am-datepicker-months td').append(html);
  1490. };
  1491. Datepicker.prototype.fill = function() {
  1492. var d = new Date(this.viewDate);
  1493. var year = d.getFullYear();
  1494. var month = d.getMonth();
  1495. var currentDate = this.date.valueOf();
  1496. var prevMonth = new Date(year, month - 1, 28, 0, 0, 0, 0);
  1497. var day = DPGlobal
  1498. .getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth());
  1499. var daysSelect = this.$picker
  1500. .find('.am-datepicker-days .am-datepicker-select');
  1501. if (this.language === 'zh_CN') {
  1502. daysSelect.text(year + Datepicker.locales[this.language].year[0] +
  1503. ' ' + Datepicker.locales[this.language].months[month]);
  1504. } else {
  1505. daysSelect.text(Datepicker.locales[this.language].months[month] +
  1506. ' ' + year);
  1507. }
  1508. prevMonth.setDate(day);
  1509. prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7) % 7);
  1510. var nextMonth = new Date(prevMonth);
  1511. nextMonth.setDate(nextMonth.getDate() + 42);
  1512. nextMonth = nextMonth.valueOf();
  1513. var html = [];
  1514. var className;
  1515. var prevY;
  1516. var prevM;
  1517. while (prevMonth.valueOf() < nextMonth) {
  1518. if (prevMonth.getDay() === this.weekStart) {
  1519. html.push('<tr>');
  1520. }
  1521. className = this.onRender(prevMonth);
  1522. prevY = prevMonth.getFullYear();
  1523. prevM = prevMonth.getMonth();
  1524. if ((prevM < month && prevY === year) || prevY < year) {
  1525. className += ' am-datepicker-old';
  1526. } else if ((prevM > month && prevY === year) || prevY > year) {
  1527. className += ' am-datepicker-new';
  1528. }
  1529. if (prevMonth.valueOf() === currentDate) {
  1530. className += ' am-active';
  1531. }
  1532. html.push('<td class="am-datepicker-day ' +
  1533. className + '">' + prevMonth.getDate() + '</td>');
  1534. if (prevMonth.getDay() === this.weekEnd) {
  1535. html.push('</tr>');
  1536. }
  1537. prevMonth.setDate(prevMonth.getDate() + 1);
  1538. }
  1539. this.$picker.find('.am-datepicker-days tbody')
  1540. .empty().append(html.join(''));
  1541. var currentYear = this.date.getFullYear();
  1542. var months = this.$picker.find('.am-datepicker-months')
  1543. .find('.am-datepicker-select')
  1544. .text(year);
  1545. months = months.end()
  1546. .find('span').removeClass('am-active').removeClass('am-disabled');
  1547. var monthLen = 0;
  1548. while(monthLen < 12) {
  1549. if (this.onRender(d.setFullYear(year, monthLen))) {
  1550. months.eq(monthLen).addClass('am-disabled');
  1551. }
  1552. monthLen++;
  1553. }
  1554. if (currentYear === year) {
  1555. months.eq(this.date.getMonth())
  1556. .removeClass('am-disabled')
  1557. .addClass('am-active');
  1558. }
  1559. html = '';
  1560. year = parseInt(year / 10, 10) * 10;
  1561. var yearCont = this.$picker
  1562. .find('.am-datepicker-years')
  1563. .find('.am-datepicker-select')
  1564. .text(year + '-' + (year + 9))
  1565. .end()
  1566. .find('td');
  1567. var yearClassName;
  1568. year -= 1;
  1569. for (var i = -1; i < 11; i++) {
  1570. yearClassName = this.onRender(d.setFullYear(year));
  1571. html += '<span class="'+ yearClassName +'' +
  1572. (i === -1 || i === 10 ? ' am-datepicker-old' : '') +
  1573. (currentYear === year ? ' am-active' : '') + '">' + year + '</span>';
  1574. year += 1;
  1575. }
  1576. yearCont.html(html);
  1577. };
  1578. Datepicker.prototype.click = function(event) {
  1579. event.stopPropagation();
  1580. event.preventDefault();
  1581. var month;
  1582. var year;
  1583. var $dayActive = this.$picker.find('.am-datepicker-days').find('.am-active');
  1584. var $months = this.$picker.find('.am-datepicker-months');
  1585. var $monthIndex = $months.find('.am-active').index();
  1586. var $target = $(event.target).closest('span, td, th');
  1587. if ($target.length === 1) {
  1588. switch ($target[0].nodeName.toLowerCase()) {
  1589. case 'th':
  1590. switch ($target[0].className) {
  1591. case 'am-datepicker-switch':
  1592. this.showMode(1);
  1593. break;
  1594. case 'am-datepicker-prev':
  1595. case 'am-datepicker-next':
  1596. this.viewDate['set' + DPGlobal.modes[this.viewMode].navFnc].call(
  1597. this.viewDate,
  1598. this.viewDate
  1599. ['get' + DPGlobal.modes[this.viewMode].navFnc]
  1600. .call(this.viewDate) +
  1601. DPGlobal.modes[this.viewMode].navStep *
  1602. ($target[0].className === 'am-datepicker-prev' ? -1 : 1)
  1603. );
  1604. this.fill();
  1605. this.set();
  1606. break;
  1607. }
  1608. break;
  1609. case 'span':
  1610. if ($target.is('.am-disabled')) {
  1611. return
  1612. }
  1613. if ($target.is('.am-datepicker-month')) {
  1614. month = $target.parent().find('span').index($target);
  1615. if ($target.is('.am-active')) {
  1616. this.viewDate.setMonth(month, $dayActive.text());
  1617. } else {
  1618. this.viewDate.setMonth(month);
  1619. }
  1620. } else {
  1621. year = parseInt($target.text(), 10) || 0;
  1622. if ($target.is('.am-active')) {
  1623. this.viewDate.setFullYear(year, $monthIndex, $dayActive.text());
  1624. } else {
  1625. this.viewDate.setFullYear(year);
  1626. }
  1627. }
  1628. if (this.viewMode !== 0) {
  1629. this.date = new Date(this.viewDate);
  1630. this.$element.trigger({
  1631. type: 'changeDate.datepicker.amui',
  1632. date: this.date,
  1633. viewMode: DPGlobal.modes[this.viewMode].clsName
  1634. });
  1635. }
  1636. this.showMode(-1);
  1637. this.fill();
  1638. this.set();
  1639. break;
  1640. case 'td':
  1641. if ($target.is('.am-datepicker-day') && !$target.is('.am-disabled')) {
  1642. var day = parseInt($target.text(), 10) || 1;
  1643. month = this.viewDate.getMonth();
  1644. if ($target.is('.am-datepicker-old')) {
  1645. month -= 1;
  1646. } else if ($target.is('.am-datepicker-new')) {
  1647. month += 1;
  1648. }
  1649. year = this.viewDate.getFullYear();
  1650. this.date = new Date(year, month, day, 0, 0, 0, 0);
  1651. this.viewDate = new Date(year, month, Math.min(28, day), 0, 0, 0, 0);
  1652. this.fill();
  1653. this.set();
  1654. this.$element.trigger({
  1655. type: 'changeDate.datepicker.amui',
  1656. date: this.date,
  1657. viewMode: DPGlobal.modes[this.viewMode].clsName
  1658. });
  1659. this.options.autoClose && this.close();
  1660. }
  1661. break;
  1662. }
  1663. }
  1664. };
  1665. Datepicker.prototype.mousedown = function(event) {
  1666. event.stopPropagation();
  1667. event.preventDefault();
  1668. };
  1669. Datepicker.prototype.showMode = function(dir) {
  1670. if (dir) {
  1671. this.viewMode = Math.max(this.minViewMode,
  1672. Math.min(2, this.viewMode + dir));
  1673. }
  1674. this.$picker.find('>div').hide().
  1675. filter('.am-datepicker-' + DPGlobal.modes[this.viewMode].clsName).show();
  1676. };
  1677. Datepicker.prototype.isOutView = function() {
  1678. var offset = this.component ?
  1679. this.component.offset() : this.$element.offset();
  1680. var isOutView = {
  1681. outRight: false,
  1682. outBottom: false
  1683. };
  1684. var $picker = this.$picker;
  1685. var width = offset.left + $picker.outerWidth(true);
  1686. var height = offset.top + $picker.outerHeight(true) +
  1687. this.$element.innerHeight();
  1688. if (width > $doc.width()) {
  1689. isOutView.outRight = true;
  1690. }
  1691. if (height > $doc.height()) {
  1692. isOutView.outBottom = true;
  1693. }
  1694. return isOutView;
  1695. };
  1696. Datepicker.prototype.getLocale = function(locale) {
  1697. if (!locale) {
  1698. locale = navigator.language && navigator.language.split('-');
  1699. locale[1] = locale[1].toUpperCase();
  1700. locale = locale.join('_');
  1701. }
  1702. if (!Datepicker.locales[locale]) {
  1703. locale = 'en_US';
  1704. }
  1705. return locale;
  1706. };
  1707. Datepicker.prototype.setTheme = function() {
  1708. if (this.theme) {
  1709. this.$picker.addClass('am-datepicker-' + this.theme);
  1710. }
  1711. };
  1712. // Datepicker locales
  1713. Datepicker.locales = {
  1714. en_US: {
  1715. days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
  1716. 'Friday', 'Saturday'],
  1717. daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  1718. daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
  1719. months: ['January', 'February', 'March', 'April', 'May', 'June',
  1720. 'July', 'August', 'September', 'October', 'November', 'December'],
  1721. monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  1722. 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  1723. weekStart: 0
  1724. },
  1725. zh_CN: {
  1726. days: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  1727. daysShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
  1728. daysMin: ['日', '一', '二', '三', '四', '五', '六'],
  1729. months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月',
  1730. '八月', '九月', '十月', '十一月', '十二月'],
  1731. monthsShort: ['一月', '二月', '三月', '四月', '五月', '六月',
  1732. '七月', '八月', '九月', '十月', '十一月', '十二月'],
  1733. weekStart: 1,
  1734. year: ['年']
  1735. }
  1736. };
  1737. var DPGlobal = {
  1738. modes: [
  1739. {
  1740. clsName: 'days',
  1741. navFnc: 'Month',
  1742. navStep: 1
  1743. },
  1744. {
  1745. clsName: 'months',
  1746. navFnc: 'FullYear',
  1747. navStep: 1
  1748. },
  1749. {
  1750. clsName: 'years',
  1751. navFnc: 'FullYear',
  1752. navStep: 10
  1753. }
  1754. ],
  1755. isLeapYear: function(year) {
  1756. return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
  1757. },
  1758. getDaysInMonth: function(year, month) {
  1759. return [31, (DPGlobal.isLeapYear(year) ? 29 : 28),
  1760. 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
  1761. },
  1762. parseFormat: function(format) {
  1763. var separator = format.match(/[.\/\-\s].*?/);
  1764. var parts = format.split(/\W+/);
  1765. if (!separator || !parts || parts.length === 0) {
  1766. throw new Error('Invalid date format.');
  1767. }
  1768. return {
  1769. separator: separator,
  1770. parts: parts
  1771. };
  1772. },
  1773. parseDate: function(date, format) {
  1774. var parts = date.split(format.separator);
  1775. var val;
  1776. date = new Date();
  1777. date.setHours(0);
  1778. date.setMinutes(0);
  1779. date.setSeconds(0);
  1780. date.setMilliseconds(0);
  1781. if (parts.length === format.parts.length) {
  1782. var year = date.getFullYear();
  1783. var day = date.getDate();
  1784. var month = date.getMonth();
  1785. for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
  1786. val = parseInt(parts[i], 10) || 1;
  1787. switch (format.parts[i]) {
  1788. case 'dd':
  1789. case 'd':
  1790. day = val;
  1791. date.setDate(val);
  1792. break;
  1793. case 'mm':
  1794. case 'm':
  1795. month = val - 1;
  1796. date.setMonth(val - 1);
  1797. break;
  1798. case 'yy':
  1799. year = 2000 + val;
  1800. date.setFullYear(2000 + val);
  1801. break;
  1802. case 'yyyy':
  1803. year = val;
  1804. date.setFullYear(val);
  1805. break;
  1806. }
  1807. }
  1808. date = new Date(year, month, day, 0, 0, 0);
  1809. }
  1810. return date;
  1811. },
  1812. formatDate: function(date, format) {
  1813. var val = {
  1814. d: date.getDate(),
  1815. m: date.getMonth() + 1,
  1816. yy: date.getFullYear().toString().substring(2),
  1817. yyyy: date.getFullYear()
  1818. };
  1819. var dateArray = [];
  1820. val.dd = (val.d < 10 ? '0' : '') + val.d;
  1821. val.mm = (val.m < 10 ? '0' : '') + val.m;
  1822. for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
  1823. dateArray.push(val[format.parts[i]]);
  1824. }
  1825. return dateArray.join(format.separator);
  1826. },
  1827. headTemplate: '<thead>' +
  1828. '<tr class="am-datepicker-header">' +
  1829. '<th class="am-datepicker-prev">' +
  1830. '<i class="am-datepicker-prev-icon"></i></th>' +
  1831. '<th colspan="5" class="am-datepicker-switch">' +
  1832. '<div class="am-datepicker-select"></div></th>' +
  1833. '<th class="am-datepicker-next"><i class="am-datepicker-next-icon"></i>' +
  1834. '</th></tr></thead>',
  1835. contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
  1836. };
  1837. DPGlobal.template = '<div class="am-datepicker am-datepicker-dropdown">' +
  1838. '<div class="am-datepicker-caret"></div>' +
  1839. '<div class="am-datepicker-days">' +
  1840. '<table class="am-datepicker-table">' +
  1841. DPGlobal.headTemplate +
  1842. '<tbody></tbody>' +
  1843. '</table>' +
  1844. '</div>' +
  1845. '<div class="am-datepicker-months">' +
  1846. '<table class="am-datepicker-table">' +
  1847. DPGlobal.headTemplate +
  1848. DPGlobal.contTemplate +
  1849. '</table>' +
  1850. '</div>' +
  1851. '<div class="am-datepicker-years">' +
  1852. '<table class="am-datepicker-table">' +
  1853. DPGlobal.headTemplate +
  1854. DPGlobal.contTemplate +
  1855. '</table>' +
  1856. '</div>' +
  1857. '</div>';
  1858. $.fn.datepicker = function(option, val) {
  1859. return this.each(function() {
  1860. var $this = $(this);
  1861. var data = $this.data('amui.datepicker');
  1862. var options = $.extend({},
  1863. UI.utils.options($this.data('amDatepicker')),
  1864. typeof option === 'object' && option);
  1865. if (!data) {
  1866. $this.data('amui.datepicker', (data = new Datepicker(this, options)));
  1867. }
  1868. if (typeof option === 'string') {
  1869. data[option] && data[option](val);
  1870. }
  1871. });
  1872. };
  1873. $.fn.datepicker.Constructor = Datepicker;
  1874. // Init code
  1875. UI.ready(function(context) {
  1876. $('[data-am-datepicker]').datepicker();
  1877. });
  1878. $.AMUI.datepicker = Datepicker;
  1879. module.exports = Datepicker;
  1880. // TODO: 1. 载入动画
  1881. // 2. less 优化
  1882. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1883. },{"2":2}],8:[function(_dereq_,module,exports){
  1884. (function (global){
  1885. 'use strict';
  1886. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  1887. var UI = _dereq_(2);
  1888. var $doc = $(document);
  1889. var transition = UI.support.transition;
  1890. var Dimmer = function() {
  1891. this.id = UI.utils.generateGUID('am-dimmer');
  1892. this.$element = $(Dimmer.DEFAULTS.tpl, {
  1893. id: this.id
  1894. });
  1895. this.inited = false;
  1896. this.scrollbarWidth = 0;
  1897. this.$used = $([]);
  1898. };
  1899. Dimmer.DEFAULTS = {
  1900. tpl: '<div class="am-dimmer" data-am-dimmer></div>'
  1901. };
  1902. Dimmer.prototype.init = function() {
  1903. if (!this.inited) {
  1904. $(document.body).append(this.$element);
  1905. this.inited = true;
  1906. $doc.trigger('init.dimmer.amui');
  1907. }
  1908. return this;
  1909. };
  1910. Dimmer.prototype.open = function(relatedElement) {
  1911. if (!this.inited) {
  1912. this.init();
  1913. }
  1914. var $element = this.$element;
  1915. // 用于多重调用
  1916. if (relatedElement) {
  1917. this.$used = this.$used.add($(relatedElement));
  1918. }
  1919. this.checkScrollbar().setScrollbar();
  1920. $element.off(transition.end).show().trigger('open.dimmer.amui');
  1921. setTimeout(function() {
  1922. $element.addClass('am-active');
  1923. }, 0);
  1924. return this;
  1925. };
  1926. Dimmer.prototype.close = function(relatedElement, force) {
  1927. this.$used = this.$used.not($(relatedElement));
  1928. if (!force && this.$used.length) {
  1929. return this;
  1930. }
  1931. var $element = this.$element;
  1932. $element.removeClass('am-active').trigger('close.dimmer.amui');
  1933. function complete() {
  1934. $element.hide();
  1935. this.resetScrollbar();
  1936. }
  1937. // transition ? $element.one(transition.end, $.proxy(complete, this)) :
  1938. complete.call(this);
  1939. return this;
  1940. };
  1941. Dimmer.prototype.checkScrollbar = function() {
  1942. this.scrollbarWidth = UI.utils.measureScrollbar();
  1943. return this;
  1944. };
  1945. Dimmer.prototype.setScrollbar = function() {
  1946. var $body = $(document.body);
  1947. var bodyPaddingRight = parseInt(($body.css('padding-right') || 0), 10);
  1948. if (this.scrollbarWidth) {
  1949. $body.css('padding-right', bodyPaddingRight + this.scrollbarWidth);
  1950. }
  1951. $body.addClass('am-dimmer-active');
  1952. return this;
  1953. };
  1954. Dimmer.prototype.resetScrollbar = function() {
  1955. $(document.body).css('padding-right', '').removeClass('am-dimmer-active');
  1956. return this;
  1957. };
  1958. var dimmer = new Dimmer();
  1959. $.AMUI.dimmer = dimmer;
  1960. module.exports = dimmer;
  1961. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  1962. },{"2":2}],9:[function(_dereq_,module,exports){
  1963. (function (global){
  1964. 'use strict';
  1965. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  1966. var UI = _dereq_(2);
  1967. var animation = UI.support.animation;
  1968. /**
  1969. * @via https://github.com/Minwe/bootstrap/blob/master/js/dropdown.js
  1970. * @copyright (c) 2011-2014 Twitter, Inc
  1971. * @license The MIT License
  1972. */
  1973. // var toggle = '[data-am-dropdown] > .am-dropdown-toggle';
  1974. var Dropdown = function(element, options) {
  1975. this.options = $.extend({}, Dropdown.DEFAULTS, options);
  1976. options = this.options;
  1977. this.$element = $(element);
  1978. this.$toggle = this.$element.find(options.selector.toggle);
  1979. this.$dropdown = this.$element.find(options.selector.dropdown);
  1980. this.$boundary = (options.boundary === window) ? $(window) :
  1981. this.$element.closest(options.boundary);
  1982. this.$justify = (options.justify && $(options.justify).length &&
  1983. $(options.justify)) || undefined;
  1984. !this.$boundary.length && (this.$boundary = $(window));
  1985. this.active = this.$element.hasClass('am-active') ? true : false;
  1986. this.animating = null;
  1987. this.events();
  1988. };
  1989. Dropdown.DEFAULTS = {
  1990. animation: 'am-animation-slide-top-fixed',
  1991. boundary: window,
  1992. justify: undefined,
  1993. selector: {
  1994. dropdown: '.am-dropdown-content',
  1995. toggle: '.am-dropdown-toggle'
  1996. },
  1997. trigger: 'click'
  1998. };
  1999. Dropdown.prototype.toggle = function() {
  2000. this.clear();
  2001. if (this.animating) {
  2002. return;
  2003. }
  2004. this[this.active ? 'close' : 'open']();
  2005. };
  2006. Dropdown.prototype.open = function(e) {
  2007. var $toggle = this.$toggle;
  2008. var $element = this.$element;
  2009. var $dropdown = this.$dropdown;
  2010. if ($toggle.is('.am-disabled, :disabled')) {
  2011. return;
  2012. }
  2013. if (this.active) {
  2014. return;
  2015. }
  2016. $element.trigger('open.dropdown.amui').addClass('am-active');
  2017. $toggle.trigger('focus');
  2018. this.checkDimensions();
  2019. var complete = $.proxy(function() {
  2020. $element.trigger('opened.dropdown.amui');
  2021. this.active = true;
  2022. this.animating = 0;
  2023. }, this);
  2024. if (animation) {
  2025. this.animating = 1;
  2026. $dropdown.addClass(this.options.animation).
  2027. on(animation.end + '.open.dropdown.amui', $.proxy(function() {
  2028. complete();
  2029. $dropdown.removeClass(this.options.animation);
  2030. }, this));
  2031. } else {
  2032. complete();
  2033. }
  2034. };
  2035. Dropdown.prototype.close = function() {
  2036. if (!this.active) {
  2037. return;
  2038. }
  2039. // fix #165
  2040. // var animationName = this.options.animation + ' am-animation-reverse';
  2041. var animationName = 'am-dropdown-animation';
  2042. var $element = this.$element;
  2043. var $dropdown = this.$dropdown;
  2044. $element.trigger('close.dropdown.amui');
  2045. var complete = $.proxy(function complete() {
  2046. $element.
  2047. removeClass('am-active').
  2048. trigger('closed.dropdown.amui');
  2049. this.active = false;
  2050. this.animating = 0;
  2051. this.$toggle.blur();
  2052. }, this);
  2053. if (animation) {
  2054. $dropdown.removeClass(this.options.animation);
  2055. $dropdown.addClass(animationName);
  2056. this.animating = 1;
  2057. // animation
  2058. $dropdown.one(animation.end + '.close.dropdown.amui', function() {
  2059. $dropdown.removeClass(animationName);
  2060. complete();
  2061. });
  2062. } else {
  2063. complete();
  2064. }
  2065. };
  2066. Dropdown.prototype.checkDimensions = function() {
  2067. if (!this.$dropdown.length) {
  2068. return;
  2069. }
  2070. var $dropdown = this.$dropdown;
  2071. var offset = $dropdown.offset();
  2072. var width = $dropdown.outerWidth();
  2073. var boundaryWidth = this.$boundary.width();
  2074. var boundaryOffset = $.isWindow(this.boundary) && this.$boundary.offset() ?
  2075. this.$boundary.offset().left : 0;
  2076. if (this.$justify) {
  2077. // jQuery.fn.width() is really...
  2078. $dropdown.css({'min-width': this.$justify.css('width')});
  2079. }
  2080. if ((width + (offset.left - boundaryOffset)) > boundaryWidth) {
  2081. this.$element.addClass('am-dropdown-flip');
  2082. }
  2083. };
  2084. Dropdown.prototype.clear = function() {
  2085. $('[data-am-dropdown]').not(this.$element).each(function() {
  2086. var data = $(this).data('amui.dropdown');
  2087. data && data.close();
  2088. });
  2089. };
  2090. Dropdown.prototype.events = function() {
  2091. var eventNS = 'dropdown.amui';
  2092. // triggers = this.options.trigger.split(' '),
  2093. var $toggle = this.$toggle;
  2094. $toggle.on('click.' + eventNS, $.proxy(function(e) {
  2095. e.preventDefault();
  2096. this.toggle();
  2097. }, this));
  2098. /*for (var i = triggers.length; i--;) {
  2099. var trigger = triggers[i];
  2100. if (trigger === 'click') {
  2101. $toggle.on('click.' + eventNS, $.proxy(this.toggle, this))
  2102. }
  2103. if (trigger === 'focus' || trigger === 'hover') {
  2104. var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
  2105. var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
  2106. this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this))
  2107. .on(eventOut + '.' + eventNS, $.proxy(this.close, this));
  2108. }
  2109. }*/
  2110. $(document).on('keydown.dropdown.amui', $.proxy(function(e) {
  2111. e.keyCode === 27 && this.active && this.close();
  2112. }, this)).on('click.outer.dropdown.amui', $.proxy(function(e) {
  2113. // var $target = $(e.target);
  2114. if (this.active &&
  2115. (this.$element[0] === e.target || !this.$element.find(e.target).length)) {
  2116. this.close();
  2117. }
  2118. }, this));
  2119. };
  2120. // Dropdown Plugin
  2121. function Plugin(option) {
  2122. return this.each(function() {
  2123. var $this = $(this);
  2124. var data = $this.data('amui.dropdown');
  2125. var options = $.extend({},
  2126. UI.utils.parseOptions($this.attr('data-am-dropdown')),
  2127. typeof option == 'object' && option);
  2128. if (!data) {
  2129. $this.data('amui.dropdown', (data = new Dropdown(this, options)));
  2130. }
  2131. if (typeof option == 'string') {
  2132. data[option]();
  2133. }
  2134. });
  2135. }
  2136. $.fn.dropdown = Plugin;
  2137. // Init code
  2138. UI.ready(function(context) {
  2139. $('[data-am-dropdown]', context).dropdown();
  2140. });
  2141. $(document).on('click.dropdown.amui.data-api', '.am-dropdown form',
  2142. function(e) {
  2143. e.stopPropagation();
  2144. });
  2145. $.AMUI.dropdown = Dropdown;
  2146. module.exports = Dropdown;
  2147. // TODO: 1. 处理链接 focus
  2148. // 2. 增加 mouseenter / mouseleave 选项
  2149. // 3. 宽度适应
  2150. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  2151. },{"2":2}],10:[function(_dereq_,module,exports){
  2152. (function (global){
  2153. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  2154. var UI = _dereq_(2);
  2155. // MODIFIED:
  2156. // - LINE 226: add `<i></i>`
  2157. // - namespace
  2158. // - Init code
  2159. // TODO: start after x ms when pause on actions
  2160. /*
  2161. * jQuery FlexSlider v2.4.0
  2162. * Copyright 2012 WooThemes
  2163. * Contributing Author: Tyler Smith
  2164. */
  2165. // FlexSlider: Object Instance
  2166. $.flexslider = function(el, options) {
  2167. var slider = $(el);
  2168. // making variables public
  2169. slider.vars = $.extend({}, $.flexslider.defaults, options);
  2170. var namespace = slider.vars.namespace,
  2171. msGesture = window.navigator && window.navigator.msPointerEnabled && window.MSGesture,
  2172. touch = (( "ontouchstart" in window ) || msGesture || window.DocumentTouch && document instanceof DocumentTouch) && slider.vars.touch,
  2173. // depricating this idea, as devices are being released with both of these events
  2174. //eventType = (touch) ? "touchend" : "click",
  2175. eventType = "click touchend MSPointerUp keyup",
  2176. watchedEvent = "",
  2177. watchedEventClearTimer,
  2178. vertical = slider.vars.direction === "vertical",
  2179. reverse = slider.vars.reverse,
  2180. carousel = (slider.vars.itemWidth > 0),
  2181. fade = slider.vars.animation === "fade",
  2182. asNav = slider.vars.asNavFor !== "",
  2183. methods = {},
  2184. focused = true;
  2185. // Store a reference to the slider object
  2186. $.data(el, 'flexslider', slider);
  2187. // Private slider methods
  2188. methods = {
  2189. init: function() {
  2190. slider.animating = false;
  2191. // Get current slide and make sure it is a number
  2192. slider.currentSlide = parseInt((slider.vars.startAt ? slider.vars.startAt : 0), 10);
  2193. if (isNaN(slider.currentSlide)) {
  2194. slider.currentSlide = 0;
  2195. }
  2196. slider.animatingTo = slider.currentSlide;
  2197. slider.atEnd = (slider.currentSlide === 0 || slider.currentSlide === slider.last);
  2198. slider.containerSelector = slider.vars.selector.substr(0, slider.vars.selector.search(' '));
  2199. slider.slides = $(slider.vars.selector, slider);
  2200. slider.container = $(slider.containerSelector, slider);
  2201. slider.count = slider.slides.length;
  2202. // SYNC:
  2203. slider.syncExists = $(slider.vars.sync).length > 0;
  2204. // SLIDE:
  2205. if (slider.vars.animation === "slide") {
  2206. slider.vars.animation = "swing";
  2207. }
  2208. slider.prop = (vertical) ? "top" : "marginLeft";
  2209. slider.args = {};
  2210. // SLIDESHOW:
  2211. slider.manualPause = false;
  2212. slider.stopped = false;
  2213. //PAUSE WHEN INVISIBLE
  2214. slider.started = false;
  2215. slider.startTimeout = null;
  2216. // TOUCH/USECSS:
  2217. slider.transitions = !slider.vars.video && !fade && slider.vars.useCSS && (function() {
  2218. var obj = document.createElement('div'),
  2219. props = ['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective'];
  2220. for (var i in props) {
  2221. if (obj.style[props[i]] !== undefined) {
  2222. slider.pfx = props[i].replace('Perspective', '').toLowerCase();
  2223. slider.prop = "-" + slider.pfx + "-transform";
  2224. return true;
  2225. }
  2226. }
  2227. return false;
  2228. }());
  2229. slider.ensureAnimationEnd = '';
  2230. // CONTROLSCONTAINER:
  2231. if (slider.vars.controlsContainer !== "") slider.controlsContainer = $(slider.vars.controlsContainer).length > 0 && $(slider.vars.controlsContainer);
  2232. // MANUAL:
  2233. if (slider.vars.manualControls !== "") slider.manualControls = $(slider.vars.manualControls).length > 0 && $(slider.vars.manualControls);
  2234. // RANDOMIZE:
  2235. if (slider.vars.randomize) {
  2236. slider.slides.sort(function() {
  2237. return (Math.round(Math.random()) - 0.5);
  2238. });
  2239. slider.container.empty().append(slider.slides);
  2240. }
  2241. slider.doMath();
  2242. // INIT
  2243. slider.setup("init");
  2244. // CONTROLNAV:
  2245. if (slider.vars.controlNav) {
  2246. methods.controlNav.setup();
  2247. }
  2248. // DIRECTIONNAV:
  2249. if (slider.vars.directionNav) {
  2250. methods.directionNav.setup();
  2251. }
  2252. // KEYBOARD:
  2253. if (slider.vars.keyboard && ($(slider.containerSelector).length === 1 || slider.vars.multipleKeyboard)) {
  2254. $(document).bind('keyup', function(event) {
  2255. var keycode = event.keyCode;
  2256. if (!slider.animating && (keycode === 39 || keycode === 37)) {
  2257. var target = (keycode === 39) ? slider.getTarget('next') :
  2258. (keycode === 37) ? slider.getTarget('prev') : false;
  2259. slider.flexAnimate(target, slider.vars.pauseOnAction);
  2260. }
  2261. });
  2262. }
  2263. // MOUSEWHEEL:
  2264. if (slider.vars.mousewheel) {
  2265. slider.bind('mousewheel', function(event, delta, deltaX, deltaY) {
  2266. event.preventDefault();
  2267. var target = (delta < 0) ? slider.getTarget('next') : slider.getTarget('prev');
  2268. slider.flexAnimate(target, slider.vars.pauseOnAction);
  2269. });
  2270. }
  2271. // PAUSEPLAY
  2272. if (slider.vars.pausePlay) {
  2273. methods.pausePlay.setup();
  2274. }
  2275. //PAUSE WHEN INVISIBLE
  2276. if (slider.vars.slideshow && slider.vars.pauseInvisible) {
  2277. methods.pauseInvisible.init();
  2278. }
  2279. // SLIDSESHOW
  2280. if (slider.vars.slideshow) {
  2281. if (slider.vars.pauseOnHover) {
  2282. slider.hover(function() {
  2283. if (!slider.manualPlay && !slider.manualPause) {slider.pause();}
  2284. }, function() {
  2285. if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {slider.play();}
  2286. });
  2287. }
  2288. // initialize animation
  2289. // If we're visible, or we don't use PageVisibility API
  2290. if (!slider.vars.pauseInvisible || !methods.pauseInvisible.isHidden()) {
  2291. (slider.vars.initDelay > 0) ? slider.startTimeout = setTimeout(slider.play, slider.vars.initDelay) : slider.play();
  2292. }
  2293. }
  2294. // ASNAV:
  2295. if (asNav) {methods.asNav.setup();}
  2296. // TOUCH
  2297. if (touch && slider.vars.touch) {methods.touch();}
  2298. // FADE&&SMOOTHHEIGHT || SLIDE:
  2299. if (!fade || (fade && slider.vars.smoothHeight)) {$(window).bind("resize orientationchange focus", methods.resize);}
  2300. slider.find("img").attr("draggable", "false");
  2301. // API: start() Callback
  2302. setTimeout(function() {
  2303. slider.vars.start(slider);
  2304. }, 200);
  2305. },
  2306. asNav: {
  2307. setup: function() {
  2308. slider.asNav = true;
  2309. slider.animatingTo = Math.floor(slider.currentSlide / slider.move);
  2310. slider.currentItem = slider.currentSlide;
  2311. slider.slides.removeClass(namespace + "active-slide").eq(slider.currentItem).addClass(namespace + "active-slide");
  2312. if (!msGesture) {
  2313. slider.slides.on(eventType, function(e) {
  2314. e.preventDefault();
  2315. var $slide = $(this),
  2316. target = $slide.index();
  2317. var posFromLeft = $slide.offset().left - $(slider).scrollLeft(); // Find position of slide relative to left of slider container
  2318. if (posFromLeft <= 0 && $slide.hasClass(namespace + 'active-slide')) {
  2319. slider.flexAnimate(slider.getTarget("prev"), true);
  2320. } else if (!$(slider.vars.asNavFor).data('flexslider').animating && !$slide.hasClass(namespace + "active-slide")) {
  2321. slider.direction = (slider.currentItem < target) ? "next" : "prev";
  2322. slider.flexAnimate(target, slider.vars.pauseOnAction, false, true, true);
  2323. }
  2324. });
  2325. } else {
  2326. el._slider = slider;
  2327. slider.slides.each(function() {
  2328. var that = this;
  2329. that._gesture = new MSGesture();
  2330. that._gesture.target = that;
  2331. that.addEventListener("MSPointerDown", function(e) {
  2332. e.preventDefault();
  2333. if (e.currentTarget._gesture) {
  2334. e.currentTarget._gesture.addPointer(e.pointerId);
  2335. }
  2336. }, false);
  2337. that.addEventListener("MSGestureTap", function(e) {
  2338. e.preventDefault();
  2339. var $slide = $(this),
  2340. target = $slide.index();
  2341. if (!$(slider.vars.asNavFor).data('flexslider').animating && !$slide.hasClass('active')) {
  2342. slider.direction = (slider.currentItem < target) ? "next" : "prev";
  2343. slider.flexAnimate(target, slider.vars.pauseOnAction, false, true, true);
  2344. }
  2345. });
  2346. });
  2347. }
  2348. }
  2349. },
  2350. controlNav: {
  2351. setup: function() {
  2352. if (!slider.manualControls) {
  2353. methods.controlNav.setupPaging();
  2354. } else { // MANUALCONTROLS:
  2355. methods.controlNav.setupManual();
  2356. }
  2357. },
  2358. setupPaging: function() {
  2359. var type = (slider.vars.controlNav === "thumbnails") ? 'control-thumbs' : 'control-paging',
  2360. j = 1,
  2361. item,
  2362. slide;
  2363. slider.controlNavScaffold = $('<ol class="' + namespace + 'control-nav ' + namespace + type + '"></ol>');
  2364. if (slider.pagingCount > 1) {
  2365. for (var i = 0; i < slider.pagingCount; i++) {
  2366. slide = slider.slides.eq(i);
  2367. item = (slider.vars.controlNav === "thumbnails") ? '<img src="' + slide.attr('data-thumb') + '"/>' : '<a>' + j + '</a>';
  2368. if ('thumbnails' === slider.vars.controlNav && true === slider.vars.thumbCaptions) {
  2369. var captn = slide.attr('data-thumbcaption');
  2370. if ('' != captn && undefined != captn) {item += '<span class="' + namespace + 'caption">' + captn + '</span>'};
  2371. }
  2372. // slider.controlNavScaffold.append('<li>' + item + '</li>');
  2373. slider.controlNavScaffold.append('<li>' + item + '<i></i></li>');
  2374. j++;
  2375. }
  2376. }
  2377. // CONTROLSCONTAINER:
  2378. (slider.controlsContainer) ? $(slider.controlsContainer).append(slider.controlNavScaffold) : slider.append(slider.controlNavScaffold);
  2379. methods.controlNav.set();
  2380. methods.controlNav.active();
  2381. slider.controlNavScaffold.delegate('a, img', eventType, function(event) {
  2382. event.preventDefault();
  2383. if (watchedEvent === "" || watchedEvent === event.type) {
  2384. var $this = $(this),
  2385. target = slider.controlNav.index($this);
  2386. if (!$this.hasClass(namespace + 'active')) {
  2387. slider.direction = (target > slider.currentSlide) ? "next" : "prev";
  2388. slider.flexAnimate(target, slider.vars.pauseOnAction);
  2389. }
  2390. }
  2391. // setup flags to prevent event duplication
  2392. if (watchedEvent === "") {
  2393. watchedEvent = event.type;
  2394. }
  2395. methods.setToClearWatchedEvent();
  2396. });
  2397. },
  2398. setupManual: function() {
  2399. slider.controlNav = slider.manualControls;
  2400. methods.controlNav.active();
  2401. slider.controlNav.bind(eventType, function(event) {
  2402. event.preventDefault();
  2403. if (watchedEvent === "" || watchedEvent === event.type) {
  2404. var $this = $(this),
  2405. target = slider.controlNav.index($this);
  2406. if (!$this.hasClass(namespace + 'active')) {
  2407. (target > slider.currentSlide) ? slider.direction = "next" : slider.direction = "prev";
  2408. slider.flexAnimate(target, slider.vars.pauseOnAction);
  2409. }
  2410. }
  2411. // setup flags to prevent event duplication
  2412. if (watchedEvent === "") {
  2413. watchedEvent = event.type;
  2414. }
  2415. methods.setToClearWatchedEvent();
  2416. });
  2417. },
  2418. set: function() {
  2419. var selector = (slider.vars.controlNav === "thumbnails") ? 'img' : 'a';
  2420. slider.controlNav = $('.' + namespace + 'control-nav li ' + selector, (slider.controlsContainer) ? slider.controlsContainer : slider);
  2421. },
  2422. active: function() {
  2423. slider.controlNav.removeClass(namespace + "active").eq(slider.animatingTo).addClass(namespace + "active");
  2424. },
  2425. update: function(action, pos) {
  2426. if (slider.pagingCount > 1 && action === "add") {
  2427. slider.controlNavScaffold.append($('<li><a>' + slider.count + '</a></li>'));
  2428. } else if (slider.pagingCount === 1) {
  2429. slider.controlNavScaffold.find('li').remove();
  2430. } else {
  2431. slider.controlNav.eq(pos).closest('li').remove();
  2432. }
  2433. methods.controlNav.set();
  2434. (slider.pagingCount > 1 && slider.pagingCount !== slider.controlNav.length) ? slider.update(pos, action) : methods.controlNav.active();
  2435. }
  2436. },
  2437. directionNav: {
  2438. setup: function() {
  2439. 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>');
  2440. // CONTROLSCONTAINER:
  2441. if (slider.controlsContainer) {
  2442. $(slider.controlsContainer).append(directionNavScaffold);
  2443. slider.directionNav = $('.' + namespace + 'direction-nav li a', slider.controlsContainer);
  2444. } else {
  2445. slider.append(directionNavScaffold);
  2446. slider.directionNav = $('.' + namespace + 'direction-nav li a', slider);
  2447. }
  2448. methods.directionNav.update();
  2449. slider.directionNav.bind(eventType, function(event) {
  2450. event.preventDefault();
  2451. var target;
  2452. if (watchedEvent === "" || watchedEvent === event.type) {
  2453. target = ($(this).hasClass(namespace + 'next')) ? slider.getTarget('next') : slider.getTarget('prev');
  2454. slider.flexAnimate(target, slider.vars.pauseOnAction);
  2455. }
  2456. // setup flags to prevent event duplication
  2457. if (watchedEvent === "") {
  2458. watchedEvent = event.type;
  2459. }
  2460. methods.setToClearWatchedEvent();
  2461. });
  2462. },
  2463. update: function() {
  2464. var disabledClass = namespace + 'disabled';
  2465. if (slider.pagingCount === 1) {
  2466. slider.directionNav.addClass(disabledClass).attr('tabindex', '-1');
  2467. } else if (!slider.vars.animationLoop) {
  2468. if (slider.animatingTo === 0) {
  2469. slider.directionNav.removeClass(disabledClass).filter('.' + namespace + "prev").addClass(disabledClass).attr('tabindex', '-1');
  2470. } else if (slider.animatingTo === slider.last) {
  2471. slider.directionNav.removeClass(disabledClass).filter('.' + namespace + "next").addClass(disabledClass).attr('tabindex', '-1');
  2472. } else {
  2473. slider.directionNav.removeClass(disabledClass).removeAttr('tabindex');
  2474. }
  2475. } else {
  2476. slider.directionNav.removeClass(disabledClass).removeAttr('tabindex');
  2477. }
  2478. }
  2479. },
  2480. pausePlay: {
  2481. setup: function() {
  2482. var pausePlayScaffold = $('<div class="' + namespace + 'pauseplay"><a></a></div>');
  2483. // CONTROLSCONTAINER:
  2484. if (slider.controlsContainer) {
  2485. slider.controlsContainer.append(pausePlayScaffold);
  2486. slider.pausePlay = $('.' + namespace + 'pauseplay a', slider.controlsContainer);
  2487. } else {
  2488. slider.append(pausePlayScaffold);
  2489. slider.pausePlay = $('.' + namespace + 'pauseplay a', slider);
  2490. }
  2491. methods.pausePlay.update((slider.vars.slideshow) ? namespace + 'pause' : namespace + 'play');
  2492. slider.pausePlay.bind(eventType, function(event) {
  2493. event.preventDefault();
  2494. if (watchedEvent === "" || watchedEvent === event.type) {
  2495. if ($(this).hasClass(namespace + 'pause')) {
  2496. slider.manualPause = true;
  2497. slider.manualPlay = false;
  2498. slider.pause();
  2499. } else {
  2500. slider.manualPause = false;
  2501. slider.manualPlay = true;
  2502. slider.play();
  2503. }
  2504. }
  2505. // setup flags to prevent event duplication
  2506. if (watchedEvent === "") {
  2507. watchedEvent = event.type;
  2508. }
  2509. methods.setToClearWatchedEvent();
  2510. });
  2511. },
  2512. update: function(state) {
  2513. (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);
  2514. }
  2515. },
  2516. touch: function() {
  2517. var startX,
  2518. startY,
  2519. offset,
  2520. cwidth,
  2521. dx,
  2522. startT,
  2523. scrolling = false,
  2524. localX = 0,
  2525. localY = 0,
  2526. accDx = 0;
  2527. if (!msGesture) {
  2528. el.addEventListener('touchstart', onTouchStart, false);
  2529. function onTouchStart(e) {
  2530. if (slider.animating) {
  2531. e.preventDefault();
  2532. } else if (( window.navigator.msPointerEnabled ) || e.touches.length === 1) {
  2533. slider.pause();
  2534. // CAROUSEL:
  2535. cwidth = (vertical) ? slider.h : slider.w;
  2536. startT = Number(new Date());
  2537. // CAROUSEL:
  2538. // Local vars for X and Y points.
  2539. localX = e.touches[0].pageX;
  2540. localY = e.touches[0].pageY;
  2541. offset = (carousel && reverse && slider.animatingTo === slider.last) ? 0 :
  2542. (carousel && reverse) ? slider.limit - (((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo) :
  2543. (carousel && slider.currentSlide === slider.last) ? slider.limit :
  2544. (carousel) ? ((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.currentSlide :
  2545. (reverse) ? (slider.last - slider.currentSlide + slider.cloneOffset) * cwidth : (slider.currentSlide + slider.cloneOffset) * cwidth;
  2546. startX = (vertical) ? localY : localX;
  2547. startY = (vertical) ? localX : localY;
  2548. el.addEventListener('touchmove', onTouchMove, false);
  2549. el.addEventListener('touchend', onTouchEnd, false);
  2550. }
  2551. }
  2552. function onTouchMove(e) {
  2553. // Local vars for X and Y points.
  2554. localX = e.touches[0].pageX;
  2555. localY = e.touches[0].pageY;
  2556. dx = (vertical) ? startX - localY : startX - localX;
  2557. scrolling = (vertical) ? (Math.abs(dx) < Math.abs(localX - startY)) : (Math.abs(dx) < Math.abs(localY - startY));
  2558. var fxms = 500;
  2559. if (!scrolling || Number(new Date()) - startT > fxms) {
  2560. e.preventDefault();
  2561. if (!fade && slider.transitions) {
  2562. if (!slider.vars.animationLoop) {
  2563. dx = dx / ((slider.currentSlide === 0 && dx < 0 || slider.currentSlide === slider.last && dx > 0) ? (Math.abs(dx) / cwidth + 2) : 1);
  2564. }
  2565. slider.setProps(offset + dx, "setTouch");
  2566. }
  2567. }
  2568. }
  2569. function onTouchEnd(e) {
  2570. // finish the touch by undoing the touch session
  2571. el.removeEventListener('touchmove', onTouchMove, false);
  2572. if (slider.animatingTo === slider.currentSlide && !scrolling && !(dx === null)) {
  2573. var updateDx = (reverse) ? -dx : dx,
  2574. target = (updateDx > 0) ? slider.getTarget('next') : slider.getTarget('prev');
  2575. if (slider.canAdvance(target) && (Number(new Date()) - startT < 550 && Math.abs(updateDx) > 50 || Math.abs(updateDx) > cwidth / 2)) {
  2576. slider.flexAnimate(target, slider.vars.pauseOnAction);
  2577. } else {
  2578. if (!fade) {slider.flexAnimate(slider.currentSlide, slider.vars.pauseOnAction, true);}
  2579. }
  2580. }
  2581. el.removeEventListener('touchend', onTouchEnd, false);
  2582. startX = null;
  2583. startY = null;
  2584. dx = null;
  2585. offset = null;
  2586. }
  2587. } else {
  2588. el.style.msTouchAction = "none";
  2589. el._gesture = new MSGesture();
  2590. el._gesture.target = el;
  2591. el.addEventListener("MSPointerDown", onMSPointerDown, false);
  2592. el._slider = slider;
  2593. el.addEventListener("MSGestureChange", onMSGestureChange, false);
  2594. el.addEventListener("MSGestureEnd", onMSGestureEnd, false);
  2595. function onMSPointerDown(e) {
  2596. e.stopPropagation();
  2597. if (slider.animating) {
  2598. e.preventDefault();
  2599. } else {
  2600. slider.pause();
  2601. el._gesture.addPointer(e.pointerId);
  2602. accDx = 0;
  2603. cwidth = (vertical) ? slider.h : slider.w;
  2604. startT = Number(new Date());
  2605. // CAROUSEL:
  2606. offset = (carousel && reverse && slider.animatingTo === slider.last) ? 0 :
  2607. (carousel && reverse) ? slider.limit - (((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo) :
  2608. (carousel && slider.currentSlide === slider.last) ? slider.limit :
  2609. (carousel) ? ((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.currentSlide :
  2610. (reverse) ? (slider.last - slider.currentSlide + slider.cloneOffset) * cwidth : (slider.currentSlide + slider.cloneOffset) * cwidth;
  2611. }
  2612. }
  2613. function onMSGestureChange(e) {
  2614. e.stopPropagation();
  2615. var slider = e.target._slider;
  2616. if (!slider) {
  2617. return;
  2618. }
  2619. var transX = -e.translationX,
  2620. transY = -e.translationY;
  2621. //Accumulate translations.
  2622. accDx = accDx + ((vertical) ? transY : transX);
  2623. dx = accDx;
  2624. scrolling = (vertical) ? (Math.abs(accDx) < Math.abs(-transX)) : (Math.abs(accDx) < Math.abs(-transY));
  2625. if (e.detail === e.MSGESTURE_FLAG_INERTIA) {
  2626. setImmediate(function() {
  2627. el._gesture.stop();
  2628. });
  2629. return;
  2630. }
  2631. if (!scrolling || Number(new Date()) - startT > 500) {
  2632. e.preventDefault();
  2633. if (!fade && slider.transitions) {
  2634. if (!slider.vars.animationLoop) {
  2635. dx = accDx / ((slider.currentSlide === 0 && accDx < 0 || slider.currentSlide === slider.last && accDx > 0) ? (Math.abs(accDx) / cwidth + 2) : 1);
  2636. }
  2637. slider.setProps(offset + dx, "setTouch");
  2638. }
  2639. }
  2640. }
  2641. function onMSGestureEnd(e) {
  2642. e.stopPropagation();
  2643. var slider = e.target._slider;
  2644. if (!slider) {
  2645. return;
  2646. }
  2647. if (slider.animatingTo === slider.currentSlide && !scrolling && !(dx === null)) {
  2648. var updateDx = (reverse) ? -dx : dx,
  2649. target = (updateDx > 0) ? slider.getTarget('next') : slider.getTarget('prev');
  2650. if (slider.canAdvance(target) && (Number(new Date()) - startT < 550 && Math.abs(updateDx) > 50 || Math.abs(updateDx) > cwidth / 2)) {
  2651. slider.flexAnimate(target, slider.vars.pauseOnAction);
  2652. } else {
  2653. if (!fade) {slider.flexAnimate(slider.currentSlide, slider.vars.pauseOnAction, true);}
  2654. }
  2655. }
  2656. startX = null;
  2657. startY = null;
  2658. dx = null;
  2659. offset = null;
  2660. accDx = 0;
  2661. }
  2662. }
  2663. },
  2664. resize: function() {
  2665. if (!slider.animating && slider.is(':visible')) {
  2666. if (!carousel) {slider.doMath()};
  2667. if (fade) {
  2668. // SMOOTH HEIGHT:
  2669. methods.smoothHeight();
  2670. } else if (carousel) { //CAROUSEL:
  2671. slider.slides.width(slider.computedW);
  2672. slider.update(slider.pagingCount);
  2673. slider.setProps();
  2674. }
  2675. else if (vertical) { //VERTICAL:
  2676. slider.viewport.height(slider.h);
  2677. slider.setProps(slider.h, "setTotal");
  2678. } else {
  2679. // SMOOTH HEIGHT:
  2680. if (slider.vars.smoothHeight) {methods.smoothHeight();}
  2681. slider.newSlides.width(slider.computedW);
  2682. slider.setProps(slider.computedW, "setTotal");
  2683. }
  2684. }
  2685. },
  2686. smoothHeight: function(dur) {
  2687. if (!vertical || fade) {
  2688. var $obj = (fade) ? slider : slider.viewport;
  2689. (dur) ? $obj.animate({"height": slider.slides.eq(slider.animatingTo).height()}, dur) : $obj.height(slider.slides.eq(slider.animatingTo).height());
  2690. }
  2691. },
  2692. sync: function(action) {
  2693. var $obj = $(slider.vars.sync).data("flexslider"),
  2694. target = slider.animatingTo;
  2695. switch (action) {
  2696. case "animate":
  2697. $obj.flexAnimate(target, slider.vars.pauseOnAction, false, true);
  2698. break;
  2699. case "play":
  2700. if (!$obj.playing && !$obj.asNav) {
  2701. $obj.play();
  2702. }
  2703. break;
  2704. case "pause":
  2705. $obj.pause();
  2706. break;
  2707. }
  2708. },
  2709. uniqueID: function($clone) {
  2710. // Append _clone to current level and children elements with id attributes
  2711. $clone.filter('[id]').add($clone.find('[id]')).each(function() {
  2712. var $this = $(this);
  2713. $this.attr('id', $this.attr('id') + '_clone');
  2714. });
  2715. return $clone;
  2716. },
  2717. pauseInvisible: {
  2718. visProp: null,
  2719. init: function() {
  2720. var visProp = methods.pauseInvisible.getHiddenProp();
  2721. if (visProp) {
  2722. var evtname = visProp.replace(/[H|h]idden/,'') + 'visibilitychange';
  2723. document.addEventListener(evtname, function() {
  2724. if (methods.pauseInvisible.isHidden()) {
  2725. if(slider.startTimeout) {
  2726. clearTimeout(slider.startTimeout); //If clock is ticking, stop timer and prevent from starting while invisible
  2727. } else {
  2728. slider.pause(); //Or just pause
  2729. }
  2730. }
  2731. else {
  2732. if(slider.started) {
  2733. slider.play(); //Initiated before, just play
  2734. } else {
  2735. if (slider.vars.initDelay > 0) {
  2736. setTimeout(slider.play, slider.vars.initDelay);
  2737. } else {
  2738. slider.play(); //Didn't init before: simply init or wait for it
  2739. }
  2740. }
  2741. }
  2742. });
  2743. }
  2744. },
  2745. isHidden: function() {
  2746. var prop = methods.pauseInvisible.getHiddenProp();
  2747. if (!prop) {
  2748. return false;
  2749. }
  2750. return document[prop];
  2751. },
  2752. getHiddenProp: function() {
  2753. var prefixes = ['webkit','moz','ms','o'];
  2754. // if 'hidden' is natively supported just return it
  2755. if ('hidden' in document) {
  2756. return 'hidden';
  2757. }
  2758. // otherwise loop over all the known prefixes until we find one
  2759. for (var i = 0; i < prefixes.length; i++ ) {
  2760. if ((prefixes[i] + 'Hidden') in document) {
  2761. return prefixes[i] + 'Hidden';
  2762. }
  2763. }
  2764. // otherwise it's not supported
  2765. return null;
  2766. }
  2767. },
  2768. setToClearWatchedEvent: function() {
  2769. clearTimeout(watchedEventClearTimer);
  2770. watchedEventClearTimer = setTimeout(function() {
  2771. watchedEvent = "";
  2772. }, 3000);
  2773. }
  2774. };
  2775. // public methods
  2776. slider.flexAnimate = function(target, pause, override, withSync, fromNav) {
  2777. if (!slider.vars.animationLoop && target !== slider.currentSlide) {
  2778. slider.direction = (target > slider.currentSlide) ? "next" : "prev";
  2779. }
  2780. if (asNav && slider.pagingCount === 1) slider.direction = (slider.currentItem < target) ? "next" : "prev";
  2781. if (!slider.animating && (slider.canAdvance(target, fromNav) || override) && slider.is(":visible")) {
  2782. if (asNav && withSync) {
  2783. var master = $(slider.vars.asNavFor).data('flexslider');
  2784. slider.atEnd = target === 0 || target === slider.count - 1;
  2785. master.flexAnimate(target, true, false, true, fromNav);
  2786. slider.direction = (slider.currentItem < target) ? "next" : "prev";
  2787. master.direction = slider.direction;
  2788. if (Math.ceil((target + 1) / slider.visible) - 1 !== slider.currentSlide && target !== 0) {
  2789. slider.currentItem = target;
  2790. slider.slides.removeClass(namespace + "active-slide").eq(target).addClass(namespace + "active-slide");
  2791. target = Math.floor(target / slider.visible);
  2792. } else {
  2793. slider.currentItem = target;
  2794. slider.slides.removeClass(namespace + "active-slide").eq(target).addClass(namespace + "active-slide");
  2795. return false;
  2796. }
  2797. }
  2798. slider.animating = true;
  2799. slider.animatingTo = target;
  2800. // SLIDESHOW:
  2801. if (pause) {slider.pause();}
  2802. // API: before() animation Callback
  2803. slider.vars.before(slider);
  2804. // SYNC:
  2805. if (slider.syncExists && !fromNav) {methods.sync("animate");}
  2806. // CONTROLNAV
  2807. if (slider.vars.controlNav) {methods.controlNav.active();}
  2808. // !CAROUSEL:
  2809. // CANDIDATE: slide active class (for add/remove slide)
  2810. if (!carousel) {slider.slides.removeClass(namespace + 'active-slide').eq(target).addClass(namespace + 'active-slide');}
  2811. // INFINITE LOOP:
  2812. // CANDIDATE: atEnd
  2813. slider.atEnd = target === 0 || target === slider.last;
  2814. // DIRECTIONNAV:
  2815. if (slider.vars.directionNav) {methods.directionNav.update();}
  2816. if (target === slider.last) {
  2817. // API: end() of cycle Callback
  2818. slider.vars.end(slider);
  2819. // SLIDESHOW && !INFINITE LOOP:
  2820. if (!slider.vars.animationLoop) {slider.pause();}
  2821. }
  2822. // SLIDE:
  2823. if (!fade) {
  2824. var dimension = (vertical) ? slider.slides.filter(':first').height() : slider.computedW,
  2825. margin, slideString, calcNext;
  2826. // INFINITE LOOP / REVERSE:
  2827. if (carousel) {
  2828. //margin = (slider.vars.itemWidth > slider.w) ? slider.vars.itemMargin * 2 : slider.vars.itemMargin;
  2829. margin = slider.vars.itemMargin;
  2830. calcNext = ((slider.itemW + margin) * slider.move) * slider.animatingTo;
  2831. slideString = (calcNext > slider.limit && slider.visible !== 1) ? slider.limit : calcNext;
  2832. } else if (slider.currentSlide === 0 && target === slider.count - 1 && slider.vars.animationLoop && slider.direction !== "next") {
  2833. slideString = (reverse) ? (slider.count + slider.cloneOffset) * dimension : 0;
  2834. } else if (slider.currentSlide === slider.last && target === 0 && slider.vars.animationLoop && slider.direction !== "prev") {
  2835. slideString = (reverse) ? 0 : (slider.count + 1) * dimension;
  2836. } else {
  2837. slideString = (reverse) ? ((slider.count - 1) - target + slider.cloneOffset) * dimension : (target + slider.cloneOffset) * dimension;
  2838. }
  2839. slider.setProps(slideString, "", slider.vars.animationSpeed);
  2840. if (slider.transitions) {
  2841. if (!slider.vars.animationLoop || !slider.atEnd) {
  2842. slider.animating = false;
  2843. slider.currentSlide = slider.animatingTo;
  2844. }
  2845. // Unbind previous transitionEnd events and re-bind new transitionEnd event
  2846. slider.container.unbind("webkitTransitionEnd transitionend");
  2847. slider.container.bind("webkitTransitionEnd transitionend", function() {
  2848. clearTimeout(slider.ensureAnimationEnd);
  2849. slider.wrapup(dimension);
  2850. });
  2851. // Insurance for the ever-so-fickle transitionEnd event
  2852. clearTimeout(slider.ensureAnimationEnd);
  2853. slider.ensureAnimationEnd = setTimeout(function() {
  2854. slider.wrapup(dimension);
  2855. }, slider.vars.animationSpeed + 100);
  2856. } else {
  2857. slider.container.animate(slider.args, slider.vars.animationSpeed, slider.vars.easing, function(){
  2858. slider.wrapup(dimension);
  2859. });
  2860. }
  2861. } else { // FADE:
  2862. if (!touch) {
  2863. //slider.slides.eq(slider.currentSlide).fadeOut(slider.vars.animationSpeed, slider.vars.easing);
  2864. //slider.slides.eq(target).fadeIn(slider.vars.animationSpeed, slider.vars.easing, slider.wrapup);
  2865. slider.slides.eq(slider.currentSlide).css({"zIndex": 1}).animate({"opacity": 0}, slider.vars.animationSpeed, slider.vars.easing);
  2866. slider.slides.eq(target).css({"zIndex": 2}).animate({"opacity": 1}, slider.vars.animationSpeed, slider.vars.easing, slider.wrapup);
  2867. } else {
  2868. slider.slides.eq(slider.currentSlide).css({
  2869. "opacity": 0,
  2870. "zIndex": 1
  2871. });
  2872. slider.slides.eq(target).css({"opacity": 1, "zIndex": 2});
  2873. slider.wrapup(dimension);
  2874. }
  2875. }
  2876. // SMOOTH HEIGHT:
  2877. if (slider.vars.smoothHeight) {methods.smoothHeight(slider.vars.animationSpeed)};
  2878. }
  2879. };
  2880. slider.wrapup = function(dimension) {
  2881. // SLIDE:
  2882. if (!fade && !carousel) {
  2883. if (slider.currentSlide === 0 && slider.animatingTo === slider.last && slider.vars.animationLoop) {
  2884. slider.setProps(dimension, "jumpEnd");
  2885. } else if (slider.currentSlide === slider.last && slider.animatingTo === 0 && slider.vars.animationLoop) {
  2886. slider.setProps(dimension, "jumpStart");
  2887. }
  2888. }
  2889. slider.animating = false;
  2890. slider.currentSlide = slider.animatingTo;
  2891. // API: after() animation Callback
  2892. slider.vars.after(slider);
  2893. };
  2894. // SLIDESHOW:
  2895. slider.animateSlides = function() {
  2896. if (!slider.animating && focused) {slider.flexAnimate(slider.getTarget("next"));}
  2897. };
  2898. // SLIDESHOW:
  2899. slider.pause = function() {
  2900. clearInterval(slider.animatedSlides);
  2901. slider.animatedSlides = null;
  2902. slider.playing = false;
  2903. // PAUSEPLAY:
  2904. if (slider.vars.pausePlay) {methods.pausePlay.update("play");}
  2905. // SYNC:
  2906. if (slider.syncExists) {methods.sync("pause");}
  2907. };
  2908. // SLIDESHOW:
  2909. slider.play = function() {
  2910. if (slider.playing) {clearInterval(slider.animatedSlides);}
  2911. slider.animatedSlides = slider.animatedSlides || setInterval(slider.animateSlides, slider.vars.slideshowSpeed);
  2912. slider.started = slider.playing = true;
  2913. // PAUSEPLAY:
  2914. if (slider.vars.pausePlay) {methods.pausePlay.update("pause");}
  2915. // SYNC:
  2916. if (slider.syncExists) {methods.sync("play");}
  2917. };
  2918. // STOP:
  2919. slider.stop = function() {
  2920. slider.pause();
  2921. slider.stopped = true;
  2922. };
  2923. slider.canAdvance = function(target, fromNav) {
  2924. // ASNAV:
  2925. var last = (asNav) ? slider.pagingCount - 1 : slider.last;
  2926. return (fromNav) ? true :
  2927. (asNav && slider.currentItem === slider.count - 1 && target === 0 && slider.direction === "prev") ? true :
  2928. (asNav && slider.currentItem === 0 && target === slider.pagingCount - 1 && slider.direction !== "next") ? false :
  2929. (target === slider.currentSlide && !asNav) ? false :
  2930. (slider.vars.animationLoop) ? true :
  2931. (slider.atEnd && slider.currentSlide === 0 && target === last && slider.direction !== "next") ? false :
  2932. (slider.atEnd && slider.currentSlide === last && target === 0 && slider.direction === "next") ? false :
  2933. true;
  2934. };
  2935. slider.getTarget = function(dir) {
  2936. slider.direction = dir;
  2937. if (dir === "next") {
  2938. return (slider.currentSlide === slider.last) ? 0 : slider.currentSlide + 1;
  2939. } else {
  2940. return (slider.currentSlide === 0) ? slider.last : slider.currentSlide - 1;
  2941. }
  2942. };
  2943. // SLIDE:
  2944. slider.setProps = function(pos, special, dur) {
  2945. var target = (function() {
  2946. var posCheck = (pos) ? pos : ((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo,
  2947. posCalc = (function() {
  2948. if (carousel) {
  2949. return (special === "setTouch") ? pos :
  2950. (reverse && slider.animatingTo === slider.last) ? 0 :
  2951. (reverse) ? slider.limit - (((slider.itemW + slider.vars.itemMargin) * slider.move) * slider.animatingTo) :
  2952. (slider.animatingTo === slider.last) ? slider.limit : posCheck;
  2953. } else {
  2954. switch (special) {
  2955. case "setTotal":
  2956. return (reverse) ? ((slider.count - 1) - slider.currentSlide + slider.cloneOffset) * pos : (slider.currentSlide + slider.cloneOffset) * pos;
  2957. case "setTouch":
  2958. return (reverse) ? pos : pos;
  2959. case "jumpEnd":
  2960. return (reverse) ? pos : slider.count * pos;
  2961. case "jumpStart":
  2962. return (reverse) ? slider.count * pos : pos;
  2963. default:
  2964. return pos;
  2965. }
  2966. }
  2967. }());
  2968. return (posCalc * -1) + "px";
  2969. }());
  2970. if (slider.transitions) {
  2971. target = (vertical) ? "translate3d(0," + target + ",0)" : "translate3d(" + target + ",0,0)";
  2972. dur = (dur !== undefined) ? (dur / 1000) + "s" : "0s";
  2973. slider.container.css("-" + slider.pfx + "-transition-duration", dur);
  2974. slider.container.css("transition-duration", dur);
  2975. }
  2976. slider.args[slider.prop] = target;
  2977. if (slider.transitions || dur === undefined) {slider.container.css(slider.args);}
  2978. slider.container.css('transform', target);
  2979. };
  2980. slider.setup = function(type) {
  2981. // SLIDE:
  2982. if (!fade) {
  2983. var sliderOffset, arr;
  2984. if (type === "init") {
  2985. slider.viewport = $('<div class="' + namespace + 'viewport"></div>').css({
  2986. "overflow": "hidden",
  2987. "position": "relative"
  2988. }).appendTo(slider).append(slider.container);
  2989. // INFINITE LOOP:
  2990. slider.cloneCount = 0;
  2991. slider.cloneOffset = 0;
  2992. // REVERSE:
  2993. if (reverse) {
  2994. arr = $.makeArray(slider.slides).reverse();
  2995. slider.slides = $(arr);
  2996. slider.container.empty().append(slider.slides);
  2997. }
  2998. }
  2999. // INFINITE LOOP && !CAROUSEL:
  3000. if (slider.vars.animationLoop && !carousel) {
  3001. slider.cloneCount = 2;
  3002. slider.cloneOffset = 1;
  3003. // clear out old clones
  3004. if (type !== "init") { slider.container.find('.clone').remove(); }
  3005. slider.container.append(methods.uniqueID(slider.slides.first().clone().addClass('clone')).attr('aria-hidden', 'true'))
  3006. .prepend(methods.uniqueID(slider.slides.last().clone().addClass('clone')).attr('aria-hidden', 'true'));
  3007. }
  3008. slider.newSlides = $(slider.vars.selector, slider);
  3009. sliderOffset = (reverse) ? slider.count - 1 - slider.currentSlide + slider.cloneOffset : slider.currentSlide + slider.cloneOffset;
  3010. // VERTICAL:
  3011. if (vertical && !carousel) {
  3012. slider.container.height((slider.count + slider.cloneCount) * 200 + "%").css("position", "absolute").width("100%");
  3013. setTimeout(function() {
  3014. slider.newSlides.css({"display": "block"});
  3015. slider.doMath();
  3016. slider.viewport.height(slider.h);
  3017. slider.setProps(sliderOffset * slider.h, "init");
  3018. }, (type === "init") ? 100 : 0);
  3019. } else {
  3020. slider.container.width((slider.count + slider.cloneCount) * 200 + "%");
  3021. slider.setProps(sliderOffset * slider.computedW, "init");
  3022. setTimeout(function() {
  3023. slider.doMath();
  3024. slider.newSlides.css({
  3025. "width": slider.computedW,
  3026. "float": "left",
  3027. "display": "block"
  3028. });
  3029. // SMOOTH HEIGHT:
  3030. if (slider.vars.smoothHeight) {methods.smoothHeight();}
  3031. }, (type === "init") ? 100 : 0);
  3032. }
  3033. } else { // FADE:
  3034. slider.slides.css({
  3035. "width": "100%",
  3036. "float": "left",
  3037. "marginRight": "-100%",
  3038. "position": "relative"
  3039. });
  3040. if (type === "init") {
  3041. if (!touch) {
  3042. //slider.slides.eq(slider.currentSlide).fadeIn(slider.vars.animationSpeed, slider.vars.easing);
  3043. if (slider.vars.fadeFirstSlide == false) {
  3044. slider.slides.css({ "opacity": 0, "display": "block", "zIndex": 1 }).eq(slider.currentSlide).css({"zIndex": 2}).css({"opacity": 1});
  3045. } else {
  3046. slider.slides.css({ "opacity": 0, "display": "block", "zIndex": 1 }).eq(slider.currentSlide).css({"zIndex": 2}).animate({"opacity": 1},slider.vars.animationSpeed,slider.vars.easing);
  3047. }
  3048. } else {
  3049. 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});
  3050. }
  3051. }
  3052. // SMOOTH HEIGHT:
  3053. if (slider.vars.smoothHeight) {methods.smoothHeight();}
  3054. }
  3055. // !CAROUSEL:
  3056. // CANDIDATE: active slide
  3057. if (!carousel) {slider.slides.removeClass(namespace + "active-slide").eq(slider.currentSlide).addClass(namespace + "active-slide");}
  3058. //FlexSlider: init() Callback
  3059. slider.vars.init(slider);
  3060. };
  3061. slider.doMath = function() {
  3062. var slide = slider.slides.first(),
  3063. slideMargin = slider.vars.itemMargin,
  3064. minItems = slider.vars.minItems,
  3065. maxItems = slider.vars.maxItems;
  3066. slider.w = (slider.viewport === undefined) ? slider.width() : slider.viewport.width();
  3067. slider.h = slide.height();
  3068. slider.boxPadding = slide.outerWidth() - slide.width();
  3069. // CAROUSEL:
  3070. if (carousel) {
  3071. slider.itemT = slider.vars.itemWidth + slideMargin;
  3072. slider.minW = (minItems) ? minItems * slider.itemT : slider.w;
  3073. slider.maxW = (maxItems) ? (maxItems * slider.itemT) - slideMargin : slider.w;
  3074. slider.itemW = (slider.minW > slider.w) ? (slider.w - (slideMargin * (minItems - 1))) / minItems :
  3075. (slider.maxW < slider.w) ? (slider.w - (slideMargin * (maxItems - 1))) / maxItems :
  3076. (slider.vars.itemWidth > slider.w) ? slider.w : slider.vars.itemWidth;
  3077. slider.visible = Math.floor(slider.w / (slider.itemW));
  3078. slider.move = (slider.vars.move > 0 && slider.vars.move < slider.visible ) ? slider.vars.move : slider.visible;
  3079. slider.pagingCount = Math.ceil(((slider.count - slider.visible) / slider.move) + 1);
  3080. slider.last = slider.pagingCount - 1;
  3081. slider.limit = (slider.pagingCount === 1) ? 0 :
  3082. (slider.vars.itemWidth > slider.w) ? (slider.itemW * (slider.count - 1)) + (slideMargin * (slider.count - 1)) : ((slider.itemW + slideMargin) * slider.count) - slider.w - slideMargin;
  3083. } else {
  3084. slider.itemW = slider.w;
  3085. slider.pagingCount = slider.count;
  3086. slider.last = slider.count - 1;
  3087. }
  3088. slider.computedW = slider.itemW - slider.boxPadding;
  3089. };
  3090. slider.update = function(pos, action) {
  3091. slider.doMath();
  3092. // update currentSlide and slider.animatingTo if necessary
  3093. if (!carousel) {
  3094. if (pos < slider.currentSlide) {
  3095. slider.currentSlide += 1;
  3096. } else if (pos <= slider.currentSlide && pos !== 0) {
  3097. slider.currentSlide -= 1;
  3098. }
  3099. slider.animatingTo = slider.currentSlide;
  3100. }
  3101. // update controlNav
  3102. if (slider.vars.controlNav && !slider.manualControls) {
  3103. if ((action === "add" && !carousel) || slider.pagingCount > slider.controlNav.length) {
  3104. methods.controlNav.update("add");
  3105. } else if ((action === "remove" && !carousel) || slider.pagingCount < slider.controlNav.length) {
  3106. if (carousel && slider.currentSlide > slider.last) {
  3107. slider.currentSlide -= 1;
  3108. slider.animatingTo -= 1;
  3109. }
  3110. methods.controlNav.update("remove", slider.last);
  3111. }
  3112. }
  3113. // update directionNav
  3114. if (slider.vars.directionNav) {methods.directionNav.update();}
  3115. };
  3116. slider.addSlide = function(obj, pos) {
  3117. var $obj = $(obj);
  3118. slider.count += 1;
  3119. slider.last = slider.count - 1;
  3120. // append new slide
  3121. if (vertical && reverse) {
  3122. (pos !== undefined) ? slider.slides.eq(slider.count - pos).after($obj) : slider.container.prepend($obj);
  3123. } else {
  3124. (pos !== undefined) ? slider.slides.eq(pos).before($obj) : slider.container.append($obj);
  3125. }
  3126. // update currentSlide, animatingTo, controlNav, and directionNav
  3127. slider.update(pos, "add");
  3128. // update slider.slides
  3129. slider.slides = $(slider.vars.selector + ':not(.clone)', slider);
  3130. // re-setup the slider to accomdate new slide
  3131. slider.setup();
  3132. //FlexSlider: added() Callback
  3133. slider.vars.added(slider);
  3134. };
  3135. slider.removeSlide = function(obj) {
  3136. var pos = (isNaN(obj)) ? slider.slides.index($(obj)) : obj;
  3137. // update count
  3138. slider.count -= 1;
  3139. slider.last = slider.count - 1;
  3140. // remove slide
  3141. if (isNaN(obj)) {
  3142. $(obj, slider.slides).remove();
  3143. } else {
  3144. (vertical && reverse) ? slider.slides.eq(slider.last).remove() : slider.slides.eq(obj).remove();
  3145. }
  3146. // update currentSlide, animatingTo, controlNav, and directionNav
  3147. slider.doMath();
  3148. slider.update(pos, "remove");
  3149. // update slider.slides
  3150. slider.slides = $(slider.vars.selector + ':not(.clone)', slider);
  3151. // re-setup the slider to accomdate new slide
  3152. slider.setup();
  3153. // FlexSlider: removed() Callback
  3154. slider.vars.removed(slider);
  3155. };
  3156. //FlexSlider: Initialize
  3157. methods.init();
  3158. };
  3159. // Ensure the slider isn't focussed if the window loses focus.
  3160. $(window).blur(function(e) {
  3161. focused = false;
  3162. }).focus(function(e) {
  3163. focused = true;
  3164. });
  3165. // FlexSlider: Default Settings
  3166. $.flexslider.defaults = {
  3167. namespace: "am-", //{NEW} String: Prefix string attached to the class of every element generated by the plugin
  3168. selector: ".am-slides > li", //{NEW} Selector: Must match a simple pattern. '{container} > {slide}' -- Ignore pattern at your own peril
  3169. animation: "slide", //String: Select your animation type, "fade" or "slide"
  3170. easing: "swing", //{NEW} String: Determines the easing method used in jQuery transitions. jQuery easing plugin is supported!
  3171. direction: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical"
  3172. reverse: false, //{NEW} Boolean: Reverse the animation direction
  3173. animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end
  3174. smoothHeight: false, //{NEW} Boolean: Allow height of the slider to animate smoothly in horizontal mode
  3175. startAt: 0, //Integer: The slide that the slider should start on. Array notation (0 = first slide)
  3176. slideshow: true, //Boolean: Animate slider automatically
  3177. slideshowSpeed: 5000, //Integer: Set the speed of the slideshow cycling, in milliseconds
  3178. animationSpeed: 600, //Integer: Set the speed of animations, in milliseconds
  3179. initDelay: 0, //{NEW} Integer: Set an initialization delay, in milliseconds
  3180. randomize: false, //Boolean: Randomize slide order
  3181. fadeFirstSlide: true, //Boolean: Fade in the first slide when animation type is "fade"
  3182. thumbCaptions: false, //Boolean: Whether or not to put captions on thumbnails when using the "thumbnails" controlNav.
  3183. // Usability features
  3184. pauseOnAction: true, //Boolean: Pause the slideshow when interacting with control elements, highly recommended.
  3185. pauseOnHover: false, //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering
  3186. pauseInvisible: true, //{NEW} Boolean: Pause the slideshow when tab is invisible, resume when visible. Provides better UX, lower CPU usage.
  3187. useCSS: true, //{NEW} Boolean: Slider will use CSS3 transitions if available
  3188. touch: true, //{NEW} Boolean: Allow touch swipe navigation of the slider on touch-enabled devices
  3189. video: false, //{NEW} Boolean: If using video in the slider, will prevent CSS3 3D Transforms to avoid graphical glitches
  3190. // Primary Controls
  3191. controlNav: true, //Boolean: Create navigation for paging control of each slide? Note: Leave true for manualControls usage
  3192. directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false)
  3193. prevText: " ", //String: Set the text for the "previous" directionNav item
  3194. nextText: " ", //String: Set the text for the "next" directionNav item
  3195. // Secondary Navigation
  3196. keyboard: true, //Boolean: Allow slider navigating via keyboard left/right keys
  3197. multipleKeyboard: false, //{NEW} Boolean: Allow keyboard navigation to affect multiple sliders. Default behavior cuts out keyboard navigation with more than one slider present.
  3198. mousewheel: false, //{UPDATED} Boolean: Requires jquery.mousewheel.js (https://github.com/brandonaaron/jquery-mousewheel) - Allows slider navigating via mousewheel
  3199. pausePlay: false, //Boolean: Create pause/play dynamic element
  3200. pauseText: "Pause", //String: Set the text for the "pause" pausePlay item
  3201. playText: "Play", //String: Set the text for the "play" pausePlay item
  3202. // Special properties
  3203. 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.
  3204. 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.
  3205. sync: "", //{NEW} Selector: Mirror the actions performed on this slider with another slider. Use with care.
  3206. asNavFor: "", //{NEW} Selector: Internal property exposed for turning the slider into a thumbnail navigation for another slider
  3207. // Carousel Options
  3208. itemWidth: 0, //{NEW} Integer: Box-model width of individual carousel items, including horizontal borders and padding.
  3209. itemMargin: 0, //{NEW} Integer: Margin between carousel items.
  3210. minItems: 1, //{NEW} Integer: Minimum number of carousel items that should be visible. Items will resize fluidly when below this.
  3211. maxItems: 0, //{NEW} Integer: Maxmimum number of carousel items that should be visible. Items will resize fluidly when above this limit.
  3212. move: 0, //{NEW} Integer: Number of carousel items that should move on animation. If 0, slider will move all visible items.
  3213. allowOneSlide: true, //{NEW} Boolean: Whether or not to allow a slider comprised of a single slide
  3214. // Callback API
  3215. start: function() {
  3216. }, //Callback: function(slider) - Fires when the slider loads the first slide
  3217. before: function() {
  3218. }, //Callback: function(slider) - Fires asynchronously with each slider animation
  3219. after: function() {
  3220. }, //Callback: function(slider) - Fires after each slider animation completes
  3221. end: function() {
  3222. }, //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous)
  3223. added: function() {
  3224. }, //{NEW} Callback: function(slider) - Fires after a slide is added
  3225. removed: function() {
  3226. }, //{NEW} Callback: function(slider) - Fires after a slide is removed
  3227. init: function() {
  3228. } //{NEW} Callback: function(slider) - Fires after the slider is initially setup
  3229. };
  3230. // FlexSlider: Plugin Function
  3231. $.fn.flexslider = function(options) {
  3232. if (options === undefined) {options = {};}
  3233. if (typeof options === "object") {
  3234. return this.each(function() {
  3235. var $this = $(this),
  3236. selector = (options.selector) ? options.selector : ".am-slides > li",
  3237. $slides = $this.find(selector);
  3238. if (($slides.length === 1 && options.allowOneSlide === true) || $slides.length === 0) {
  3239. $slides.fadeIn(400);
  3240. if (options.start) {options.start($this);}
  3241. } else if ($this.data('flexslider') === undefined) {
  3242. new $.flexslider(this, options);
  3243. }
  3244. });
  3245. } else {
  3246. // Helper strings to quickly pecdrform functions on the slider
  3247. var $slider = $(this).data('flexslider');
  3248. switch (options) {
  3249. case 'play':
  3250. $slider.play();
  3251. break;
  3252. case 'pause':
  3253. $slider.pause();
  3254. break;
  3255. case 'stop':
  3256. $slider.stop();
  3257. break;
  3258. case 'next':
  3259. $slider.flexAnimate($slider.getTarget('next'), true);
  3260. break;
  3261. case 'prev':
  3262. case 'previous':
  3263. $slider.flexAnimate($slider.getTarget('prev'), true);
  3264. break;
  3265. default:
  3266. if (typeof options === 'number') {
  3267. $slider.flexAnimate(options, true);
  3268. }
  3269. }
  3270. }
  3271. };
  3272. // Init code
  3273. UI.ready(function(context) {
  3274. $('[data-am-flexslider]', context).each(function(i, item) {
  3275. var $slider = $(item);
  3276. var options = UI.utils.parseOptions($slider.data('amFlexslider'));
  3277. options.before = function(slider) {
  3278. if (slider._pausedTimer) {
  3279. window.clearTimeout(slider._pausedTimer);
  3280. slider._pausedTimer = null;
  3281. }
  3282. };
  3283. options.after = function(slider) {
  3284. var pauseTime = slider.vars.playAfterPaused;
  3285. if (pauseTime && !isNaN(pauseTime) && !slider.playing) {
  3286. if (!slider.manualPause && !slider.manualPlay && !slider.stopped) {
  3287. slider._pausedTimer = window.setTimeout(function() {
  3288. slider.play();
  3289. }, pauseTime);
  3290. }
  3291. }
  3292. };
  3293. $slider.flexslider(options);
  3294. });
  3295. });
  3296. module.exports = $.flexslider;
  3297. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  3298. },{"2":2}],11:[function(_dereq_,module,exports){
  3299. (function (global){
  3300. 'use strict';
  3301. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  3302. var UI = _dereq_(2);
  3303. /* jshint unused: false */
  3304. /* jshint -W101, -W116, -W109 */
  3305. /*! iScroll v5.1.3
  3306. * (c) 2008-2014 Matteo Spinelli
  3307. * http://cubiq.org/license
  3308. */
  3309. var rAF = window.requestAnimationFrame ||
  3310. window.webkitRequestAnimationFrame ||
  3311. window.mozRequestAnimationFrame ||
  3312. window.oRequestAnimationFrame ||
  3313. window.msRequestAnimationFrame ||
  3314. function(callback) {
  3315. window.setTimeout(callback, 1000 / 60);
  3316. };
  3317. var utils = (function() {
  3318. var me = {};
  3319. var _elementStyle = document.createElement('div').style;
  3320. var _vendor = (function() {
  3321. var vendors = ['t', 'webkitT', 'MozT', 'msT', 'OT'],
  3322. transform,
  3323. i = 0,
  3324. l = vendors.length;
  3325. for (; i < l; i++) {
  3326. transform = vendors[i] + 'ransform';
  3327. if (transform in _elementStyle) return vendors[i].substr(0, vendors[i].length - 1);
  3328. }
  3329. return false;
  3330. })();
  3331. function _prefixStyle(style) {
  3332. if (_vendor === false) return false;
  3333. if (_vendor === '') return style;
  3334. return _vendor + style.charAt(0).toUpperCase() + style.substr(1);
  3335. }
  3336. me.getTime = Date.now || function getTime() {
  3337. return new Date().getTime();
  3338. };
  3339. me.extend = function(target, obj) {
  3340. for (var i in obj) {
  3341. target[i] = obj[i];
  3342. }
  3343. };
  3344. me.addEvent = function(el, type, fn, capture) {
  3345. el.addEventListener(type, fn, !!capture);
  3346. };
  3347. me.removeEvent = function(el, type, fn, capture) {
  3348. el.removeEventListener(type, fn, !!capture);
  3349. };
  3350. me.prefixPointerEvent = function(pointerEvent) {
  3351. return window.MSPointerEvent ?
  3352. 'MSPointer' + pointerEvent.charAt(9).toUpperCase() + pointerEvent.substr(10) :
  3353. pointerEvent;
  3354. };
  3355. me.momentum = function(current, start, time, lowerMargin, wrapperSize, deceleration) {
  3356. var distance = current - start,
  3357. speed = Math.abs(distance) / time,
  3358. destination,
  3359. duration;
  3360. deceleration = deceleration === undefined ? 0.0006 : deceleration;
  3361. destination = current + ( speed * speed ) / ( 2 * deceleration ) * ( distance < 0 ? -1 : 1 );
  3362. duration = speed / deceleration;
  3363. if (destination < lowerMargin) {
  3364. destination = wrapperSize ? lowerMargin - ( wrapperSize / 2.5 * ( speed / 8 ) ) : lowerMargin;
  3365. distance = Math.abs(destination - current);
  3366. duration = distance / speed;
  3367. } else if (destination > 0) {
  3368. destination = wrapperSize ? wrapperSize / 2.5 * ( speed / 8 ) : 0;
  3369. distance = Math.abs(current) + destination;
  3370. duration = distance / speed;
  3371. }
  3372. return {
  3373. destination: Math.round(destination),
  3374. duration: duration
  3375. };
  3376. };
  3377. var _transform = _prefixStyle('transform');
  3378. me.extend(me, {
  3379. hasTransform: _transform !== false,
  3380. hasPerspective: _prefixStyle('perspective') in _elementStyle,
  3381. hasTouch: 'ontouchstart' in window,
  3382. hasPointer: window.PointerEvent || window.MSPointerEvent, // IE10 is prefixed
  3383. hasTransition: _prefixStyle('transition') in _elementStyle
  3384. });
  3385. // This should find all Android browsers lower than build 535.19 (both stock browser and webview)
  3386. me.isBadAndroid = /Android /.test(window.navigator.appVersion) && !(/Chrome\/\d/.test(window.navigator.appVersion));
  3387. me.extend(me.style = {}, {
  3388. transform: _transform,
  3389. transitionTimingFunction: _prefixStyle('transitionTimingFunction'),
  3390. transitionDuration: _prefixStyle('transitionDuration'),
  3391. transitionDelay: _prefixStyle('transitionDelay'),
  3392. transformOrigin: _prefixStyle('transformOrigin')
  3393. });
  3394. me.hasClass = function(e, c) {
  3395. var re = new RegExp("(^|\\s)" + c + "(\\s|$)");
  3396. return re.test(e.className);
  3397. };
  3398. me.addClass = function(e, c) {
  3399. if (me.hasClass(e, c)) {
  3400. return;
  3401. }
  3402. var newclass = e.className.split(' ');
  3403. newclass.push(c);
  3404. e.className = newclass.join(' ');
  3405. };
  3406. me.removeClass = function(e, c) {
  3407. if (!me.hasClass(e, c)) {
  3408. return;
  3409. }
  3410. var re = new RegExp("(^|\\s)" + c + "(\\s|$)", 'g');
  3411. e.className = e.className.replace(re, ' ');
  3412. };
  3413. me.offset = function(el) {
  3414. var left = -el.offsetLeft,
  3415. top = -el.offsetTop;
  3416. // jshint -W084
  3417. while (el = el.offsetParent) {
  3418. left -= el.offsetLeft;
  3419. top -= el.offsetTop;
  3420. }
  3421. // jshint +W084
  3422. return {
  3423. left: left,
  3424. top: top
  3425. };
  3426. };
  3427. me.preventDefaultException = function(el, exceptions) {
  3428. for (var i in exceptions) {
  3429. if (exceptions[i].test(el[i])) {
  3430. return true;
  3431. }
  3432. }
  3433. return false;
  3434. };
  3435. me.extend(me.eventType = {}, {
  3436. touchstart: 1,
  3437. touchmove: 1,
  3438. touchend: 1,
  3439. mousedown: 2,
  3440. mousemove: 2,
  3441. mouseup: 2,
  3442. pointerdown: 3,
  3443. pointermove: 3,
  3444. pointerup: 3,
  3445. MSPointerDown: 3,
  3446. MSPointerMove: 3,
  3447. MSPointerUp: 3
  3448. });
  3449. me.extend(me.ease = {}, {
  3450. quadratic: {
  3451. style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
  3452. fn: function(k) {
  3453. return k * ( 2 - k );
  3454. }
  3455. },
  3456. circular: {
  3457. style: 'cubic-bezier(0.1, 0.57, 0.1, 1)', // Not properly "circular" but this looks better, it should be (0.075, 0.82, 0.165, 1)
  3458. fn: function(k) {
  3459. return Math.sqrt(1 - ( --k * k ));
  3460. }
  3461. },
  3462. back: {
  3463. style: 'cubic-bezier(0.175, 0.885, 0.32, 1.275)',
  3464. fn: function(k) {
  3465. var b = 4;
  3466. return ( k = k - 1 ) * k * ( ( b + 1 ) * k + b ) + 1;
  3467. }
  3468. },
  3469. bounce: {
  3470. style: '',
  3471. fn: function(k) {
  3472. if (( k /= 1 ) < ( 1 / 2.75 )) {
  3473. return 7.5625 * k * k;
  3474. } else if (k < ( 2 / 2.75 )) {
  3475. return 7.5625 * ( k -= ( 1.5 / 2.75 ) ) * k + 0.75;
  3476. } else if (k < ( 2.5 / 2.75 )) {
  3477. return 7.5625 * ( k -= ( 2.25 / 2.75 ) ) * k + 0.9375;
  3478. } else {
  3479. return 7.5625 * ( k -= ( 2.625 / 2.75 ) ) * k + 0.984375;
  3480. }
  3481. }
  3482. },
  3483. elastic: {
  3484. style: '',
  3485. fn: function(k) {
  3486. var f = 0.22,
  3487. e = 0.4;
  3488. if (k === 0) {
  3489. return 0;
  3490. }
  3491. if (k == 1) {
  3492. return 1;
  3493. }
  3494. return ( e * Math.pow(2, -10 * k) * Math.sin(( k - f / 4 ) * ( 2 * Math.PI ) / f) + 1 );
  3495. }
  3496. }
  3497. });
  3498. me.tap = function(e, eventName) {
  3499. var ev = document.createEvent('Event');
  3500. ev.initEvent(eventName, true, true);
  3501. ev.pageX = e.pageX;
  3502. ev.pageY = e.pageY;
  3503. e.target.dispatchEvent(ev);
  3504. };
  3505. me.click = function(e) {
  3506. var target = e.target,
  3507. ev;
  3508. if (!(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName)) {
  3509. ev = document.createEvent('MouseEvents');
  3510. ev.initMouseEvent('click', true, true, e.view, 1,
  3511. target.screenX, target.screenY, target.clientX, target.clientY,
  3512. e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
  3513. 0, null);
  3514. ev._constructed = true;
  3515. target.dispatchEvent(ev);
  3516. }
  3517. };
  3518. return me;
  3519. })();
  3520. function IScroll(el, options) {
  3521. this.wrapper = typeof el == 'string' ? document.querySelector(el) : el;
  3522. this.scroller = this.wrapper.children[0];
  3523. this.scrollerStyle = this.scroller.style; // cache style for better performance
  3524. this.options = {
  3525. // INSERT POINT: OPTIONS
  3526. startX: 0,
  3527. startY: 0,
  3528. scrollY: true,
  3529. directionLockThreshold: 5,
  3530. momentum: true,
  3531. bounce: true,
  3532. bounceTime: 600,
  3533. bounceEasing: '',
  3534. preventDefault: true,
  3535. preventDefaultException: {tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT)$/},
  3536. HWCompositing: true,
  3537. useTransition: true,
  3538. useTransform: true
  3539. };
  3540. for (var i in options) {
  3541. this.options[i] = options[i];
  3542. }
  3543. // Normalize options
  3544. this.translateZ = this.options.HWCompositing && utils.hasPerspective ? ' translateZ(0)' : '';
  3545. this.options.useTransition = utils.hasTransition && this.options.useTransition;
  3546. this.options.useTransform = utils.hasTransform && this.options.useTransform;
  3547. this.options.eventPassthrough = this.options.eventPassthrough === true ? 'vertical' : this.options.eventPassthrough;
  3548. this.options.preventDefault = !this.options.eventPassthrough && this.options.preventDefault;
  3549. // If you want eventPassthrough I have to lock one of the axes
  3550. this.options.scrollY = this.options.eventPassthrough == 'vertical' ? false : this.options.scrollY;
  3551. this.options.scrollX = this.options.eventPassthrough == 'horizontal' ? false : this.options.scrollX;
  3552. // With eventPassthrough we also need lockDirection mechanism
  3553. this.options.freeScroll = this.options.freeScroll && !this.options.eventPassthrough;
  3554. this.options.directionLockThreshold = this.options.eventPassthrough ? 0 : this.options.directionLockThreshold;
  3555. this.options.bounceEasing = typeof this.options.bounceEasing == 'string' ? utils.ease[this.options.bounceEasing] || utils.ease.circular : this.options.bounceEasing;
  3556. this.options.resizePolling = this.options.resizePolling === undefined ? 60 : this.options.resizePolling;
  3557. if (this.options.tap === true) {
  3558. this.options.tap = 'tap';
  3559. }
  3560. // INSERT POINT: NORMALIZATION
  3561. // Some defaults
  3562. this.x = 0;
  3563. this.y = 0;
  3564. this.directionX = 0;
  3565. this.directionY = 0;
  3566. this._events = {};
  3567. // INSERT POINT: DEFAULTS
  3568. this._init();
  3569. this.refresh();
  3570. this.scrollTo(this.options.startX, this.options.startY);
  3571. this.enable();
  3572. }
  3573. IScroll.prototype = {
  3574. version: '5.1.3',
  3575. _init: function() {
  3576. this._initEvents();
  3577. // INSERT POINT: _init
  3578. },
  3579. destroy: function() {
  3580. this._initEvents(true);
  3581. this._execEvent('destroy');
  3582. },
  3583. _transitionEnd: function(e) {
  3584. if (e.target != this.scroller || !this.isInTransition) {
  3585. return;
  3586. }
  3587. this._transitionTime();
  3588. if (!this.resetPosition(this.options.bounceTime)) {
  3589. this.isInTransition = false;
  3590. this._execEvent('scrollEnd');
  3591. }
  3592. },
  3593. _start: function(e) {
  3594. // React to left mouse button only
  3595. if (utils.eventType[e.type] != 1) {
  3596. if (e.button !== 0) {
  3597. return;
  3598. }
  3599. }
  3600. if (!this.enabled || (this.initiated && utils.eventType[e.type] !== this.initiated)) {
  3601. return;
  3602. }
  3603. if (this.options.preventDefault && !utils.isBadAndroid && !utils.preventDefaultException(e.target, this.options.preventDefaultException)) {
  3604. e.preventDefault();
  3605. }
  3606. var point = e.touches ? e.touches[0] : e,
  3607. pos;
  3608. this.initiated = utils.eventType[e.type];
  3609. this.moved = false;
  3610. this.distX = 0;
  3611. this.distY = 0;
  3612. this.directionX = 0;
  3613. this.directionY = 0;
  3614. this.directionLocked = 0;
  3615. this._transitionTime();
  3616. this.startTime = utils.getTime();
  3617. if (this.options.useTransition && this.isInTransition) {
  3618. this.isInTransition = false;
  3619. pos = this.getComputedPosition();
  3620. this._translate(Math.round(pos.x), Math.round(pos.y));
  3621. this._execEvent('scrollEnd');
  3622. } else if (!this.options.useTransition && this.isAnimating) {
  3623. this.isAnimating = false;
  3624. this._execEvent('scrollEnd');
  3625. }
  3626. this.startX = this.x;
  3627. this.startY = this.y;
  3628. this.absStartX = this.x;
  3629. this.absStartY = this.y;
  3630. this.pointX = point.pageX;
  3631. this.pointY = point.pageY;
  3632. this._execEvent('beforeScrollStart');
  3633. },
  3634. _move: function(e) {
  3635. if (!this.enabled || utils.eventType[e.type] !== this.initiated) {
  3636. return;
  3637. }
  3638. if (this.options.preventDefault) { // increases performance on Android? TODO: check!
  3639. e.preventDefault();
  3640. }
  3641. var point = e.touches ? e.touches[0] : e,
  3642. deltaX = point.pageX - this.pointX,
  3643. deltaY = point.pageY - this.pointY,
  3644. timestamp = utils.getTime(),
  3645. newX, newY,
  3646. absDistX, absDistY;
  3647. this.pointX = point.pageX;
  3648. this.pointY = point.pageY;
  3649. this.distX += deltaX;
  3650. this.distY += deltaY;
  3651. absDistX = Math.abs(this.distX);
  3652. absDistY = Math.abs(this.distY);
  3653. // We need to move at least 10 pixels for the scrolling to initiate
  3654. if (timestamp - this.endTime > 300 && (absDistX < 10 && absDistY < 10)) {
  3655. return;
  3656. }
  3657. // If you are scrolling in one direction lock the other
  3658. if (!this.directionLocked && !this.options.freeScroll) {
  3659. if (absDistX > absDistY + this.options.directionLockThreshold) {
  3660. this.directionLocked = 'h'; // lock horizontally
  3661. } else if (absDistY >= absDistX + this.options.directionLockThreshold) {
  3662. this.directionLocked = 'v'; // lock vertically
  3663. } else {
  3664. this.directionLocked = 'n'; // no lock
  3665. }
  3666. }
  3667. if (this.directionLocked == 'h') {
  3668. if (this.options.eventPassthrough == 'vertical') {
  3669. e.preventDefault();
  3670. } else if (this.options.eventPassthrough == 'horizontal') {
  3671. this.initiated = false;
  3672. return;
  3673. }
  3674. deltaY = 0;
  3675. } else if (this.directionLocked == 'v') {
  3676. if (this.options.eventPassthrough == 'horizontal') {
  3677. e.preventDefault();
  3678. } else if (this.options.eventPassthrough == 'vertical') {
  3679. this.initiated = false;
  3680. return;
  3681. }
  3682. deltaX = 0;
  3683. }
  3684. deltaX = this.hasHorizontalScroll ? deltaX : 0;
  3685. deltaY = this.hasVerticalScroll ? deltaY : 0;
  3686. newX = this.x + deltaX;
  3687. newY = this.y + deltaY;
  3688. // Slow down if outside of the boundaries
  3689. if (newX > 0 || newX < this.maxScrollX) {
  3690. newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX;
  3691. }
  3692. if (newY > 0 || newY < this.maxScrollY) {
  3693. newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY;
  3694. }
  3695. this.directionX = deltaX > 0 ? -1 : deltaX < 0 ? 1 : 0;
  3696. this.directionY = deltaY > 0 ? -1 : deltaY < 0 ? 1 : 0;
  3697. if (!this.moved) {
  3698. this._execEvent('scrollStart');
  3699. }
  3700. this.moved = true;
  3701. this._translate(newX, newY);
  3702. /* REPLACE START: _move */
  3703. if (timestamp - this.startTime > 300) {
  3704. this.startTime = timestamp;
  3705. this.startX = this.x;
  3706. this.startY = this.y;
  3707. }
  3708. /* REPLACE END: _move */
  3709. },
  3710. _end: function(e) {
  3711. if (!this.enabled || utils.eventType[e.type] !== this.initiated) {
  3712. return;
  3713. }
  3714. if (this.options.preventDefault && !utils.preventDefaultException(e.target, this.options.preventDefaultException)) {
  3715. e.preventDefault();
  3716. }
  3717. var point = e.changedTouches ? e.changedTouches[0] : e,
  3718. momentumX,
  3719. momentumY,
  3720. duration = utils.getTime() - this.startTime,
  3721. newX = Math.round(this.x),
  3722. newY = Math.round(this.y),
  3723. distanceX = Math.abs(newX - this.startX),
  3724. distanceY = Math.abs(newY - this.startY),
  3725. time = 0,
  3726. easing = '';
  3727. this.isInTransition = 0;
  3728. this.initiated = 0;
  3729. this.endTime = utils.getTime();
  3730. // reset if we are outside of the boundaries
  3731. if (this.resetPosition(this.options.bounceTime)) {
  3732. return;
  3733. }
  3734. this.scrollTo(newX, newY); // ensures that the last position is rounded
  3735. // we scrolled less than 10 pixels
  3736. if (!this.moved) {
  3737. if (this.options.tap) {
  3738. utils.tap(e, this.options.tap);
  3739. }
  3740. if (this.options.click) {
  3741. utils.click(e);
  3742. }
  3743. this._execEvent('scrollCancel');
  3744. return;
  3745. }
  3746. if (this._events.flick && duration < 200 && distanceX < 100 && distanceY < 100) {
  3747. this._execEvent('flick');
  3748. return;
  3749. }
  3750. // start momentum animation if needed
  3751. if (this.options.momentum && duration < 300) {
  3752. momentumX = this.hasHorizontalScroll ? utils.momentum(this.x, this.startX, duration, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : {
  3753. destination: newX,
  3754. duration: 0
  3755. };
  3756. momentumY = this.hasVerticalScroll ? utils.momentum(this.y, this.startY, duration, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : {
  3757. destination: newY,
  3758. duration: 0
  3759. };
  3760. newX = momentumX.destination;
  3761. newY = momentumY.destination;
  3762. time = Math.max(momentumX.duration, momentumY.duration);
  3763. this.isInTransition = 1;
  3764. }
  3765. // INSERT POINT: _end
  3766. if (newX != this.x || newY != this.y) {
  3767. // change easing function when scroller goes out of the boundaries
  3768. if (newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY) {
  3769. easing = utils.ease.quadratic;
  3770. }
  3771. this.scrollTo(newX, newY, time, easing);
  3772. return;
  3773. }
  3774. this._execEvent('scrollEnd');
  3775. },
  3776. _resize: function() {
  3777. var that = this;
  3778. clearTimeout(this.resizeTimeout);
  3779. this.resizeTimeout = setTimeout(function() {
  3780. that.refresh();
  3781. }, this.options.resizePolling);
  3782. },
  3783. resetPosition: function(time) {
  3784. var x = this.x,
  3785. y = this.y;
  3786. time = time || 0;
  3787. if (!this.hasHorizontalScroll || this.x > 0) {
  3788. x = 0;
  3789. } else if (this.x < this.maxScrollX) {
  3790. x = this.maxScrollX;
  3791. }
  3792. if (!this.hasVerticalScroll || this.y > 0) {
  3793. y = 0;
  3794. } else if (this.y < this.maxScrollY) {
  3795. y = this.maxScrollY;
  3796. }
  3797. if (x == this.x && y == this.y) {
  3798. return false;
  3799. }
  3800. this.scrollTo(x, y, time, this.options.bounceEasing);
  3801. return true;
  3802. },
  3803. disable: function() {
  3804. this.enabled = false;
  3805. },
  3806. enable: function() {
  3807. this.enabled = true;
  3808. },
  3809. refresh: function() {
  3810. var rf = this.wrapper.offsetHeight; // Force reflow
  3811. this.wrapperWidth = this.wrapper.clientWidth;
  3812. this.wrapperHeight = this.wrapper.clientHeight;
  3813. /* REPLACE START: refresh */
  3814. this.scrollerWidth = this.scroller.offsetWidth;
  3815. this.scrollerHeight = this.scroller.offsetHeight;
  3816. this.maxScrollX = this.wrapperWidth - this.scrollerWidth;
  3817. this.maxScrollY = this.wrapperHeight - this.scrollerHeight;
  3818. /* REPLACE END: refresh */
  3819. this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0;
  3820. this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0;
  3821. if (!this.hasHorizontalScroll) {
  3822. this.maxScrollX = 0;
  3823. this.scrollerWidth = this.wrapperWidth;
  3824. }
  3825. if (!this.hasVerticalScroll) {
  3826. this.maxScrollY = 0;
  3827. this.scrollerHeight = this.wrapperHeight;
  3828. }
  3829. this.endTime = 0;
  3830. this.directionX = 0;
  3831. this.directionY = 0;
  3832. this.wrapperOffset = utils.offset(this.wrapper);
  3833. this._execEvent('refresh');
  3834. this.resetPosition();
  3835. // INSERT POINT: _refresh
  3836. },
  3837. on: function(type, fn) {
  3838. if (!this._events[type]) {
  3839. this._events[type] = [];
  3840. }
  3841. this._events[type].push(fn);
  3842. },
  3843. off: function(type, fn) {
  3844. if (!this._events[type]) {
  3845. return;
  3846. }
  3847. var index = this._events[type].indexOf(fn);
  3848. if (index > -1) {
  3849. this._events[type].splice(index, 1);
  3850. }
  3851. },
  3852. _execEvent: function(type) {
  3853. if (!this._events[type]) {
  3854. return;
  3855. }
  3856. var i = 0,
  3857. l = this._events[type].length;
  3858. if (!l) {
  3859. return;
  3860. }
  3861. for (; i < l; i++) {
  3862. this._events[type][i].apply(this, [].slice.call(arguments, 1));
  3863. }
  3864. },
  3865. scrollBy: function(x, y, time, easing) {
  3866. x = this.x + x;
  3867. y = this.y + y;
  3868. time = time || 0;
  3869. this.scrollTo(x, y, time, easing);
  3870. },
  3871. scrollTo: function(x, y, time, easing) {
  3872. easing = easing || utils.ease.circular;
  3873. this.isInTransition = this.options.useTransition && time > 0;
  3874. if (!time || (this.options.useTransition && easing.style)) {
  3875. this._transitionTimingFunction(easing.style);
  3876. this._transitionTime(time);
  3877. this._translate(x, y);
  3878. } else {
  3879. this._animate(x, y, time, easing.fn);
  3880. }
  3881. },
  3882. scrollToElement: function(el, time, offsetX, offsetY, easing) {
  3883. el = el.nodeType ? el : this.scroller.querySelector(el);
  3884. if (!el) {
  3885. return;
  3886. }
  3887. var pos = utils.offset(el);
  3888. pos.left -= this.wrapperOffset.left;
  3889. pos.top -= this.wrapperOffset.top;
  3890. // if offsetX/Y are true we center the element to the screen
  3891. if (offsetX === true) {
  3892. offsetX = Math.round(el.offsetWidth / 2 - this.wrapper.offsetWidth / 2);
  3893. }
  3894. if (offsetY === true) {
  3895. offsetY = Math.round(el.offsetHeight / 2 - this.wrapper.offsetHeight / 2);
  3896. }
  3897. pos.left -= offsetX || 0;
  3898. pos.top -= offsetY || 0;
  3899. pos.left = pos.left > 0 ? 0 : pos.left < this.maxScrollX ? this.maxScrollX : pos.left;
  3900. pos.top = pos.top > 0 ? 0 : pos.top < this.maxScrollY ? this.maxScrollY : pos.top;
  3901. time = time === undefined || time === null || time === 'auto' ? Math.max(Math.abs(this.x - pos.left), Math.abs(this.y - pos.top)) : time;
  3902. this.scrollTo(pos.left, pos.top, time, easing);
  3903. },
  3904. _transitionTime: function(time) {
  3905. time = time || 0;
  3906. this.scrollerStyle[utils.style.transitionDuration] = time + 'ms';
  3907. if (!time && utils.isBadAndroid) {
  3908. this.scrollerStyle[utils.style.transitionDuration] = '0.001s';
  3909. }
  3910. // INSERT POINT: _transitionTime
  3911. },
  3912. _transitionTimingFunction: function(easing) {
  3913. this.scrollerStyle[utils.style.transitionTimingFunction] = easing;
  3914. // INSERT POINT: _transitionTimingFunction
  3915. },
  3916. _translate: function(x, y) {
  3917. if (this.options.useTransform) {
  3918. /* REPLACE START: _translate */
  3919. this.scrollerStyle[utils.style.transform] = 'translate(' + x + 'px,' + y + 'px)' + this.translateZ;
  3920. /* REPLACE END: _translate */
  3921. } else {
  3922. x = Math.round(x);
  3923. y = Math.round(y);
  3924. this.scrollerStyle.left = x + 'px';
  3925. this.scrollerStyle.top = y + 'px';
  3926. }
  3927. this.x = x;
  3928. this.y = y;
  3929. // INSERT POINT: _translate
  3930. },
  3931. _initEvents: function(remove) {
  3932. var eventType = remove ? utils.removeEvent : utils.addEvent,
  3933. target = this.options.bindToWrapper ? this.wrapper : window;
  3934. eventType(window, 'orientationchange', this);
  3935. eventType(window, 'resize', this);
  3936. if (this.options.click) {
  3937. eventType(this.wrapper, 'click', this, true);
  3938. }
  3939. if (!this.options.disableMouse) {
  3940. eventType(this.wrapper, 'mousedown', this);
  3941. eventType(target, 'mousemove', this);
  3942. eventType(target, 'mousecancel', this);
  3943. eventType(target, 'mouseup', this);
  3944. }
  3945. if (utils.hasPointer && !this.options.disablePointer) {
  3946. eventType(this.wrapper, utils.prefixPointerEvent('pointerdown'), this);
  3947. eventType(target, utils.prefixPointerEvent('pointermove'), this);
  3948. eventType(target, utils.prefixPointerEvent('pointercancel'), this);
  3949. eventType(target, utils.prefixPointerEvent('pointerup'), this);
  3950. }
  3951. if (utils.hasTouch && !this.options.disableTouch) {
  3952. eventType(this.wrapper, 'touchstart', this);
  3953. eventType(target, 'touchmove', this);
  3954. eventType(target, 'touchcancel', this);
  3955. eventType(target, 'touchend', this);
  3956. }
  3957. eventType(this.scroller, 'transitionend', this);
  3958. eventType(this.scroller, 'webkitTransitionEnd', this);
  3959. eventType(this.scroller, 'oTransitionEnd', this);
  3960. eventType(this.scroller, 'MSTransitionEnd', this);
  3961. },
  3962. getComputedPosition: function() {
  3963. var matrix = window.getComputedStyle(this.scroller, null),
  3964. x, y;
  3965. if (this.options.useTransform) {
  3966. matrix = matrix[utils.style.transform].split(')')[0].split(', ');
  3967. x = +(matrix[12] || matrix[4]);
  3968. y = +(matrix[13] || matrix[5]);
  3969. } else {
  3970. x = +matrix.left.replace(/[^-\d.]/g, '');
  3971. y = +matrix.top.replace(/[^-\d.]/g, '');
  3972. }
  3973. return {x: x, y: y};
  3974. },
  3975. _animate: function(destX, destY, duration, easingFn) {
  3976. var that = this,
  3977. startX = this.x,
  3978. startY = this.y,
  3979. startTime = utils.getTime(),
  3980. destTime = startTime + duration;
  3981. function step() {
  3982. var now = utils.getTime(),
  3983. newX, newY,
  3984. easing;
  3985. if (now >= destTime) {
  3986. that.isAnimating = false;
  3987. that._translate(destX, destY);
  3988. if (!that.resetPosition(that.options.bounceTime)) {
  3989. that._execEvent('scrollEnd');
  3990. }
  3991. return;
  3992. }
  3993. now = ( now - startTime ) / duration;
  3994. easing = easingFn(now);
  3995. newX = ( destX - startX ) * easing + startX;
  3996. newY = ( destY - startY ) * easing + startY;
  3997. that._translate(newX, newY);
  3998. if (that.isAnimating) {
  3999. rAF(step);
  4000. }
  4001. }
  4002. this.isAnimating = true;
  4003. step();
  4004. },
  4005. handleEvent: function(e) {
  4006. switch (e.type) {
  4007. case 'touchstart':
  4008. case 'pointerdown':
  4009. case 'MSPointerDown':
  4010. case 'mousedown':
  4011. this._start(e);
  4012. break;
  4013. case 'touchmove':
  4014. case 'pointermove':
  4015. case 'MSPointerMove':
  4016. case 'mousemove':
  4017. this._move(e);
  4018. break;
  4019. case 'touchend':
  4020. case 'pointerup':
  4021. case 'MSPointerUp':
  4022. case 'mouseup':
  4023. case 'touchcancel':
  4024. case 'pointercancel':
  4025. case 'MSPointerCancel':
  4026. case 'mousecancel':
  4027. this._end(e);
  4028. break;
  4029. case 'orientationchange':
  4030. case 'resize':
  4031. this._resize();
  4032. break;
  4033. case 'transitionend':
  4034. case 'webkitTransitionEnd':
  4035. case 'oTransitionEnd':
  4036. case 'MSTransitionEnd':
  4037. this._transitionEnd(e);
  4038. break;
  4039. case 'wheel':
  4040. case 'DOMMouseScroll':
  4041. case 'mousewheel':
  4042. this._wheel(e);
  4043. break;
  4044. case 'keydown':
  4045. this._key(e);
  4046. break;
  4047. case 'click':
  4048. if (!e._constructed) {
  4049. e.preventDefault();
  4050. e.stopPropagation();
  4051. }
  4052. break;
  4053. }
  4054. }
  4055. };
  4056. IScroll.utils = utils;
  4057. $.AMUI.iScroll = IScroll;
  4058. module.exports = IScroll;
  4059. /* jshint unused: true */
  4060. /* jshint +W101, +W116, +W109 */
  4061. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4062. },{"2":2}],12:[function(_dereq_,module,exports){
  4063. (function (global){
  4064. 'use strict';
  4065. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  4066. var UI = _dereq_(2);
  4067. var dimmer = _dereq_(8);
  4068. var $doc = $(document);
  4069. var supportTransition = UI.support.transition;
  4070. /**
  4071. * @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
  4072. * @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
  4073. */
  4074. var Modal = function(element, options) {
  4075. this.options = $.extend({}, Modal.DEFAULTS, options || {});
  4076. this.$element = $(element);
  4077. this.$dialog = this.$element.find('.am-modal-dialog');
  4078. if (!this.$element.attr('id')) {
  4079. this.$element.attr('id', UI.utils.generateGUID('am-modal'));
  4080. }
  4081. this.isPopup = this.$element.hasClass('am-popup');
  4082. this.isActions = this.$element.hasClass('am-modal-actions');
  4083. this.isPrompt = this.$element.hasClass('am-modal-prompt');
  4084. this.isLoading = this.$element.hasClass('am-modal-loading');
  4085. this.active = this.transitioning = this.relatedTarget = null;
  4086. this.events();
  4087. };
  4088. Modal.DEFAULTS = {
  4089. className: {
  4090. active: 'am-modal-active',
  4091. out: 'am-modal-out'
  4092. },
  4093. selector: {
  4094. modal: '.am-modal',
  4095. active: '.am-modal-active'
  4096. },
  4097. closeViaDimmer: true,
  4098. cancelable: true,
  4099. onConfirm: function() {
  4100. },
  4101. onCancel: function() {
  4102. },
  4103. height: undefined,
  4104. width: undefined,
  4105. duration: 300, // must equal the CSS transition duration
  4106. transitionEnd: supportTransition && supportTransition.end + '.modal.amui'
  4107. };
  4108. Modal.prototype.toggle = function(relatedTarget) {
  4109. return this.active ? this.close() : this.open(relatedTarget);
  4110. };
  4111. Modal.prototype.open = function(relatedTarget) {
  4112. var $element = this.$element;
  4113. var options = this.options;
  4114. var isPopup = this.isPopup;
  4115. var width = options.width;
  4116. var height = options.height;
  4117. var style = {};
  4118. if (this.active) {
  4119. return;
  4120. }
  4121. if (!this.$element.length) {
  4122. return;
  4123. }
  4124. // callback hook
  4125. relatedTarget && (this.relatedTarget = relatedTarget);
  4126. // 判断如果还在动画,就先触发之前的closed事件
  4127. if (this.transitioning) {
  4128. clearTimeout($element.transitionEndTimmer);
  4129. $element.transitionEndTimmer = null;
  4130. $element.trigger(options.transitionEnd).off(options.transitionEnd);
  4131. }
  4132. isPopup && this.$element.show();
  4133. this.active = true;
  4134. $element.trigger($.Event('open.modal.amui', {relatedTarget: relatedTarget}));
  4135. dimmer.open($element);
  4136. $element.show().redraw();
  4137. // apply Modal width/height if set
  4138. if (!isPopup && !this.isActions) {
  4139. if (width) {
  4140. width = parseInt(width, 10);
  4141. style.width = width + 'px';
  4142. style.marginLeft = -parseInt(width / 2) + 'px';
  4143. }
  4144. if (height) {
  4145. height = parseInt(height, 10);
  4146. // style.height = height + 'px';
  4147. style.marginTop = -parseInt(height / 2) + 'px';
  4148. // the background color is styled to $dialog
  4149. // so the height should set to $dialog
  4150. this.$dialog.css({height: height + 'px'});
  4151. } else {
  4152. style.marginTop = -parseInt($element.height() / 2, 10) + 'px';
  4153. }
  4154. $element.css(style);
  4155. }
  4156. $element.
  4157. removeClass(options.className.out).
  4158. addClass(options.className.active);
  4159. this.transitioning = 1;
  4160. var complete = function() {
  4161. $element.trigger($.Event('opened.modal.amui',
  4162. {relatedTarget: relatedTarget}));
  4163. this.transitioning = 0;
  4164. // Prompt auto focus
  4165. if (this.isPrompt) {
  4166. this.$dialog.find('input').eq(0).focus();
  4167. }
  4168. };
  4169. if (!supportTransition) {
  4170. return complete.call(this);
  4171. }
  4172. $element.
  4173. one(options.transitionEnd, $.proxy(complete, this)).
  4174. emulateTransitionEnd(options.duration);
  4175. };
  4176. Modal.prototype.close = function(relatedTarget) {
  4177. if (!this.active) {
  4178. return;
  4179. }
  4180. var $element = this.$element;
  4181. var options = this.options;
  4182. var isPopup = this.isPopup;
  4183. // 判断如果还在动画,就先触发之前的opened事件
  4184. if (this.transitioning) {
  4185. clearTimeout($element.transitionEndTimmer);
  4186. $element.transitionEndTimmer = null;
  4187. $element.trigger(options.transitionEnd).off(options.transitionEnd);
  4188. dimmer.close($element, true);
  4189. }
  4190. this.$element.trigger($.Event('close.modal.amui',
  4191. {relatedTarget: relatedTarget}));
  4192. this.transitioning = 1;
  4193. var complete = function() {
  4194. $element.trigger('closed.modal.amui');
  4195. isPopup && $element.removeClass(options.className.out);
  4196. $element.hide();
  4197. this.transitioning = 0;
  4198. // 不强制关闭 Dimmer,以便多个 Modal 可以共享 Dimmer
  4199. dimmer.close($element, false);
  4200. this.active = false;
  4201. };
  4202. $element.removeClass(options.className.active).
  4203. addClass(options.className.out);
  4204. if (!supportTransition) {
  4205. return complete.call(this);
  4206. }
  4207. $element.one(options.transitionEnd, $.proxy(complete, this)).
  4208. emulateTransitionEnd(options.duration);
  4209. };
  4210. Modal.prototype.events = function() {
  4211. var that = this;
  4212. var $element = this.$element;
  4213. var $ipt = $element.find('.am-modal-prompt-input');
  4214. var getData = function() {
  4215. var data = [];
  4216. $ipt.each(function() {
  4217. data.push($(this).val());
  4218. });
  4219. return (data.length === 0) ? undefined :
  4220. ((data.length === 1) ? data[0] : data);
  4221. };
  4222. // close via Esc key
  4223. if (this.options.cancelable) {
  4224. $element.on('keyup.modal.amui', function(e) {
  4225. if (that.active && e.which === 27) {
  4226. $element.trigger('cancel.modal.amui');
  4227. that.close();
  4228. }
  4229. });
  4230. }
  4231. // Close Modal when dimmer clicked
  4232. if (this.options.closeViaDimmer && !this.isLoading) {
  4233. dimmer.$element.on('click.dimmer.modal.amui', function(e) {
  4234. that.close();
  4235. });
  4236. }
  4237. // Close Modal when button clicked
  4238. $element.find('[data-am-modal-close], .am-modal-btn').
  4239. on('click.close.modal.amui', function(e) {
  4240. e.preventDefault();
  4241. that.close();
  4242. });
  4243. $element.find('[data-am-modal-confirm]').on('click.confirm.modal.amui',
  4244. function() {
  4245. $element.trigger($.Event('confirm.modal.amui', {
  4246. trigger: this
  4247. }));
  4248. });
  4249. $element.find('[data-am-modal-cancel]').
  4250. on('click.cancel.modal.amui', function() {
  4251. $element.trigger($.Event('cancel.modal.amui', {
  4252. trigger: this
  4253. }));
  4254. });
  4255. $element.on('confirm.modal.amui', function(e) {
  4256. e.data = getData();
  4257. that.options.onConfirm.call(that, e);
  4258. }).on('cancel.modal.amui', function(e) {
  4259. e.data = getData();
  4260. that.options.onCancel.call(that, e);
  4261. });
  4262. };
  4263. function Plugin(option, relatedTarget) {
  4264. return this.each(function() {
  4265. var $this = $(this);
  4266. var data = $this.data('amui.modal');
  4267. var options = $.extend({},
  4268. Modal.DEFAULTS, typeof option == 'object' && option);
  4269. if (!data) {
  4270. $this.data('amui.modal', (data = new Modal(this, options)));
  4271. }
  4272. if (typeof option == 'string') {
  4273. data[option] && data[option](relatedTarget);
  4274. } else {
  4275. data.toggle(option && option.relatedTarget || undefined);
  4276. }
  4277. });
  4278. }
  4279. $.fn.modal = Plugin;
  4280. // Init
  4281. $doc.on('click.modal.amui.data-api', '[data-am-modal]', function() {
  4282. var $this = $(this);
  4283. var options = UI.utils.parseOptions($this.attr('data-am-modal'));
  4284. var $target = $(options.target ||
  4285. (this.href && this.href.replace(/.*(?=#[^\s]+$)/, '')));
  4286. var option = $target.data('amui.modal') ? 'toggle' : options;
  4287. Plugin.call($target, option, this);
  4288. });
  4289. $.AMUI.modal = Modal;
  4290. module.exports = Modal;
  4291. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4292. },{"2":2,"8":8}],13:[function(_dereq_,module,exports){
  4293. (function (global){
  4294. 'use strict';
  4295. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  4296. var UI = _dereq_(2);
  4297. var Hammer = _dereq_(30);
  4298. var $win = $(window);
  4299. var $doc = $(document);
  4300. var scrollPos;
  4301. /**
  4302. * @via https://github.com/uikit/uikit/blob/master/src/js/offcanvas.js
  4303. * @license https://github.com/uikit/uikit/blob/master/LICENSE.md
  4304. */
  4305. var OffCanvas = function(element, options) {
  4306. this.$element = $(element);
  4307. this.options = $.extend({}, OffCanvas.DEFAULTS, options);
  4308. this.active = null;
  4309. this.bindEvents();
  4310. };
  4311. OffCanvas.DEFAULTS = {
  4312. duration: 300,
  4313. effect: 'overlay' // {push|overlay}, push is too expensive
  4314. };
  4315. OffCanvas.prototype.open = function(relatedElement) {
  4316. var _this = this;
  4317. var $element = this.$element;
  4318. if (!$element.length || $element.hasClass('am-active')) {
  4319. return;
  4320. }
  4321. var effect = this.options.effect;
  4322. var $html = $('html');
  4323. var $body = $('body');
  4324. var $bar = $element.find('.am-offcanvas-bar').first();
  4325. var dir = $bar.hasClass('am-offcanvas-bar-flip') ? -1 : 1;
  4326. $bar.addClass('am-offcanvas-bar-' + effect);
  4327. scrollPos = {x: window.scrollX, y: window.scrollY};
  4328. $element.addClass('am-active');
  4329. $body.css({
  4330. width: window.innerWidth,
  4331. height: $win.height()
  4332. }).addClass('am-offcanvas-page');
  4333. if (effect !== 'overlay') {
  4334. $body.css({
  4335. 'margin-left': $bar.outerWidth() * dir
  4336. }).width(); // force redraw
  4337. }
  4338. $html.css('margin-top', scrollPos.y * -1);
  4339. setTimeout(function() {
  4340. $bar.addClass('am-offcanvas-bar-active').width();
  4341. }, 0);
  4342. $element.trigger('open.offcanvas.amui');
  4343. this.active = 1;
  4344. // Close OffCanvas when none content area clicked
  4345. $element.on('click.offcanvas.amui', function(e) {
  4346. var $target = $(e.target);
  4347. if ($target.hasClass('am-offcanvas-bar')) {
  4348. return;
  4349. }
  4350. if ($target.parents('.am-offcanvas-bar').first().length) {
  4351. return;
  4352. }
  4353. // https://developer.mozilla.org/zh-CN/docs/DOM/event.stopImmediatePropagation
  4354. e.stopImmediatePropagation();
  4355. _this.close();
  4356. });
  4357. $html.on('keydown.offcanvas.amui', function(e) {
  4358. (e.keyCode === 27) && _this.close();
  4359. });
  4360. };
  4361. OffCanvas.prototype.close = function(relatedElement) {
  4362. var _this = this;
  4363. var $html = $('html');
  4364. var $body = $('body');
  4365. var $element = this.$element;
  4366. var $bar = $element.find('.am-offcanvas-bar').first();
  4367. if (!$element.length || !this.active || !$element.hasClass('am-active')) {
  4368. return;
  4369. }
  4370. $element.trigger('close.offcanvas.amui');
  4371. function complete() {
  4372. $body.removeClass('am-offcanvas-page').
  4373. css({width: '', height: '', 'margin-left': '', 'margin-right': ''});
  4374. $element.removeClass('am-active');
  4375. $bar.removeClass('am-offcanvas-bar-active');
  4376. $html.css('margin-top', '');
  4377. window.scrollTo(scrollPos.x, scrollPos.y);
  4378. $element.trigger('closed.offcanvas.amui');
  4379. _this.active = 0;
  4380. }
  4381. if (UI.support.transition) {
  4382. setTimeout(function() {
  4383. $bar.removeClass('am-offcanvas-bar-active');
  4384. }, 0);
  4385. $body.css('margin-left', '').one(UI.support.transition.end, function() {
  4386. complete();
  4387. }).emulateTransitionEnd(this.options.duration);
  4388. } else {
  4389. complete();
  4390. }
  4391. $element.off('click.offcanvas.amui');
  4392. $html.off('.offcanvas.amui');
  4393. };
  4394. OffCanvas.prototype.bindEvents = function() {
  4395. var _this = this;
  4396. $doc.on('click.offcanvas.amui', '[data-am-dismiss="offcanvas"]', function(e) {
  4397. e.preventDefault();
  4398. _this.close();
  4399. });
  4400. $win.on('resize.offcanvas.amui orientationchange.offcanvas.amui',
  4401. function() {
  4402. _this.active && _this.close();
  4403. });
  4404. this.$element.hammer().on('swipeleft swipeleft', function(e) {
  4405. e.preventDefault();
  4406. _this.close();
  4407. });
  4408. return this;
  4409. };
  4410. function Plugin(option, relatedElement) {
  4411. return this.each(function() {
  4412. var $this = $(this);
  4413. var data = $this.data('amui.offcanvas');
  4414. var options = $.extend({}, typeof option == 'object' && option);
  4415. if (!data) {
  4416. $this.data('amui.offcanvas', (data = new OffCanvas(this, options)));
  4417. (!option || typeof option == 'object') && data.open(relatedElement);
  4418. }
  4419. if (typeof option == 'string') {
  4420. data[option] && data[option](relatedElement);
  4421. }
  4422. });
  4423. }
  4424. $.fn.offCanvas = Plugin;
  4425. // Init code
  4426. $doc.on('click.offcanvas.amui', '[data-am-offcanvas]', function(e) {
  4427. e.preventDefault();
  4428. var $this = $(this);
  4429. var options = UI.utils.parseOptions($this.data('amOffcanvas'));
  4430. var $target = $(options.target ||
  4431. (this.href && this.href.replace(/.*(?=#[^\s]+$)/, '')));
  4432. var option = $target.data('amui.offcanvas') ? 'open' : options;
  4433. Plugin.call($target, option, this);
  4434. });
  4435. $.AMUI.offcanvas = OffCanvas;
  4436. module.exports = OffCanvas;
  4437. // TODO: 优化动画效果
  4438. // http://dbushell.github.io/Responsive-Off-Canvas-Menu/step4.html
  4439. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  4440. },{"2":2,"30":30}],14:[function(_dereq_,module,exports){
  4441. (function (global){
  4442. 'use strict';
  4443. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  4444. var UI = _dereq_(2);
  4445. /**
  4446. * @via https://github.com/manuelstofer/pinchzoom/blob/master/src/pinchzoom.js
  4447. * @license the MIT License.
  4448. */
  4449. var definePinchZoom = function($) {
  4450. /**
  4451. * Pinch zoom using jQuery
  4452. * @version 0.0.2
  4453. * @author Manuel Stofer <mst@rtp.ch>
  4454. * @param el
  4455. * @param options
  4456. * @constructor
  4457. */
  4458. var PinchZoom = function(el, options) {
  4459. this.el = $(el);
  4460. this.zoomFactor = 1;
  4461. this.lastScale = 1;
  4462. this.offset = {
  4463. x: 0,
  4464. y: 0
  4465. };
  4466. this.options = $.extend({}, this.defaults, options);
  4467. this.setupMarkup();
  4468. this.bindEvents();
  4469. this.update();
  4470. // default enable.
  4471. this.enable();
  4472. },
  4473. sum = function(a, b) {
  4474. return a + b;
  4475. },
  4476. isCloseTo = function(value, expected) {
  4477. return value > expected - 0.01 && value < expected + 0.01;
  4478. };
  4479. PinchZoom.prototype = {
  4480. defaults: {
  4481. tapZoomFactor: 2,
  4482. zoomOutFactor: 1.3,
  4483. animationDuration: 300,
  4484. animationInterval: 5,
  4485. maxZoom: 5,
  4486. minZoom: 0.5,
  4487. lockDragAxis: false,
  4488. use2d: false,
  4489. zoomStartEventName: 'pz_zoomstart',
  4490. zoomEndEventName: 'pz_zoomend',
  4491. dragStartEventName: 'pz_dragstart',
  4492. dragEndEventName: 'pz_dragend',
  4493. doubleTapEventName: 'pz_doubletap'
  4494. },
  4495. /**
  4496. * Event handler for 'dragstart'
  4497. * @param event
  4498. */
  4499. handleDragStart: function(event) {
  4500. this.el.trigger(this.options.dragStartEventName);
  4501. this.stopAnimation();
  4502. this.lastDragPosition = false;
  4503. this.hasInteraction = true;
  4504. this.handleDrag(event);
  4505. },
  4506. /**
  4507. * Event handler for 'drag'
  4508. * @param event
  4509. */
  4510. handleDrag: function(event) {
  4511. if (this.zoomFactor > 1.0) {
  4512. var touch = this.getTouches(event)[0];
  4513. this.drag(touch, this.lastDragPosition);
  4514. this.offset = this.sanitizeOffset(this.offset);
  4515. this.lastDragPosition = touch;
  4516. }
  4517. },
  4518. handleDragEnd: function() {
  4519. this.el.trigger(this.options.dragEndEventName);
  4520. this.end();
  4521. },
  4522. /**
  4523. * Event handler for 'zoomstart'
  4524. * @param event
  4525. */
  4526. handleZoomStart: function(event) {
  4527. this.el.trigger(this.options.zoomStartEventName);
  4528. this.stopAnimation();
  4529. this.lastScale = 1;
  4530. this.nthZoom = 0;
  4531. this.lastZoomCenter = false;
  4532. this.hasInteraction = true;
  4533. },
  4534. /**
  4535. * Event handler for 'zoom'
  4536. * @param event
  4537. */
  4538. handleZoom: function(event, newScale) {
  4539. // a relative scale factor is used
  4540. var touchCenter = this.getTouchCenter(this.getTouches(event)),
  4541. scale = newScale / this.lastScale;
  4542. this.lastScale = newScale;
  4543. // the first touch events are thrown away since they are not precise
  4544. this.nthZoom += 1;
  4545. if (this.nthZoom > 3) {
  4546. this.scale(scale, touchCenter);
  4547. this.drag(touchCenter, this.lastZoomCenter);
  4548. }
  4549. this.lastZoomCenter = touchCenter;
  4550. },
  4551. handleZoomEnd: function() {
  4552. this.el.trigger(this.options.zoomEndEventName);
  4553. this.end();
  4554. },
  4555. /**
  4556. * Event handler for 'doubletap'
  4557. * @param event
  4558. */
  4559. handleDoubleTap: function(event) {
  4560. var center = this.getTouches(event)[0],
  4561. zoomFactor = this.zoomFactor > 1 ? 1 : this.options.tapZoomFactor,
  4562. startZoomFactor = this.zoomFactor,
  4563. updateProgress = (function(progress) {
  4564. this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center);
  4565. }).bind(this);
  4566. if (this.hasInteraction) {
  4567. return;
  4568. }
  4569. if (startZoomFactor > zoomFactor) {
  4570. center = this.getCurrentZoomCenter();
  4571. }
  4572. this.animate(this.options.animationDuration, this.options.animationInterval, updateProgress, this.swing);
  4573. this.el.trigger(this.options.doubleTapEventName);
  4574. },
  4575. /**
  4576. * Max / min values for the offset
  4577. * @param offset
  4578. * @return {Object} the sanitized offset
  4579. */
  4580. sanitizeOffset: function(offset) {
  4581. var maxX = (this.zoomFactor - 1) * this.getContainerX(),
  4582. maxY = (this.zoomFactor - 1) * this.getContainerY(),
  4583. maxOffsetX = Math.max(maxX, 0),
  4584. maxOffsetY = Math.max(maxY, 0),
  4585. minOffsetX = Math.min(maxX, 0),
  4586. minOffsetY = Math.min(maxY, 0);
  4587. return {
  4588. x: Math.min(Math.max(offset.x, minOffsetX), maxOffsetX),
  4589. y: Math.min(Math.max(offset.y, minOffsetY), maxOffsetY)
  4590. };
  4591. },
  4592. /**
  4593. * Scale to a specific zoom factor (not relative)
  4594. * @param zoomFactor
  4595. * @param center
  4596. */
  4597. scaleTo: function(zoomFactor, center) {
  4598. this.scale(zoomFactor / this.zoomFactor, center);
  4599. },
  4600. /**
  4601. * Scales the element from specified center
  4602. * @param scale
  4603. * @param center
  4604. */
  4605. scale: function(scale, center) {
  4606. scale = this.scaleZoomFactor(scale);
  4607. this.addOffset({
  4608. x: (scale - 1) * (center.x + this.offset.x),
  4609. y: (scale - 1) * (center.y + this.offset.y)
  4610. });
  4611. },
  4612. /**
  4613. * Scales the zoom factor relative to current state
  4614. * @param scale
  4615. * @return the actual scale (can differ because of max min zoom factor)
  4616. */
  4617. scaleZoomFactor: function(scale) {
  4618. var originalZoomFactor = this.zoomFactor;
  4619. this.zoomFactor *= scale;
  4620. this.zoomFactor = Math.min(this.options.maxZoom, Math.max(this.zoomFactor, this.options.minZoom));
  4621. return this.zoomFactor / originalZoomFactor;
  4622. },
  4623. /**
  4624. * Drags the element
  4625. * @param center
  4626. * @param lastCenter
  4627. */
  4628. drag: function(center, lastCenter) {
  4629. if (lastCenter) {
  4630. if (this.options.lockDragAxis) {
  4631. // lock scroll to position that was changed the most
  4632. if (Math.abs(center.x - lastCenter.x) > Math.abs(center.y - lastCenter.y)) {
  4633. this.addOffset({
  4634. x: -(center.x - lastCenter.x),
  4635. y: 0
  4636. });
  4637. }
  4638. else {
  4639. this.addOffset({
  4640. y: -(center.y - lastCenter.y),
  4641. x: 0
  4642. });
  4643. }
  4644. }
  4645. else {
  4646. this.addOffset({
  4647. y: -(center.y - lastCenter.y),
  4648. x: -(center.x - lastCenter.x)
  4649. });
  4650. }
  4651. }
  4652. },
  4653. /**
  4654. * Calculates the touch center of multiple touches
  4655. * @param touches
  4656. * @return {Object}
  4657. */
  4658. getTouchCenter: function(touches) {
  4659. return this.getVectorAvg(touches);
  4660. },
  4661. /**
  4662. * Calculates the average of multiple vectors (x, y values)
  4663. */
  4664. getVectorAvg: function(vectors) {
  4665. return {
  4666. x: vectors.map(function(v) {
  4667. return v.x;
  4668. }).reduce(sum) / vectors.length,
  4669. y: vectors.map(function(v) {
  4670. return v.y;
  4671. }).reduce(sum) / vectors.length
  4672. };
  4673. },
  4674. /**
  4675. * Adds an offset
  4676. * @param offset the offset to add
  4677. * @return return true when the offset change was accepted
  4678. */
  4679. addOffset: function(offset) {
  4680. this.offset = {
  4681. x: this.offset.x + offset.x,
  4682. y: this.offset.y + offset.y
  4683. };
  4684. },
  4685. sanitize: function() {
  4686. if (this.zoomFactor < this.options.zoomOutFactor) {
  4687. this.zoomOutAnimation();
  4688. } else if (this.isInsaneOffset(this.offset)) {
  4689. this.sanitizeOffsetAnimation();
  4690. }
  4691. },
  4692. /**
  4693. * Checks if the offset is ok with the current zoom factor
  4694. * @param offset
  4695. * @return {Boolean}
  4696. */
  4697. isInsaneOffset: function(offset) {
  4698. var sanitizedOffset = this.sanitizeOffset(offset);
  4699. return sanitizedOffset.x !== offset.x ||
  4700. sanitizedOffset.y !== offset.y;
  4701. },
  4702. /**
  4703. * Creates an animation moving to a sane offset
  4704. */
  4705. sanitizeOffsetAnimation: function() {
  4706. var targetOffset = this.sanitizeOffset(this.offset),
  4707. startOffset = {
  4708. x: this.offset.x,
  4709. y: this.offset.y
  4710. },
  4711. updateProgress = (function(progress) {
  4712. this.offset.x = startOffset.x + progress * (targetOffset.x - startOffset.x);
  4713. this.offset.y = startOffset.y + progress * (targetOffset.y - startOffset.y);
  4714. this.update();
  4715. }).bind(this);
  4716. this.animate(
  4717. this.options.animationDuration,
  4718. this.options.animationInterval,
  4719. updateProgress,
  4720. this.swing
  4721. );
  4722. },
  4723. /**
  4724. * Zooms back to the original position,
  4725. * (no offset and zoom factor 1)
  4726. */
  4727. zoomOutAnimation: function() {
  4728. var startZoomFactor = this.zoomFactor,
  4729. zoomFactor = 1,
  4730. center = this.getCurrentZoomCenter(),
  4731. updateProgress = (function(progress) {
  4732. this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center);
  4733. }).bind(this);
  4734. this.animate(
  4735. this.options.animationDuration,
  4736. this.options.animationInterval,
  4737. updateProgress,
  4738. this.swing
  4739. );
  4740. },
  4741. /**
  4742. * Updates the aspect ratio
  4743. */
  4744. updateAspectRatio: function() {
  4745. // this.setContainerY(this.getContainerX() / this.getAspectRatio());
  4746. // @modified
  4747. this.setContainerY()
  4748. },
  4749. /**
  4750. * Calculates the initial zoom factor (for the element to fit into the container)
  4751. * @return the initial zoom factor
  4752. */
  4753. getInitialZoomFactor: function() {
  4754. // use .offsetWidth instead of width()
  4755. // because jQuery-width() return the original width but Zepto-width() will calculate width with transform.
  4756. // the same as .height()
  4757. return this.container[0].offsetWidth / this.el[0].offsetWidth;
  4758. },
  4759. /**
  4760. * Calculates the aspect ratio of the element
  4761. * @return the aspect ratio
  4762. */
  4763. getAspectRatio: function() {
  4764. return this.el[0].offsetWidth / this.el[0].offsetHeight;
  4765. },
  4766. /**
  4767. * Calculates the virtual zoom center for the current offset and zoom factor
  4768. * (used for reverse zoom)
  4769. * @return {Object} the current zoom center
  4770. */
  4771. getCurrentZoomCenter: function() {
  4772. // uses following formula to calculate the zoom center x value
  4773. // offset_left / offset_right = zoomcenter_x / (container_x - zoomcenter_x)
  4774. var length = this.container[0].offsetWidth * this.zoomFactor,
  4775. offsetLeft = this.offset.x,
  4776. offsetRight = length - offsetLeft - this.container[0].offsetWidth,
  4777. widthOffsetRatio = offsetLeft / offsetRight,
  4778. centerX = widthOffsetRatio * this.container[0].offsetWidth / (widthOffsetRatio + 1),
  4779. // the same for the zoomcenter y
  4780. height = this.container[0].offsetHeight * this.zoomFactor,
  4781. offsetTop = this.offset.y,
  4782. offsetBottom = height - offsetTop - this.container[0].offsetHeight,
  4783. heightOffsetRatio = offsetTop / offsetBottom,
  4784. centerY = heightOffsetRatio * this.container[0].offsetHeight / (heightOffsetRatio + 1);
  4785. // prevents division by zero
  4786. if (offsetRight === 0) {
  4787. centerX = this.container[0].offsetWidth;
  4788. }
  4789. if (offsetBottom === 0) {
  4790. centerY = this.container[0].offsetHeight;
  4791. }
  4792. return {
  4793. x: centerX,
  4794. y: centerY
  4795. };
  4796. },
  4797. canDrag: function() {
  4798. return !isCloseTo(this.zoomFactor, 1);
  4799. },
  4800. /**
  4801. * Returns the touches of an event relative to the container offset
  4802. * @param event
  4803. * @return array touches
  4804. */
  4805. getTouches: function(event) {
  4806. var position = this.container.offset();
  4807. return Array.prototype.slice.call(event.touches).map(function(touch) {
  4808. return {
  4809. x: touch.pageX - position.left,
  4810. y: touch.pageY - position.top
  4811. };
  4812. });
  4813. },
  4814. /**
  4815. * Animation loop
  4816. * does not support simultaneous animations
  4817. * @param duration
  4818. * @param interval
  4819. * @param framefn
  4820. * @param timefn
  4821. * @param callback
  4822. */
  4823. animate: function(duration, interval, framefn, timefn, callback) {
  4824. var startTime = new Date().getTime(),
  4825. renderFrame = (function() {
  4826. if (!this.inAnimation) {
  4827. return;
  4828. }
  4829. var frameTime = new Date().getTime() - startTime,
  4830. progress = frameTime / duration;
  4831. if (frameTime >= duration) {
  4832. framefn(1);
  4833. if (callback) {
  4834. callback();
  4835. }
  4836. this.update();
  4837. this.stopAnimation();
  4838. this.update();
  4839. } else {
  4840. if (timefn) {
  4841. progress = timefn(progress);
  4842. }
  4843. framefn(progress);
  4844. this.update();
  4845. setTimeout(renderFrame, interval);
  4846. }
  4847. }).bind(this);
  4848. this.inAnimation = true;
  4849. renderFrame();
  4850. },
  4851. /**
  4852. * Stops the animation
  4853. */
  4854. stopAnimation: function() {
  4855. this.inAnimation = false;
  4856. },
  4857. /**
  4858. * Swing timing function for animations
  4859. * @param p
  4860. * @return {Number}
  4861. */
  4862. swing: function(p) {
  4863. return -Math.cos(p * Math.PI) / 2 + 0.5;
  4864. },
  4865. getContainerX: function() {
  4866. // return this.container[0].offsetWidth;
  4867. // @modified
  4868. return window.innerWidth
  4869. },
  4870. getContainerY: function() {
  4871. // return this.container[0].offsetHeight;
  4872. // @modified
  4873. return window.innerHeight
  4874. },
  4875. setContainerY: function(y) {
  4876. // return this.container.height(y);
  4877. // @modified
  4878. var t = window.innerHeight;
  4879. return this.el.css({height: t}), this.container.height(t);
  4880. },
  4881. /**
  4882. * Creates the expected html structure
  4883. */
  4884. setupMarkup: function() {
  4885. this.container = $('<div class="pinch-zoom-container"></div>');
  4886. this.el.before(this.container);
  4887. this.container.append(this.el);
  4888. this.container.css({
  4889. 'overflow': 'hidden',
  4890. 'position': 'relative'
  4891. });
  4892. // Zepto doesn't recognize `webkitTransform..` style
  4893. this.el.css({
  4894. '-webkit-transform-origin': '0% 0%',
  4895. '-moz-transform-origin': '0% 0%',
  4896. '-ms-transform-origin': '0% 0%',
  4897. '-o-transform-origin': '0% 0%',
  4898. 'transform-origin': '0% 0%',
  4899. 'position': 'absolute'
  4900. });
  4901. },
  4902. end: function() {
  4903. this.hasInteraction = false;
  4904. this.sanitize();
  4905. this.update();
  4906. },
  4907. /**
  4908. * Binds all required event listeners
  4909. */
  4910. bindEvents: function() {
  4911. detectGestures(this.container.get(0), this);
  4912. // Zepto and jQuery both know about `on`
  4913. $(window).on('resize', this.update.bind(this));
  4914. $(this.el).find('img').on('load', this.update.bind(this));
  4915. },
  4916. /**
  4917. * Updates the css values according to the current zoom factor and offset
  4918. */
  4919. update: function() {
  4920. if (this.updatePlaned) {
  4921. return;
  4922. }
  4923. this.updatePlaned = true;
  4924. setTimeout((function() {
  4925. this.updatePlaned = false;
  4926. this.updateAspectRatio();
  4927. var zoomFactor = this.getInitialZoomFactor() * this.zoomFactor,
  4928. offsetX = -this.offset.x / zoomFactor,
  4929. offsetY = -this.offset.y / zoomFactor,
  4930. transform3d = 'scale3d(' + zoomFactor + ', ' + zoomFactor + ',1) ' +
  4931. 'translate3d(' + offsetX + 'px,' + offsetY + 'px,0px)',
  4932. transform2d = 'scale(' + zoomFactor + ', ' + zoomFactor + ') ' +
  4933. 'translate(' + offsetX + 'px,' + offsetY + 'px)',
  4934. removeClone = (function() {
  4935. if (this.clone) {
  4936. this.clone.remove();
  4937. delete this.clone;
  4938. }
  4939. }).bind(this);
  4940. // Scale 3d and translate3d are faster (at least on ios)
  4941. // but they also reduce the quality.
  4942. // PinchZoom uses the 3d transformations during interactions
  4943. // after interactions it falls back to 2d transformations
  4944. if (!this.options.use2d || this.hasInteraction || this.inAnimation) {
  4945. this.is3d = true;
  4946. removeClone();
  4947. this.el.css({
  4948. '-webkit-transform': transform3d,
  4949. '-o-transform': transform2d,
  4950. '-ms-transform': transform2d,
  4951. '-moz-transform': transform2d,
  4952. 'transform': transform3d
  4953. });
  4954. } else {
  4955. // When changing from 3d to 2d transform webkit has some glitches.
  4956. // To avoid this, a copy of the 3d transformed element is displayed in the
  4957. // foreground while the element is converted from 3d to 2d transform
  4958. if (this.is3d) {
  4959. this.clone = this.el.clone();
  4960. this.clone.css('pointer-events', 'none');
  4961. this.clone.appendTo(this.container);
  4962. setTimeout(removeClone, 200);
  4963. }
  4964. this.el.css({
  4965. '-webkit-transform': transform2d,
  4966. '-o-transform': transform2d,
  4967. '-ms-transform': transform2d,
  4968. '-moz-transform': transform2d,
  4969. 'transform': transform2d
  4970. });
  4971. this.is3d = false;
  4972. }
  4973. }).bind(this), 0);
  4974. },
  4975. /**
  4976. * Enables event handling for gestures
  4977. */
  4978. enable: function() {
  4979. this.enabled = true;
  4980. },
  4981. /**
  4982. * Disables event handling for gestures
  4983. */
  4984. disable: function() {
  4985. this.enabled = false;
  4986. }
  4987. };
  4988. var detectGestures = function(el, target) {
  4989. var interaction = null,
  4990. fingers = 0,
  4991. lastTouchStart = null,
  4992. startTouches = null,
  4993. setInteraction = function(newInteraction, event) {
  4994. if (interaction !== newInteraction) {
  4995. if (interaction && !newInteraction) {
  4996. switch (interaction) {
  4997. case "zoom":
  4998. target.handleZoomEnd(event);
  4999. break;
  5000. case 'drag':
  5001. target.handleDragEnd(event);
  5002. break;
  5003. }
  5004. }
  5005. switch (newInteraction) {
  5006. case 'zoom':
  5007. target.handleZoomStart(event);
  5008. break;
  5009. case 'drag':
  5010. target.handleDragStart(event);
  5011. break;
  5012. }
  5013. }
  5014. interaction = newInteraction;
  5015. },
  5016. updateInteraction = function(event) {
  5017. if (fingers === 2) {
  5018. setInteraction('zoom');
  5019. } else if (fingers === 1 && target.canDrag()) {
  5020. setInteraction('drag', event);
  5021. } else {
  5022. setInteraction(null, event);
  5023. }
  5024. },
  5025. targetTouches = function(touches) {
  5026. return Array.prototype.slice.call(touches).map(function(touch) {
  5027. return {
  5028. x: touch.pageX,
  5029. y: touch.pageY
  5030. };
  5031. });
  5032. },
  5033. getDistance = function(a, b) {
  5034. var x, y;
  5035. x = a.x - b.x;
  5036. y = a.y - b.y;
  5037. return Math.sqrt(x * x + y * y);
  5038. },
  5039. calculateScale = function(startTouches, endTouches) {
  5040. var startDistance = getDistance(startTouches[0], startTouches[1]),
  5041. endDistance = getDistance(endTouches[0], endTouches[1]);
  5042. return endDistance / startDistance;
  5043. },
  5044. cancelEvent = function(event) {
  5045. event.stopPropagation();
  5046. event.preventDefault();
  5047. },
  5048. detectDoubleTap = function(event) {
  5049. var time = (new Date()).getTime();
  5050. if (fingers > 1) {
  5051. lastTouchStart = null;
  5052. }
  5053. if (time - lastTouchStart < 300) {
  5054. cancelEvent(event);
  5055. target.handleDoubleTap(event);
  5056. switch (interaction) {
  5057. case "zoom":
  5058. target.handleZoomEnd(event);
  5059. break;
  5060. case 'drag':
  5061. target.handleDragEnd(event);
  5062. break;
  5063. }
  5064. }
  5065. if (fingers === 1) {
  5066. lastTouchStart = time;
  5067. }
  5068. },
  5069. firstMove = true;
  5070. el.addEventListener('touchstart', function(event) {
  5071. if (target.enabled) {
  5072. firstMove = true;
  5073. fingers = event.touches.length;
  5074. detectDoubleTap(event);
  5075. }
  5076. });
  5077. el.addEventListener('touchmove', function(event) {
  5078. if (target.enabled) {
  5079. if (firstMove) {
  5080. updateInteraction(event);
  5081. if (interaction) {
  5082. cancelEvent(event);
  5083. }
  5084. startTouches = targetTouches(event.touches);
  5085. } else {
  5086. switch (interaction) {
  5087. case 'zoom':
  5088. target.handleZoom(event, calculateScale(startTouches, targetTouches(event.touches)));
  5089. break;
  5090. case 'drag':
  5091. target.handleDrag(event);
  5092. break;
  5093. }
  5094. if (interaction) {
  5095. cancelEvent(event);
  5096. target.update();
  5097. }
  5098. }
  5099. firstMove = false;
  5100. }
  5101. });
  5102. el.addEventListener('touchend', function(event) {
  5103. if (target.enabled) {
  5104. fingers = event.touches.length;
  5105. updateInteraction(event);
  5106. }
  5107. });
  5108. };
  5109. return PinchZoom;
  5110. };
  5111. $.AMUI.pichzoom = definePinchZoom($);
  5112. module.exports = definePinchZoom($);
  5113. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5114. },{"2":2}],15:[function(_dereq_,module,exports){
  5115. (function (global){
  5116. 'use strict';
  5117. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  5118. var UI = _dereq_(2);
  5119. var $w = $(window);
  5120. /**
  5121. * @reference https://github.com/nolimits4web/Framework7/blob/master/src/js/modals.js
  5122. * @license https://github.com/nolimits4web/Framework7/blob/master/LICENSE
  5123. */
  5124. var Popover = function(element, options) {
  5125. this.options = $.extend({}, Popover.DEFAULTS, options || {});
  5126. this.$element = $(element);
  5127. this.active = null;
  5128. this.$popover = (this.options.target && $(this.options.target)) || null;
  5129. this.init();
  5130. this.events();
  5131. };
  5132. Popover.DEFAULTS = {
  5133. theme: undefined,
  5134. trigger: 'click',
  5135. content: '',
  5136. open: false,
  5137. target: undefined,
  5138. tpl: '<div class="am-popover">' +
  5139. '<div class="am-popover-inner"></div>' +
  5140. '<div class="am-popover-caret"></div></div>'
  5141. };
  5142. Popover.prototype.init = function() {
  5143. var me = this;
  5144. var $element = this.$element;
  5145. var $popover;
  5146. if (!this.options.target) {
  5147. this.$popover = this.getPopover();
  5148. this.setContent();
  5149. }
  5150. $popover = this.$popover;
  5151. $popover.appendTo($('body'));
  5152. this.sizePopover();
  5153. function sizePopover() {
  5154. me.sizePopover();
  5155. }
  5156. // TODO: 监听页面内容变化,重新调整位置
  5157. $element.on('open.popover.amui', function() {
  5158. $(window).on('resize.popover.amui', UI.utils.debounce(sizePopover, 50));
  5159. });
  5160. $element.on('close.popover.amui', function() {
  5161. $(window).off('resize.popover.amui', sizePopover);
  5162. });
  5163. this.options.open && this.open();
  5164. };
  5165. Popover.prototype.sizePopover = function sizePopover() {
  5166. var $element = this.$element;
  5167. var $popover = this.$popover;
  5168. if (!$popover || !$popover.length) {
  5169. return;
  5170. }
  5171. var popWidth = $popover.outerWidth();
  5172. var popHeight = $popover.outerHeight();
  5173. var $popCaret = $popover.find('.am-popover-caret');
  5174. var popCaretSize = ($popCaret.outerWidth() / 2) || 8;
  5175. // 取不到 $popCaret.outerHeight() 的值,所以直接加 8
  5176. var popTotalHeight = popHeight + 8; // $popCaret.outerHeight();
  5177. var triggerWidth = $element.outerWidth();
  5178. var triggerHeight = $element.outerHeight();
  5179. var triggerOffset = $element.offset();
  5180. var triggerRect = $element[0].getBoundingClientRect();
  5181. var winHeight = $w.height();
  5182. var winWidth = $w.width();
  5183. var popTop = 0;
  5184. var popLeft = 0;
  5185. var diff = 0;
  5186. var spacing = 2;
  5187. var popPosition = 'top';
  5188. $popover.css({left: '', top: ''}).removeClass('am-popover-left ' +
  5189. 'am-popover-right am-popover-top am-popover-bottom');
  5190. // $popCaret.css({left: '', top: ''});
  5191. if (popTotalHeight - spacing < triggerRect.top + spacing) {
  5192. // Popover on the top of trigger
  5193. popTop = triggerOffset.top - popTotalHeight - spacing;
  5194. } else if (popTotalHeight <
  5195. winHeight - triggerRect.top - triggerRect.height) {
  5196. // On bottom
  5197. popPosition = 'bottom';
  5198. popTop = triggerOffset.top + triggerHeight + popCaretSize + spacing;
  5199. } else { // On middle
  5200. popPosition = 'middle';
  5201. popTop = triggerHeight / 2 + triggerOffset.top - popHeight / 2;
  5202. }
  5203. // Horizontal Position
  5204. if (popPosition === 'top' || popPosition === 'bottom') {
  5205. popLeft = triggerWidth / 2 + triggerOffset.left - popWidth / 2;
  5206. diff = popLeft;
  5207. if (popLeft < 5) {
  5208. popLeft = 5;
  5209. }
  5210. if (popLeft + popWidth > winWidth) {
  5211. popLeft = (winWidth - popWidth - 20);
  5212. // console.log('left %d, win %d, popw %d', popLeft, winWidth, popWidth);
  5213. }
  5214. if (popPosition === 'top') {
  5215. // This is the Popover position, NOT caret position
  5216. // Popover on the Top of trigger, caret on the bottom of Popover
  5217. $popover.addClass('am-popover-top');
  5218. }
  5219. if (popPosition === 'bottom') {
  5220. $popover.addClass('am-popover-bottom');
  5221. }
  5222. diff = diff - popLeft;
  5223. // $popCaret.css({left: (popWidth / 2 - popCaretSize + diff) + 'px'});
  5224. } else if (popPosition === 'middle') {
  5225. popLeft = triggerOffset.left - popWidth - popCaretSize;
  5226. $popover.addClass('am-popover-left');
  5227. if (popLeft < 5) {
  5228. popLeft = triggerOffset.left + triggerWidth + popCaretSize;
  5229. $popover.removeClass('am-popover-left').addClass('am-popover-right');
  5230. }
  5231. if (popLeft + popWidth > winWidth) {
  5232. popLeft = winWidth - popWidth - 5;
  5233. $popover.removeClass('am-popover-left').addClass('am-popover-right');
  5234. }
  5235. // $popCaret.css({top: (popHeight / 2 - popCaretSize / 2) + 'px'});
  5236. }
  5237. // Apply position style
  5238. $popover.css({top: popTop + 'px', left: popLeft + 'px'});
  5239. };
  5240. Popover.prototype.toggle = function() {
  5241. return this[this.active ? 'close' : 'open']();
  5242. };
  5243. Popover.prototype.open = function() {
  5244. var $popover = this.$popover;
  5245. this.$element.trigger('open.popover.amui');
  5246. this.sizePopover();
  5247. $popover.show().addClass('am-active');
  5248. this.active = true;
  5249. };
  5250. Popover.prototype.close = function() {
  5251. var $popover = this.$popover;
  5252. this.$element.trigger('close.popover.amui');
  5253. $popover.
  5254. removeClass('am-active').
  5255. trigger('closed.popover.amui').
  5256. hide();
  5257. this.active = false;
  5258. };
  5259. Popover.prototype.getPopover = function() {
  5260. var uid = UI.utils.generateGUID('am-popover');
  5261. var theme = [];
  5262. if (this.options.theme) {
  5263. $.each(this.options.theme.split(','), function(i, item) {
  5264. theme.push('am-popover-' + $.trim(item));
  5265. });
  5266. }
  5267. return $(this.options.tpl).attr('id', uid).addClass(theme.join(' '));
  5268. };
  5269. Popover.prototype.setContent = function(content) {
  5270. content = content || this.options.content;
  5271. this.$popover && this.$popover.find('.am-popover-inner').empty().
  5272. html(content);
  5273. };
  5274. Popover.prototype.events = function() {
  5275. var eventNS = 'popover.amui';
  5276. var triggers = this.options.trigger.split(' ');
  5277. for (var i = triggers.length; i--;) {
  5278. var trigger = triggers[i];
  5279. if (trigger === 'click') {
  5280. this.$element.on('click.' + eventNS, $.proxy(this.toggle, this));
  5281. } else { // hover or focus
  5282. var eventIn = trigger == 'hover' ? 'mouseenter' : 'focusin';
  5283. var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout';
  5284. this.$element.on(eventIn + '.' + eventNS, $.proxy(this.open, this));
  5285. this.$element.on(eventOut + '.' + eventNS, $.proxy(this.close, this));
  5286. }
  5287. }
  5288. };
  5289. function Plugin(option) {
  5290. return this.each(function() {
  5291. var $this = $(this);
  5292. var data = $this.data('amui.popover');
  5293. var options = $.extend({},
  5294. UI.utils.parseOptions($this.attr('data-am-popover')),
  5295. typeof option == 'object' && option);
  5296. if (!data) {
  5297. $this.data('amui.popover', (data = new Popover(this, options)));
  5298. }
  5299. if (typeof option == 'string') {
  5300. data[option] && data[option]();
  5301. }
  5302. });
  5303. }
  5304. $.fn.popover = Plugin;
  5305. // Init code
  5306. UI.ready(function(context) {
  5307. $('[data-am-popover]', context).popover();
  5308. });
  5309. $.AMUI.popover = Popover;
  5310. module.exports = Popover;
  5311. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5312. },{"2":2}],16:[function(_dereq_,module,exports){
  5313. (function (global){
  5314. 'use strict';
  5315. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  5316. var UI = _dereq_(2);
  5317. var Progress = (function() {
  5318. /**
  5319. * NProgress (c) 2013, Rico Sta. Cruz
  5320. * @via http://ricostacruz.com/nprogress
  5321. */
  5322. var NProgress = {};
  5323. var $html = $('html');
  5324. NProgress.version = '0.1.6';
  5325. var Settings = NProgress.settings = {
  5326. minimum: 0.08,
  5327. easing: 'ease',
  5328. positionUsing: '',
  5329. speed: 200,
  5330. trickle: true,
  5331. trickleRate: 0.02,
  5332. trickleSpeed: 800,
  5333. showSpinner: true,
  5334. parent: 'body',
  5335. barSelector: '[role="nprogress-bar"]',
  5336. spinnerSelector: '[role="nprogress-spinner"]',
  5337. template: '<div class="nprogress-bar" role="nprogress-bar">' +
  5338. '<div class="nprogress-peg"></div></div>' +
  5339. '<div class="nprogress-spinner" role="nprogress-spinner">' +
  5340. '<div class="nprogress-spinner-icon"></div></div>'
  5341. };
  5342. /**
  5343. * Updates configuration.
  5344. *
  5345. * NProgress.configure({
  5346. * minimum: 0.1
  5347. * });
  5348. */
  5349. NProgress.configure = function(options) {
  5350. var key, value;
  5351. for (key in options) {
  5352. value = options[key];
  5353. if (value !== undefined && options.hasOwnProperty(key)) Settings[key] = value;
  5354. }
  5355. return this;
  5356. };
  5357. /**
  5358. * Last number.
  5359. */
  5360. NProgress.status = null;
  5361. /**
  5362. * Sets the progress bar status, where `n` is a number from `0.0` to `1.0`.
  5363. *
  5364. * NProgress.set(0.4);
  5365. * NProgress.set(1.0);
  5366. */
  5367. NProgress.set = function(n) {
  5368. var started = NProgress.isStarted();
  5369. n = clamp(n, Settings.minimum, 1);
  5370. NProgress.status = (n === 1 ? null : n);
  5371. var progress = NProgress.render(!started),
  5372. bar = progress.querySelector(Settings.barSelector),
  5373. speed = Settings.speed,
  5374. ease = Settings.easing;
  5375. progress.offsetWidth;
  5376. /* Repaint */
  5377. queue(function(next) {
  5378. // Set positionUsing if it hasn't already been set
  5379. if (Settings.positionUsing === '') Settings.positionUsing = NProgress.getPositioningCSS();
  5380. // Add transition
  5381. css(bar, barPositionCSS(n, speed, ease));
  5382. if (n === 1) {
  5383. // Fade out
  5384. css(progress, {
  5385. transition: 'none',
  5386. opacity: 1
  5387. });
  5388. progress.offsetWidth;
  5389. /* Repaint */
  5390. setTimeout(function() {
  5391. css(progress, {
  5392. transition: 'all ' + speed + 'ms linear',
  5393. opacity: 0
  5394. });
  5395. setTimeout(function() {
  5396. NProgress.remove();
  5397. next();
  5398. }, speed);
  5399. }, speed);
  5400. } else {
  5401. setTimeout(next, speed);
  5402. }
  5403. });
  5404. return this;
  5405. };
  5406. NProgress.isStarted = function() {
  5407. return typeof NProgress.status === 'number';
  5408. };
  5409. /**
  5410. * Shows the progress bar.
  5411. * This is the same as setting the status to 0%, except that it doesn't go backwards.
  5412. *
  5413. * NProgress.start();
  5414. *
  5415. */
  5416. NProgress.start = function() {
  5417. if (!NProgress.status) NProgress.set(0);
  5418. var work = function() {
  5419. setTimeout(function() {
  5420. if (!NProgress.status) return;
  5421. NProgress.trickle();
  5422. work();
  5423. }, Settings.trickleSpeed);
  5424. };
  5425. if (Settings.trickle) work();
  5426. return this;
  5427. };
  5428. /**
  5429. * Hides the progress bar.
  5430. * This is the *sort of* the same as setting the status to 100%, with the
  5431. * difference being `done()` makes some placebo effect of some realistic motion.
  5432. *
  5433. * NProgress.done();
  5434. *
  5435. * If `true` is passed, it will show the progress bar even if its hidden.
  5436. *
  5437. * NProgress.done(true);
  5438. */
  5439. NProgress.done = function(force) {
  5440. if (!force && !NProgress.status) return this;
  5441. return NProgress.inc(0.3 + 0.5 * Math.random()).set(1);
  5442. };
  5443. /**
  5444. * Increments by a random amount.
  5445. */
  5446. NProgress.inc = function(amount) {
  5447. var n = NProgress.status;
  5448. if (!n) {
  5449. return NProgress.start();
  5450. } else {
  5451. if (typeof amount !== 'number') {
  5452. amount = (1 - n) * clamp(Math.random() * n, 0.1, 0.95);
  5453. }
  5454. n = clamp(n + amount, 0, 0.994);
  5455. return NProgress.set(n);
  5456. }
  5457. };
  5458. NProgress.trickle = function() {
  5459. return NProgress.inc(Math.random() * Settings.trickleRate);
  5460. };
  5461. /**
  5462. * (Internal) renders the progress bar markup based on the `template`
  5463. * setting.
  5464. */
  5465. NProgress.render = function(fromStart) {
  5466. if (NProgress.isRendered()) return document.getElementById('nprogress');
  5467. $html.addClass('nprogress-busy');
  5468. var progress = document.createElement('div');
  5469. progress.id = 'nprogress';
  5470. progress.innerHTML = Settings.template;
  5471. var bar = progress.querySelector(Settings.barSelector),
  5472. perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
  5473. parent = document.querySelector(Settings.parent),
  5474. spinner;
  5475. css(bar, {
  5476. transition: 'all 0 linear',
  5477. transform: 'translate3d(' + perc + '%,0,0)'
  5478. });
  5479. if (!Settings.showSpinner) {
  5480. spinner = progress.querySelector(Settings.spinnerSelector);
  5481. spinner && $(spinner).remove();
  5482. }
  5483. if (parent != document.body) {
  5484. $(parent).addClass('nprogress-custom-parent');
  5485. }
  5486. parent.appendChild(progress);
  5487. return progress;
  5488. };
  5489. /**
  5490. * Removes the element. Opposite of render().
  5491. */
  5492. NProgress.remove = function() {
  5493. $html.removeClass('nprogress-busy');
  5494. $(Settings.parent).removeClass('nprogress-custom-parent');
  5495. var progress = document.getElementById('nprogress');
  5496. progress && $(progress).remove();
  5497. };
  5498. /**
  5499. * Checks if the progress bar is rendered.
  5500. */
  5501. NProgress.isRendered = function() {
  5502. return !!document.getElementById('nprogress');
  5503. };
  5504. /**
  5505. * Determine which positioning CSS rule to use.
  5506. */
  5507. NProgress.getPositioningCSS = function() {
  5508. // Sniff on document.body.style
  5509. var bodyStyle = document.body.style;
  5510. // Sniff prefixes
  5511. var vendorPrefix = ('WebkitTransform' in bodyStyle) ? 'Webkit' :
  5512. ('MozTransform' in bodyStyle) ? 'Moz' :
  5513. ('msTransform' in bodyStyle) ? 'ms' :
  5514. ('OTransform' in bodyStyle) ? 'O' : '';
  5515. if (vendorPrefix + 'Perspective' in bodyStyle) {
  5516. // Modern browsers with 3D support, e.g. Webkit, IE10
  5517. return 'translate3d';
  5518. } else if (vendorPrefix + 'Transform' in bodyStyle) {
  5519. // Browsers without 3D support, e.g. IE9
  5520. return 'translate';
  5521. } else {
  5522. // Browsers without translate() support, e.g. IE7-8
  5523. return 'margin';
  5524. }
  5525. };
  5526. /**
  5527. * Helpers
  5528. */
  5529. function clamp(n, min, max) {
  5530. if (n < min) return min;
  5531. if (n > max) return max;
  5532. return n;
  5533. }
  5534. /**
  5535. * (Internal) converts a percentage (`0..1`) to a bar translateX
  5536. * percentage (`-100%..0%`).
  5537. */
  5538. function toBarPerc(n) {
  5539. return (-1 + n) * 100;
  5540. }
  5541. /**
  5542. * (Internal) returns the correct CSS for changing the bar's
  5543. * position given an n percentage, and speed and ease from Settings
  5544. */
  5545. function barPositionCSS(n, speed, ease) {
  5546. var barCSS;
  5547. if (Settings.positionUsing === 'translate3d') {
  5548. barCSS = {transform: 'translate3d(' + toBarPerc(n) + '%,0,0)'};
  5549. } else if (Settings.positionUsing === 'translate') {
  5550. barCSS = {transform: 'translate(' + toBarPerc(n) + '%,0)'};
  5551. } else {
  5552. barCSS = {'margin-left': toBarPerc(n) + '%'};
  5553. }
  5554. barCSS.transition = 'all ' + speed + 'ms ' + ease;
  5555. return barCSS;
  5556. }
  5557. /**
  5558. * (Internal) Queues a function to be executed.
  5559. */
  5560. var queue = (function() {
  5561. var pending = [];
  5562. function next() {
  5563. var fn = pending.shift();
  5564. if (fn) {
  5565. fn(next);
  5566. }
  5567. }
  5568. return function(fn) {
  5569. pending.push(fn);
  5570. if (pending.length == 1) next();
  5571. };
  5572. })();
  5573. /**
  5574. * (Internal) Applies css properties to an element, similar to the jQuery
  5575. * css method.
  5576. *
  5577. * While this helper does assist with vendor prefixed property names, it
  5578. * does not perform any manipulation of values prior to setting styles.
  5579. */
  5580. var css = (function() {
  5581. var cssPrefixes = ['Webkit', 'O', 'Moz', 'ms'],
  5582. cssProps = {};
  5583. function camelCase(string) {
  5584. return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function(match, letter) {
  5585. return letter.toUpperCase();
  5586. });
  5587. }
  5588. function getVendorProp(name) {
  5589. var style = document.body.style;
  5590. if (name in style) return name;
  5591. var i = cssPrefixes.length,
  5592. capName = name.charAt(0).toUpperCase() + name.slice(1),
  5593. vendorName;
  5594. while (i--) {
  5595. vendorName = cssPrefixes[i] + capName;
  5596. if (vendorName in style) return vendorName;
  5597. }
  5598. return name;
  5599. }
  5600. function getStyleProp(name) {
  5601. name = camelCase(name);
  5602. return cssProps[name] || (cssProps[name] = getVendorProp(name));
  5603. }
  5604. function applyCss(element, prop, value) {
  5605. prop = getStyleProp(prop);
  5606. element.style[prop] = value;
  5607. }
  5608. return function(element, properties) {
  5609. var args = arguments,
  5610. prop,
  5611. value;
  5612. if (args.length == 2) {
  5613. for (prop in properties) {
  5614. value = properties[prop];
  5615. if (value !== undefined && properties.hasOwnProperty(prop)) applyCss(element, prop, value);
  5616. }
  5617. } else {
  5618. applyCss(element, args[1], args[2]);
  5619. }
  5620. }
  5621. })();
  5622. return NProgress;
  5623. })();
  5624. $.AMUI.progress = Progress;
  5625. module.exports = Progress;
  5626. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5627. },{"2":2}],17:[function(_dereq_,module,exports){
  5628. (function (global){
  5629. 'use strict';
  5630. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  5631. var UI = _dereq_(2);
  5632. var PinchZoom = _dereq_(14);
  5633. var Hammer = _dereq_(30);
  5634. var animation = UI.support.animation;
  5635. var transition = UI.support.transition;
  5636. /**
  5637. * PureView
  5638. * @desc Image browser for Mobile
  5639. * @param element
  5640. * @param options
  5641. * @constructor
  5642. */
  5643. var PureView = function(element, options) {
  5644. this.$element = $(element);
  5645. this.$body = $(document.body);
  5646. this.options = $.extend({}, PureView.DEFAULTS, options);
  5647. this.$pureview = $(this.options.tpl).attr('id',
  5648. UI.utils.generateGUID('am-pureview'));
  5649. this.$slides = null;
  5650. this.transitioning = null;
  5651. this.scrollbarWidth = 0;
  5652. this.init();
  5653. };
  5654. PureView.DEFAULTS = {
  5655. tpl: '<div class="am-pureview am-pureview-bar-active">' +
  5656. '<ul class="am-pureview-slider"></ul>' +
  5657. '<ul class="am-pureview-direction">' +
  5658. '<li class="am-pureview-prev"><a href=""></a></li>' +
  5659. '<li class="am-pureview-next"><a href=""></a></li></ul>' +
  5660. '<ol class="am-pureview-nav"></ol>' +
  5661. '<div class="am-pureview-bar am-active">' +
  5662. '<span class="am-pureview-title"></span>' +
  5663. '<div class="am-pureview-counter"><span class="am-pureview-current"></span> / ' +
  5664. '<span class="am-pureview-total"></span></div></div>' +
  5665. '<div class="am-pureview-actions am-active">' +
  5666. '<a href="javascript: void(0)" class="am-icon-chevron-left" ' +
  5667. 'data-am-close="pureview"></a></div>' +
  5668. '</div>',
  5669. className: {
  5670. prevSlide: 'am-pureview-slide-prev',
  5671. nextSlide: 'am-pureview-slide-next',
  5672. onlyOne: 'am-pureview-only',
  5673. active: 'am-active',
  5674. barActive: 'am-pureview-bar-active',
  5675. activeBody: 'am-pureview-active'
  5676. },
  5677. selector: {
  5678. slider: '.am-pureview-slider',
  5679. close: '[data-am-close="pureview"]',
  5680. total: '.am-pureview-total',
  5681. current: '.am-pureview-current',
  5682. title: '.am-pureview-title',
  5683. actions: '.am-pureview-actions',
  5684. bar: '.am-pureview-bar',
  5685. pinchZoom: '.am-pinch-zoom',
  5686. nav: '.am-pureview-nav'
  5687. },
  5688. shareBtn: false,
  5689. // press to toggle Toolbar
  5690. toggleToolbar: true,
  5691. // 从何处获取图片,img 可以使用 data-rel 指定大图
  5692. target: 'img',
  5693. // 微信 Webview 中调用微信的图片浏览器
  5694. // 实现图片保存、分享好友、收藏图片等功能
  5695. weChatImagePreview: true
  5696. };
  5697. PureView.prototype.init = function() {
  5698. var _this = this;
  5699. var options = this.options;
  5700. var $element = this.$element;
  5701. var $pureview = this.$pureview;
  5702. this.refreshSlides();
  5703. $('body').append($pureview);
  5704. this.$title = $pureview.find(options.selector.title);
  5705. this.$current = $pureview.find(options.selector.current);
  5706. this.$bar = $pureview.find(options.selector.bar);
  5707. this.$actions = $pureview.find(options.selector.actions);
  5708. if (options.shareBtn) {
  5709. this.$actions.append('<a href="javascript: void(0)" ' +
  5710. 'class="am-icon-share-square-o" data-am-toggle="share"></a>');
  5711. }
  5712. this.$element.on('click.pureview.amui', options.target, function(e) {
  5713. e.preventDefault();
  5714. var clicked = _this.$images.index(this);
  5715. // Invoke WeChat ImagePreview in WeChat
  5716. // TODO: detect WeChat before init
  5717. if (options.weChatImagePreview && window.WeixinJSBridge) {
  5718. window.WeixinJSBridge.invoke('imagePreview', {
  5719. current: _this.imgUrls[clicked],
  5720. urls: _this.imgUrls
  5721. });
  5722. } else {
  5723. _this.open(clicked);
  5724. }
  5725. });
  5726. $pureview.find('.am-pureview-direction').
  5727. on('click.direction.pureview.amui', 'li', function(e) {
  5728. e.preventDefault();
  5729. if ($(this).is('.am-pureview-prev')) {
  5730. _this.prevSlide();
  5731. } else {
  5732. _this.nextSlide();
  5733. }
  5734. });
  5735. // Nav Contorl
  5736. $pureview.find(options.selector.nav).on('click.nav.pureview.amui', 'li',
  5737. function() {
  5738. var index = _this.$navItems.index($(this));
  5739. _this.activate(_this.$slides.eq(index));
  5740. });
  5741. // Close Icon
  5742. $pureview.find(options.selector.close).
  5743. on('click.close.pureview.amui', function(e) {
  5744. e.preventDefault();
  5745. _this.close();
  5746. });
  5747. this.$slider.hammer().on('swipeleft.pureview.amui', function(e) {
  5748. e.preventDefault();
  5749. _this.nextSlide();
  5750. }).on('swiperight.pureview.amui', function(e) {
  5751. e.preventDefault();
  5752. _this.prevSlide();
  5753. }).on('press.pureview.amui', function(e) {
  5754. e.preventDefault();
  5755. options.toggleToolbar && _this.toggleToolBar();
  5756. });
  5757. this.$slider.data('hammer').get('swipe').set({
  5758. direction: Hammer.DIRECTION_HORIZONTAL,
  5759. velocity: 0.35
  5760. });
  5761. // Observe DOM
  5762. $element.DOMObserve({
  5763. childList: true,
  5764. subtree: true
  5765. }, function(mutations, observer) {
  5766. // _this.refreshSlides();
  5767. // console.log('mutations[0].type);
  5768. });
  5769. // NOTE:
  5770. // trigger this event manually if MutationObserver not supported
  5771. // when new images appended, or call refreshSlides()
  5772. // if (!UI.support.mutationobserver) $element.trigger('changed.dom.amui')
  5773. $element.on('changed.dom.amui', function(e) {
  5774. e.stopPropagation();
  5775. _this.refreshSlides();
  5776. });
  5777. $(document).on('keydown.pureview.amui', $.proxy(function(e) {
  5778. var keyCode = e.keyCode;
  5779. if (keyCode == 37) {
  5780. this.prevSlide();
  5781. } else if (keyCode == 39) {
  5782. this.nextSlide();
  5783. } else if (keyCode == 27) {
  5784. this.close();
  5785. }
  5786. }, this));
  5787. };
  5788. PureView.prototype.refreshSlides = function() {
  5789. // update images collections
  5790. this.$images = this.$element.find(this.options.target);
  5791. var _this = this;
  5792. var options = this.options;
  5793. var $pureview = this.$pureview;
  5794. var $slides = $([]);
  5795. var $navItems = $([]);
  5796. var $images = this.$images;
  5797. var total = $images.length;
  5798. this.$slider = $pureview.find(options.selector.slider);
  5799. this.$nav = $pureview.find(options.selector.nav);
  5800. var viewedFlag = 'data-am-pureviewed';
  5801. // for WeChat Image Preview
  5802. this.imgUrls = this.imgUrls || [];
  5803. if (!total) {
  5804. return;
  5805. }
  5806. if (total === 1) {
  5807. $pureview.addClass(options.className.onlyOne);
  5808. }
  5809. $images.not('[' + viewedFlag + ']').each(function(i, item) {
  5810. var src;
  5811. var title;
  5812. // get image URI from link's href attribute
  5813. if (item.nodeName === 'A') {
  5814. src = item.href; // to absolute path
  5815. title = item.title || '';
  5816. } else {
  5817. // NOTE: `data-rel` should be a full URL, otherwise,
  5818. // WeChat images preview will not work
  5819. src = $(item).data('rel') || item.src; // <img src='' data-rel='' />
  5820. title = $(item).attr('alt') || '';
  5821. }
  5822. // add pureviewed flag
  5823. item.setAttribute(viewedFlag, '1');
  5824. // hide bar: wechat_webview_type=1
  5825. // http://tmt.io/wechat/ not working?
  5826. _this.imgUrls.push(src);
  5827. $slides = $slides.add($('<li data-src="' + src + '" data-title="' + title +
  5828. '"></li>'));
  5829. $navItems = $navItems.add($('<li>' + (i + 1) + '</li>'));
  5830. });
  5831. $pureview.find(options.selector.total).text(total);
  5832. this.$slider.append($slides);
  5833. this.$nav.append($navItems);
  5834. this.$navItems = this.$nav.find('li');
  5835. this.$slides = this.$slider.find('li');
  5836. };
  5837. PureView.prototype.loadImage = function($slide, callback) {
  5838. var appendedFlag = 'image-appended';
  5839. if (!$slide.data(appendedFlag)) {
  5840. var $img = $('<img>', {
  5841. src: $slide.data('src'),
  5842. alt: $slide.data('title')
  5843. });
  5844. $slide.html($img).wrapInner('<div class="am-pinch-zoom"></div>').redraw();
  5845. var $pinchWrapper = $slide.find(this.options.selector.pinchZoom);
  5846. $pinchWrapper.data('amui.pinchzoom', new PinchZoom($pinchWrapper[0], {}));
  5847. $slide.data('image-appended', true);
  5848. }
  5849. callback && callback.call(this);
  5850. };
  5851. PureView.prototype.activate = function($slide) {
  5852. var options = this.options;
  5853. var $slides = this.$slides;
  5854. var activeIndex = $slides.index($slide);
  5855. var title = $slide.data('title') || '';
  5856. var active = options.className.active;
  5857. if ($slides.find('.' + active).is($slide)) {
  5858. return;
  5859. }
  5860. if (this.transitioning) {
  5861. return;
  5862. }
  5863. this.loadImage($slide, function() {
  5864. UI.utils.imageLoader($slide.find('img'), function(image) {
  5865. $(image).addClass('am-img-loaded');
  5866. });
  5867. });
  5868. this.transitioning = 1;
  5869. this.$title.text(title);
  5870. this.$current.text(activeIndex + 1);
  5871. $slides.removeClass();
  5872. $slide.addClass(active);
  5873. $slides.eq(activeIndex - 1).addClass(options.className.prevSlide);
  5874. $slides.eq(activeIndex + 1).addClass(options.className.nextSlide);
  5875. this.$navItems.removeClass().
  5876. eq(activeIndex).addClass(options.className.active);
  5877. if (transition) {
  5878. $slide.one(transition.end, $.proxy(function() {
  5879. this.transitioning = 0;
  5880. }, this)).emulateTransitionEnd(300);
  5881. } else {
  5882. this.transitioning = 0;
  5883. }
  5884. // TODO: pre-load next image
  5885. };
  5886. PureView.prototype.nextSlide = function() {
  5887. if (this.$slides.length === 1) {
  5888. return;
  5889. }
  5890. var $slides = this.$slides;
  5891. var $active = $slides.filter('.am-active');
  5892. var activeIndex = $slides.index($active);
  5893. var rightSpring = 'am-animation-right-spring';
  5894. if (activeIndex + 1 >= $slides.length) { // last one
  5895. animation && $active.addClass(rightSpring).on(animation.end, function() {
  5896. $active.removeClass(rightSpring);
  5897. });
  5898. } else {
  5899. this.activate($slides.eq(activeIndex + 1));
  5900. }
  5901. };
  5902. PureView.prototype.prevSlide = function() {
  5903. if (this.$slides.length === 1) {
  5904. return;
  5905. }
  5906. var $slides = this.$slides;
  5907. var $active = $slides.filter('.am-active');
  5908. var activeIndex = this.$slides.index(($active));
  5909. var leftSpring = 'am-animation-left-spring';
  5910. if (activeIndex === 0) { // first one
  5911. animation && $active.addClass(leftSpring).on(animation.end, function() {
  5912. $active.removeClass(leftSpring);
  5913. });
  5914. } else {
  5915. this.activate($slides.eq(activeIndex - 1));
  5916. }
  5917. };
  5918. PureView.prototype.toggleToolBar = function() {
  5919. this.$pureview.toggleClass(this.options.className.barActive);
  5920. };
  5921. PureView.prototype.open = function(index) {
  5922. var active = index || 0;
  5923. this.checkScrollbar();
  5924. this.setScrollbar();
  5925. this.activate(this.$slides.eq(active));
  5926. this.$pureview.show().redraw().addClass(this.options.className.active);
  5927. this.$body.addClass(this.options.className.activeBody);
  5928. };
  5929. PureView.prototype.close = function() {
  5930. var options = this.options;
  5931. this.$pureview.removeClass(options.className.active);
  5932. this.$slides.removeClass();
  5933. function resetBody() {
  5934. this.$pureview.hide();
  5935. this.$body.removeClass(options.className.activeBody);
  5936. this.resetScrollbar();
  5937. }
  5938. if (transition) {
  5939. this.$pureview.one(transition.end, $.proxy(resetBody, this)).
  5940. emulateTransitionEnd(300);
  5941. } else {
  5942. resetBody.call(this);
  5943. }
  5944. };
  5945. PureView.prototype.checkScrollbar = function() {
  5946. this.scrollbarWidth = UI.utils.measureScrollbar();
  5947. };
  5948. PureView.prototype.setScrollbar = function() {
  5949. var bodyPaddingRight = parseInt((this.$body.css('padding-right') || 0), 10);
  5950. if (this.scrollbarWidth) {
  5951. this.$body.css('padding-right', bodyPaddingRight + this.scrollbarWidth);
  5952. }
  5953. };
  5954. PureView.prototype.resetScrollbar = function() {
  5955. this.$body.css('padding-right', '');
  5956. };
  5957. function Plugin(option) {
  5958. return this.each(function() {
  5959. var $this = $(this);
  5960. var data = $this.data('amui.pureview');
  5961. var options = $.extend({},
  5962. UI.utils.parseOptions($this.data('amPureview')),
  5963. typeof option == 'object' && option);
  5964. if (!data) {
  5965. $this.data('amui.pureview', (data = new PureView(this, options)));
  5966. }
  5967. if (typeof option == 'string') {
  5968. data[option]();
  5969. }
  5970. });
  5971. }
  5972. $.fn.pureview = Plugin;
  5973. // Init code
  5974. UI.ready(function(context) {
  5975. $('[data-am-pureview]', context).pureview();
  5976. });
  5977. $.AMUI.pureview = PureView;
  5978. module.exports = PureView;
  5979. // TODO: 1. 动画改进
  5980. // 2. 改变图片的时候恢复 Zoom
  5981. // 3. 选项
  5982. // 4. 图片高度问题:由于 PinchZoom 的原因,过高的图片如果设置看了滚动,则放大以后显示不全
  5983. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  5984. },{"14":14,"2":2,"30":30}],18:[function(_dereq_,module,exports){
  5985. (function (global){
  5986. 'use strict';
  5987. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  5988. var UI = _dereq_(2);
  5989. /**
  5990. * @via https://github.com/uikit/uikit/blob/master/src/js/scrollspy.js
  5991. * @license https://github.com/uikit/uikit/blob/master/LICENSE.md
  5992. */
  5993. var ScrollSpy = function(element, options) {
  5994. if (!UI.support.animation) {
  5995. return;
  5996. }
  5997. this.options = $.extend({}, ScrollSpy.DEFAULTS, options);
  5998. this.$element = $(element);
  5999. var checkViewRAF = function() {
  6000. UI.utils.rAF.call(window, $.proxy(this.checkView, this));
  6001. }.bind(this);
  6002. this.$window = $(window).on('scroll.scrollspy.amui', checkViewRAF)
  6003. .on('resize.scrollspy.amui orientationchange.scrollspy.amui',
  6004. UI.utils.debounce(checkViewRAF, 50));
  6005. this.timer = this.inViewState = this.initInView = null;
  6006. checkViewRAF();
  6007. };
  6008. ScrollSpy.DEFAULTS = {
  6009. animation: 'fade',
  6010. className: {
  6011. inView: 'am-scrollspy-inview',
  6012. init: 'am-scrollspy-init'
  6013. },
  6014. repeat: true,
  6015. delay: 0,
  6016. topOffset: 0,
  6017. leftOffset: 0
  6018. };
  6019. ScrollSpy.prototype.checkView = function() {
  6020. var $element = this.$element;
  6021. var options = this.options;
  6022. var inView = UI.utils.isInView($element, options);
  6023. var animation = options.animation ?
  6024. ' am-animation-' + options.animation : '';
  6025. if (inView && !this.inViewState) {
  6026. if (this.timer) {
  6027. clearTimeout(this.timer);
  6028. }
  6029. if (!this.initInView) {
  6030. $element.addClass(options.className.init);
  6031. this.offset = $element.offset();
  6032. this.initInView = true;
  6033. $element.trigger('init.scrollspy.amui');
  6034. }
  6035. this.timer = setTimeout(function() {
  6036. if (inView) {
  6037. $element.addClass(options.className.inView + animation).width();
  6038. }
  6039. }, options.delay);
  6040. this.inViewState = true;
  6041. $element.trigger('inview.scrollspy.amui');
  6042. }
  6043. if (!inView && this.inViewState && options.repeat) {
  6044. $element.removeClass(options.className.inView + animation);
  6045. this.inViewState = false;
  6046. $element.trigger('outview.scrollspy.amui');
  6047. }
  6048. };
  6049. ScrollSpy.prototype.check = function() {
  6050. UI.utils.rAF.call(window, $.proxy(this.checkView, this));
  6051. };
  6052. // Sticky Plugin
  6053. function Plugin(option) {
  6054. return this.each(function() {
  6055. var $this = $(this);
  6056. var data = $this.data('am.scrollspy');
  6057. var options = typeof option == 'object' && option;
  6058. if (!data) {
  6059. $this.data('am.scrollspy', (data = new ScrollSpy(this, options)));
  6060. }
  6061. if (typeof option == 'string') {
  6062. data[option]();
  6063. }
  6064. });
  6065. }
  6066. $.fn.scrollspy = Plugin;
  6067. // Init code
  6068. UI.ready(function(context) {
  6069. $('[data-am-scrollspy]', context).each(function() {
  6070. var $this = $(this);
  6071. var options = UI.utils.options($this.data('amScrollspy'));
  6072. $this.scrollspy(options);
  6073. });
  6074. });
  6075. $.AMUI.scrollspy = ScrollSpy;
  6076. module.exports = ScrollSpy;
  6077. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6078. },{"2":2}],19:[function(_dereq_,module,exports){
  6079. (function (global){
  6080. 'use strict';
  6081. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  6082. var UI = _dereq_(2);
  6083. _dereq_(22);
  6084. /**
  6085. * @via https://github.com/uikit/uikit/
  6086. * @license https://github.com/uikit/uikit/blob/master/LICENSE.md
  6087. */
  6088. // ScrollSpyNav Class
  6089. var ScrollSpyNav = function(element, options) {
  6090. this.options = $.extend({}, ScrollSpyNav.DEFAULTS, options);
  6091. this.$element = $(element);
  6092. this.anchors = [];
  6093. this.$links = this.$element.find('a[href^="#"]').each(function(i, link) {
  6094. this.anchors.push($(link).attr('href'));
  6095. }.bind(this));
  6096. this.$targets = $(this.anchors.join(', '));
  6097. var processRAF = function() {
  6098. UI.utils.rAF.call(window, $.proxy(this.process, this));
  6099. }.bind(this);
  6100. this.$window = $(window).on('scroll.scrollspynav.amui', processRAF)
  6101. .on('resize.scrollspynav.amui orientationchange.scrollspynav.amui',
  6102. UI.utils.debounce(processRAF, 50));
  6103. processRAF();
  6104. this.scrollProcess();
  6105. };
  6106. ScrollSpyNav.DEFAULTS = {
  6107. className: {
  6108. active: 'am-active'
  6109. },
  6110. closest: false,
  6111. smooth: true,
  6112. offsetTop: 0
  6113. };
  6114. ScrollSpyNav.prototype.process = function() {
  6115. var scrollTop = this.$window.scrollTop();
  6116. var options = this.options;
  6117. var inViews = [];
  6118. var $links = this.$links;
  6119. var $targets = this.$targets;
  6120. $targets.each(function(i, target) {
  6121. if (UI.utils.isInView(target, options)) {
  6122. inViews.push(target);
  6123. }
  6124. });
  6125. // console.log(inViews.length);
  6126. if (inViews.length) {
  6127. var $target;
  6128. $.each(inViews, function(i, item) {
  6129. if ($(item).offset().top >= scrollTop) {
  6130. $target = $(item);
  6131. return false; // break
  6132. }
  6133. });
  6134. if (!$target) {
  6135. return;
  6136. }
  6137. if (options.closest) {
  6138. $links.closest(options.closest).removeClass(options.className.active);
  6139. $links.filter('a[href="#' + $target.attr('id') + '"]').
  6140. closest(options.closest).addClass(options.className.active);
  6141. } else {
  6142. $links.removeClass(options.className.active).
  6143. filter('a[href="#' + $target.attr('id') + '"]').
  6144. addClass(options.className.active);
  6145. }
  6146. }
  6147. };
  6148. ScrollSpyNav.prototype.scrollProcess = function() {
  6149. var $links = this.$links;
  6150. var options = this.options;
  6151. // smoothScroll
  6152. if (options.smooth) {
  6153. $links.on('click', function(e) {
  6154. e.preventDefault();
  6155. var $this = $(this);
  6156. var $target = $($this.attr('href'));
  6157. if (!$target) {
  6158. return;
  6159. }
  6160. var offsetTop = options.offsetTop &&
  6161. !isNaN(parseInt(options.offsetTop)) && parseInt(options.offsetTop) || 0;
  6162. $(window).smoothScroll({position: $target.offset().top - offsetTop});
  6163. });
  6164. }
  6165. };
  6166. // ScrollSpyNav Plugin
  6167. function Plugin(option) {
  6168. return this.each(function() {
  6169. var $this = $(this);
  6170. var data = $this.data('amui.scrollspynav');
  6171. var options = typeof option == 'object' && option;
  6172. if (!data) {
  6173. $this.data('amui.scrollspynav', (data = new ScrollSpyNav(this, options)));
  6174. }
  6175. if (typeof option == 'string') {
  6176. data[option]();
  6177. }
  6178. });
  6179. }
  6180. $.fn.scrollspynav = Plugin;
  6181. // Init code
  6182. UI.ready(function(context) {
  6183. $('[data-am-scrollspy-nav]', context).each(function() {
  6184. var $this = $(this);
  6185. var options = UI.utils.options($this.data('amScrollspyNav'));
  6186. Plugin.call($this, options);
  6187. });
  6188. });
  6189. $.AMUI.scrollspynav = ScrollSpyNav;
  6190. module.exports = ScrollSpyNav;
  6191. // TODO: 1. 算法改进
  6192. // 2. 多级菜单支持
  6193. // 3. smooth scroll pushState
  6194. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6195. },{"2":2,"22":22}],20:[function(_dereq_,module,exports){
  6196. (function (global){
  6197. 'use strict';
  6198. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  6199. var UI = _dereq_(2);
  6200. // Make jQuery :contains Case-Insensitive
  6201. $.expr[':'].containsNC = function(elem, i, match, array) {
  6202. return (elem.textContent || elem.innerText || '').toLowerCase().
  6203. indexOf((match[3] || '').toLowerCase()) >= 0;
  6204. };
  6205. /**
  6206. * Selected
  6207. * @desc HTML select replacer
  6208. * @via https://github.com/silviomoreto/bootstrap-select
  6209. * @license https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE
  6210. * @param element
  6211. * @param options
  6212. * @constructor
  6213. */
  6214. var Selected = function(element, options) {
  6215. this.$element = $(element);
  6216. this.options = $.extend({}, Selected.DEFAULTS, options);
  6217. this.$originalOptions = this.$element.find('option');
  6218. this.multiple = element.multiple;
  6219. this.$selector = null;
  6220. this.init();
  6221. };
  6222. Selected.DEFAULTS = {
  6223. btnWidth: null,
  6224. btnSize: null,
  6225. btnStyle: 'default',
  6226. dropUp: 0,
  6227. maxHeight: null,
  6228. noSelectedText: '点击选择...',
  6229. selectedClass: 'am-checked',
  6230. disabledClass: 'am-disabled',
  6231. searchBox: false,
  6232. tpl: '<div class="am-selected am-dropdown ' +
  6233. '<%= dropUp ? \'am-dropdown-up\': \'\' %>" id="<%= id %>" data-am-dropdown>' +
  6234. ' <button type="button" class="am-selected-btn am-btn am-dropdown-toggle">' +
  6235. ' <span class="am-selected-status am-fl"></span>' +
  6236. ' <i class="am-selected-icon am-icon-caret-' +
  6237. '<%= dropUp ? \'up\' : \'down\' %>"></i>' +
  6238. ' </button>' +
  6239. ' <div class="am-selected-content am-dropdown-content">' +
  6240. ' <h2 class="am-selected-header">' +
  6241. '<span class="am-icon-chevron-left">返回</span></h2>' +
  6242. ' <% if (searchBox) { %>' +
  6243. ' <div class="am-selected-search">' +
  6244. ' <input type="text" autocomplete="off" class="am-form-field" />' +
  6245. ' </div>' +
  6246. ' <% } %>' +
  6247. ' <ul class="am-selected-list">' +
  6248. ' <% for (var i = 0; i < options.length; i++) { %>' +
  6249. ' <% var option = options[i] %>' +
  6250. ' <% if (option.header) { %>' +
  6251. ' <li data-group="<%= option.group %>" class="am-selected-list-header">' +
  6252. ' <%= option.text %></li>' +
  6253. ' <% } else { %>' +
  6254. ' <li class="<%= option.classNames%>" ' +
  6255. ' data-index="<%= option.index %>" ' +
  6256. ' data-group="<%= option.group || 0 %>" ' +
  6257. ' data-value="<%= option.value %>" >' +
  6258. ' <span class="am-selected-text"><%= option.text %></span>' +
  6259. ' <i class="am-icon-check"></i></li>' +
  6260. ' <% } %>' +
  6261. ' <% } %>' +
  6262. ' </ul>' +
  6263. ' <div class="am-selected-hint"></div>' +
  6264. ' </div>' +
  6265. '</div>',
  6266. listTpl: '<% for (var i = 0; i < options.length; i++) { %>' +
  6267. ' <% var option = options[i] %>' +
  6268. ' <% if (option.header) { %>' +
  6269. ' <li data-group="<%= option.group %>" class="am-selected-list-header">' +
  6270. ' <%= option.text %></li>' +
  6271. ' <% } else { %>' +
  6272. ' <li class="<%= option.classNames %>" ' +
  6273. ' data-index="<%= option.index %>" ' +
  6274. ' data-group="<%= option.group || 0 %>" ' +
  6275. ' data-value="<%= option.value %>" >' +
  6276. ' <span class="am-selected-text"><%= option.text %></span>' +
  6277. ' <i class="am-icon-check"></i></li>' +
  6278. ' <% } %>' +
  6279. ' <% } %>'
  6280. };
  6281. Selected.prototype.init = function() {
  6282. var _this = this;
  6283. var $element = this.$element;
  6284. var options = this.options;
  6285. $element.hide();
  6286. var data = {
  6287. id: UI.utils.generateGUID('am-selected'),
  6288. multiple: this.multiple,
  6289. options: [],
  6290. searchBox: options.searchBox,
  6291. dropUp: options.dropUp
  6292. };
  6293. this.$selector = $(UI.template(this.options.tpl, data));
  6294. this.$list = this.$selector.find('.am-selected-list');
  6295. this.$searchField = this.$selector.find('.am-selected-search input');
  6296. this.$hint = this.$selector.find('.am-selected-hint');
  6297. // set select button styles
  6298. var $selectorBtn = this.$selector.find('.am-selected-btn').
  6299. css({width: this.options.btnWidth});
  6300. var btnClassNames = [];
  6301. options.btnSize && btnClassNames.push('am-btn-' + options.btnSize);
  6302. options.btnStyle && btnClassNames.push('am-btn-' + options.btnStyle);
  6303. $selectorBtn.addClass(btnClassNames.join(' '));
  6304. this.$selector.dropdown({
  6305. justify: $selectorBtn
  6306. });
  6307. // set list height
  6308. if (options.maxHeight) {
  6309. this.$selector.find('.am-selected-list').css({
  6310. 'max-height': options.maxHeight,
  6311. 'overflow-y': 'scroll'
  6312. });
  6313. }
  6314. // set hint text
  6315. var hint = [];
  6316. var min = $element.attr('minchecked');
  6317. var max = $element.attr('maxchecked');
  6318. if ($element[0].required) {
  6319. hint.push('必选');
  6320. }
  6321. if (min || max) {
  6322. min && hint.push('至少选择 ' + min + ' 项');
  6323. max && hint.push('至多选择 ' + max + ' 项');
  6324. }
  6325. this.$hint.text(hint.join(','));
  6326. // render dropdown list
  6327. this.renderOptions();
  6328. // append $selector after <select>
  6329. this.$element.after(this.$selector);
  6330. this.dropdown = this.$selector.data('amui.dropdown');
  6331. this.$status = this.$selector.find('.am-selected-status');
  6332. // #try to fixes #476
  6333. setTimeout(function() {
  6334. _this.syncData();
  6335. }, 0);
  6336. this.bindEvents();
  6337. };
  6338. Selected.prototype.renderOptions = function() {
  6339. var $element = this.$element;
  6340. var options = this.options;
  6341. var optionItems = [];
  6342. var $optgroup = $element.find('optgroup');
  6343. this.$originalOptions = this.$element.find('option');
  6344. // 单选框使用 JS 禁用已经选择的 option 以后,
  6345. // 浏览器会重新选定第一个 option,但有一定延迟,致使 JS 获取 value 时返回 null
  6346. if (!this.multiple && ($element.val() === null)) {
  6347. this.$originalOptions.get(0).selected = true;
  6348. }
  6349. function pushOption(index, item, group) {
  6350. var classNames = '';
  6351. item.disabled && (classNames += options.disabledClass);
  6352. !item.disabled && item.selected && (classNames += options.selectedClass);
  6353. optionItems.push({
  6354. group: group,
  6355. index: index,
  6356. classNames: classNames,
  6357. text: item.text,
  6358. value: item.value
  6359. });
  6360. }
  6361. // select with option groups
  6362. if ($optgroup.length) {
  6363. $optgroup.each(function(i) {
  6364. // push group name
  6365. optionItems.push({
  6366. header: true,
  6367. group: i + 1,
  6368. text: this.label
  6369. });
  6370. $optgroup.eq(i).find('option').each(function(index, item) {
  6371. pushOption(index, item, i);
  6372. });
  6373. });
  6374. } else {
  6375. // without option groups
  6376. this.$originalOptions.each(function(index, item) {
  6377. pushOption(index, item, null);
  6378. });
  6379. }
  6380. this.$list.html(UI.template(options.listTpl, {options: optionItems}));
  6381. this.$shadowOptions = this.$list.find('> li').
  6382. not('.am-selected-list-header');
  6383. };
  6384. Selected.prototype.setChecked = function(item) {
  6385. var options = this.options;
  6386. var $item = $(item);
  6387. var isChecked = $item.hasClass(options.selectedClass);
  6388. if (!this.multiple) {
  6389. if (!isChecked) {
  6390. this.dropdown.close();
  6391. this.$shadowOptions.not($item).removeClass(options.selectedClass);
  6392. } else {
  6393. return;
  6394. }
  6395. }
  6396. $item.toggleClass(options.selectedClass);
  6397. this.syncData(item);
  6398. };
  6399. /**
  6400. * syncData
  6401. * @desc if `item` set, only sync `item` related option
  6402. * @param {Object} item
  6403. */
  6404. Selected.prototype.syncData = function(item) {
  6405. var _this = this;
  6406. var options = this.options;
  6407. var status = [];
  6408. var $checked = $([]);
  6409. this.$shadowOptions.filter('.' + options.selectedClass).each(function() {
  6410. var $this = $(this);
  6411. status.push($this.find('.am-selected-text').text());
  6412. if (!item) {
  6413. $checked = $checked.add(_this.$originalOptions.
  6414. filter('[value="' + $this.data('value') + '"]').
  6415. prop('selected', true));
  6416. }
  6417. });
  6418. if (item) {
  6419. var $item = $(item);
  6420. this.$originalOptions.filter('[value="' + $item.data('value') + '"]').
  6421. prop('selected', $item.hasClass(options.selectedClass));
  6422. } else {
  6423. this.$originalOptions.not($checked).prop('selected', false);
  6424. }
  6425. // nothing selected
  6426. if (!this.$element.val()) {
  6427. status = [options.noSelectedText];
  6428. }
  6429. this.$status.text(status.join(', '));
  6430. this.$element.trigger('change');
  6431. };
  6432. Selected.prototype.bindEvents = function() {
  6433. var _this = this;
  6434. var header = 'am-selected-list-header';
  6435. var handleKeyup = UI.utils.debounce(function(e) {
  6436. _this.$shadowOptions.not('.' + header).hide().
  6437. filter(':containsNC("' + e.target.value + '")').show();
  6438. }, 100);
  6439. this.$list.on('click', '> li', function(e) {
  6440. var $this = $(this);
  6441. !$this.hasClass(_this.options.disabledClass) &&
  6442. !$this.hasClass(header) && _this.setChecked(this);
  6443. });
  6444. // simple search with jQuery :contains
  6445. this.$searchField.on('keyup.selected.amui', handleKeyup);
  6446. // empty search keywords
  6447. this.$selector.on('closed.dropdown.amui', function() {
  6448. _this.$searchField.val('');
  6449. _this.$shadowOptions.css({display: ''});
  6450. });
  6451. // observe DOM
  6452. if (UI.support.mutationobserver) {
  6453. this.observer = new UI.support.mutationobserver(function() {
  6454. _this.$element.trigger('changed.selected.amui');
  6455. });
  6456. this.observer.observe(this.$element[0], {
  6457. childList: true,
  6458. attributes: true,
  6459. subtree: true,
  6460. characterData: true
  6461. });
  6462. }
  6463. // custom event
  6464. this.$element.on('changed.selected.amui', function() {
  6465. _this.renderOptions();
  6466. _this.syncData();
  6467. });
  6468. };
  6469. Selected.prototype.destroy = function() {
  6470. this.$element.removeData('amui.selected').show();
  6471. this.$selector.remove();
  6472. };
  6473. function Plugin(option) {
  6474. return this.each(function() {
  6475. var $this = $(this);
  6476. var data = $this.data('amui.selected');
  6477. var options = $.extend({}, UI.utils.parseOptions($this.data('amSelected')),
  6478. UI.utils.parseOptions($this.data('amSelectit')),
  6479. typeof option === 'object' && option);
  6480. if (!data && option === 'destroy') {
  6481. return;
  6482. }
  6483. if (!data) {
  6484. $this.data('amui.selected', (data = new Selected(this, options)));
  6485. }
  6486. if (typeof option == 'string') {
  6487. data[option] && data[option]();
  6488. }
  6489. });
  6490. }
  6491. // Conflict with jQuery form
  6492. // https://github.com/malsup/form/blob/6bf24a5f6d8be65f4e5491863180c09356d9dadd/jquery.form.js#L1240-L1258
  6493. // https://github.com/allmobilize/amazeui/issues/379
  6494. $.fn.selected = $.fn.selectIt = Plugin;
  6495. UI.ready(function(context) {
  6496. $('[data-am-selected]', context).selectIt();
  6497. });
  6498. $.AMUI.selected = Selected;
  6499. module.exports = Selected;
  6500. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6501. },{"2":2}],21:[function(_dereq_,module,exports){
  6502. (function (global){
  6503. 'use strict';
  6504. _dereq_(12);
  6505. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  6506. var UI = _dereq_(2);
  6507. var QRCode = _dereq_(31);
  6508. var doc = document;
  6509. var $doc = $(doc);
  6510. var Share = function(options) {
  6511. this.options = $.extend({}, Share.DEFAULTS, options || {});
  6512. this.$element = null;
  6513. this.$wechatQr = null;
  6514. this.pics = null;
  6515. this.inited = false;
  6516. this.active = false;
  6517. // this.init();
  6518. };
  6519. Share.DEFAULTS = {
  6520. sns: ['weibo', 'qq', 'qzone', 'tqq', 'wechat', 'renren'],
  6521. title: '分享到',
  6522. cancel: '取消',
  6523. closeOnShare: true,
  6524. id: UI.utils.generateGUID('am-share'),
  6525. desc: 'Hi,孤夜观天象,发现一个不错的西西,分享一下下 ;-)',
  6526. via: 'Amaze UI',
  6527. tpl: '<div class="am-share am-modal-actions" id="<%= id %>">' +
  6528. '<h3 class="am-share-title"><%= title %></h3>' +
  6529. '<ul class="am-share-sns am-avg-sm-3">' +
  6530. '<% for(var i = 0; i < sns.length; i++) {%>' +
  6531. '<li>' +
  6532. '<a href="<%= sns[i].shareUrl %>" ' +
  6533. 'data-am-share-to="<%= sns[i].id %>" >' +
  6534. '<i class="am-icon-<%= sns[i].icon %>"></i>' +
  6535. '<span><%= sns[i].title %></span>' +
  6536. '</a></li>' +
  6537. '<% } %></ul>' +
  6538. '<div class="am-share-footer">' +
  6539. '<button class="am-btn am-btn-default am-btn-block" ' +
  6540. 'data-am-share-close><%= cancel %></button></div>' +
  6541. '</div>'
  6542. };
  6543. Share.SNS = {
  6544. weibo: {
  6545. title: '新浪微博',
  6546. url: 'http://service.weibo.com/share/share.php',
  6547. width: 620,
  6548. height: 450,
  6549. icon: 'weibo'
  6550. },
  6551. // url 链接地址
  6552. // title:”, 分享的文字内容(可选,默认为所在页面的title)
  6553. // appkey:”, 您申请的应用appkey,显示分享来源(可选)
  6554. // pic:”, 分享图片的路径(可选)
  6555. // ralateUid:”, 关联用户的UID,分享微博会@该用户(可选)
  6556. // NOTE: 会自动抓取图片,不用指定 pic
  6557. qq: {
  6558. title: 'QQ 好友',
  6559. url: 'http://connect.qq.com/widget/shareqq/index.html',
  6560. icon: 'qq'
  6561. },
  6562. // url:,
  6563. // title:'', 分享标题(可选)
  6564. // pics:'', 分享图片的路径(可选)
  6565. // summary:'', 分享摘要(可选)
  6566. // site:'', 分享来源 如:腾讯网(可选)
  6567. // desc: '' 发送给用户的消息
  6568. // NOTE: 经过测试,最终发给用户的只有 url 和 desc
  6569. qzone: {
  6570. title: 'QQ 空间',
  6571. url: 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey',
  6572. icon: 'star'
  6573. },
  6574. // http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=xxx&title=xxx&desc=&summary=&site=
  6575. // url:,
  6576. // title:'', 分享标题(可选)
  6577. // desc:'', 默认分享理由(可选)
  6578. // summary:'', 分享摘要(可选)
  6579. // site:'', 分享来源 如:腾讯网(可选)
  6580. // pics:'', 分享图片的路径(可选),不会自动抓取,多个图片用|分隔
  6581. tqq: {
  6582. title: '腾讯微博',
  6583. url: 'http://v.t.qq.com/share/share.php',
  6584. icon: 'tencent-weibo'
  6585. },
  6586. // url=xx&title=&appkey=801cf76d3cfc44ada52ec13114e84a96
  6587. // url
  6588. // title
  6589. // pic 多个图片用 | 分隔
  6590. // appkey
  6591. // NOTE: 不会自动抓取图片
  6592. wechat: {
  6593. title: '微信',
  6594. url: '[qrcode]',
  6595. icon: 'wechat'
  6596. },
  6597. // 生成一个二维码 供用户扫描
  6598. // 相关接口 https://github.com/zxlie/WeixinApi
  6599. renren: {
  6600. title: '人人网',
  6601. url: 'http://widget.renren.com/dialog/share',
  6602. icon: 'renren'
  6603. },
  6604. // http://widget.renren.com/dialog/share?resourceUrl=www&srcUrl=www&title=ww&description=xxx
  6605. // 550 * 400
  6606. // resourceUrl : '', // 分享的资源Url
  6607. // srcUrl : '', // 分享的资源来源Url,
  6608. // // 默认为header中的Referer,如果分享失败可以调整此值为resourceUrl试试
  6609. // pic : '', // 分享的主题图片,会自动抓取
  6610. // title : '', // 分享的标题
  6611. // description : '' // 分享的详细描述
  6612. // NOTE: 经过测试,直接使用 url 参数即可
  6613. douban: {
  6614. title: '豆瓣',
  6615. url: 'http://www.douban.com/recommend/',
  6616. icon: 'share-alt'
  6617. },
  6618. // http://www.douban.com/service/sharebutton
  6619. // 450 * 330
  6620. // http://www.douban.com/share/service?bm=1&image=&href=xxx&updated=&name=
  6621. // href 链接
  6622. // name 标题
  6623. /* void (function() {
  6624. var d = document, e = encodeURIComponent,
  6625. s1 = window.getSelection, s2 = d.getSelection,
  6626. s3 = d.selection, s = s1 ? s1()
  6627. : s2 ? s2() : s3 ? s3.createRange().text : '',
  6628. r = 'http://www.douban.com/recommend/?url=&title=&sel=&v=1&r=1'
  6629. })();
  6630. */
  6631. // tsohu: '',
  6632. // http://t.sohu.com/third/post.jsp?url=&title=&content=utf-8&pic=
  6633. // print: '',
  6634. mail: {
  6635. title: '邮件分享',
  6636. url: 'mailto:',
  6637. icon: 'envelope-o'
  6638. },
  6639. sms: {
  6640. title: '短信分享',
  6641. url: 'sms:',
  6642. icon: 'comment'
  6643. }
  6644. };
  6645. Share.prototype.render = function() {
  6646. var options = this.options;
  6647. var snsData = [];
  6648. var title = encodeURIComponent(doc.title);
  6649. var link = encodeURIComponent(doc.location);
  6650. var msgBody = '?body=' + title + link;
  6651. options.sns.forEach(function(item, i) {
  6652. if (Share.SNS[item]) {
  6653. var tmp = Share.SNS[item];
  6654. var shareUrl;
  6655. tmp.id = item;
  6656. if (item === 'mail') {
  6657. shareUrl = msgBody + '&subject=' + options.desc;
  6658. } else if (item === 'sms') {
  6659. shareUrl = msgBody;
  6660. } else {
  6661. shareUrl = '?url=' + link + '&title=' + title;
  6662. }
  6663. tmp.shareUrl = tmp.url + shareUrl;
  6664. snsData.push(tmp);
  6665. }
  6666. });
  6667. return UI.template(options.tpl, $.extend({}, options, {sns: snsData}));
  6668. };
  6669. Share.prototype.init = function() {
  6670. if (this.inited) {
  6671. return;
  6672. }
  6673. var me = this;
  6674. var shareItem = '[data-am-share-to]';
  6675. $doc.ready($.proxy(function() {
  6676. $('body').append(this.render()); // append share DOM to body
  6677. this.$element = $('#' + this.options.id);
  6678. this.$element.find('[data-am-share-close]').
  6679. on('click.share.amui', function() {
  6680. me.close();
  6681. });
  6682. }, this));
  6683. $doc.on('click.share.amui', shareItem, $.proxy(function(e) {
  6684. var $clicked = $(e.target);
  6685. var $target = $clicked.is(shareItem) && $clicked ||
  6686. $clicked.parent(shareItem);
  6687. var sns = $target.attr('data-am-share-to');
  6688. if (!(sns === 'mail' || sns === 'sms')) {
  6689. e.preventDefault();
  6690. this.shareTo(sns, this.setData(sns));
  6691. }
  6692. this.close();
  6693. }, this));
  6694. this.inited = true;
  6695. };
  6696. Share.prototype.open = function() {
  6697. !this.inited && this.init();
  6698. this.$element && this.$element.modal('open');
  6699. this.$element.trigger('open.share.amui');
  6700. this.active = true;
  6701. };
  6702. Share.prototype.close = function() {
  6703. this.$element && this.$element.modal('close');
  6704. this.$element.trigger('close.share.amui');
  6705. this.active = false;
  6706. };
  6707. Share.prototype.toggle = function() {
  6708. this.active ? this.close() : this.open();
  6709. };
  6710. Share.prototype.setData = function(sns) {
  6711. if (!sns) {
  6712. return;
  6713. }
  6714. var shareData = {
  6715. url: doc.location,
  6716. title: doc.title
  6717. };
  6718. var desc = this.options.desc;
  6719. var imgSrc = this.pics || [];
  6720. var qqReg = /^(qzone|qq|tqq)$/;
  6721. if (qqReg.test(sns) && !imgSrc.length) {
  6722. var allImages = doc.images;
  6723. for (var i = 0; i < allImages.length && i < 10; i++) {
  6724. !!allImages[i].src && imgSrc.push(encodeURIComponent(allImages[i].src));
  6725. }
  6726. this.pics = imgSrc; // 缓存图片
  6727. }
  6728. switch (sns) {
  6729. case 'qzone':
  6730. shareData.desc = desc;
  6731. shareData.site = this.options.via;
  6732. shareData.pics = imgSrc.join('|');
  6733. // TODO: 抓取图片多张
  6734. break;
  6735. case 'qq':
  6736. shareData.desc = desc;
  6737. shareData.site = this.options.via;
  6738. shareData.pics = imgSrc[0];
  6739. // 抓取一张图片
  6740. break;
  6741. case 'tqq':
  6742. // 抓取图片多张
  6743. shareData.pic = imgSrc.join('|');
  6744. break;
  6745. }
  6746. return shareData;
  6747. };
  6748. Share.prototype.shareTo = function(sns, data) {
  6749. var snsInfo = Share.SNS[sns];
  6750. if (!snsInfo) {
  6751. return;
  6752. }
  6753. if (sns === 'wechat' || sns === 'weixin') {
  6754. return this.wechatQr();
  6755. }
  6756. var query = [];
  6757. for (var key in data) {
  6758. if (data[key]) {
  6759. // 避免 encode 图片分隔符 |
  6760. query.push(key.toString() + '=' + ((key === 'pic' || key === 'pics') ?
  6761. data[key] : encodeURIComponent(data[key])));
  6762. }
  6763. }
  6764. window.open(snsInfo.url + '?' + query.join('&'));
  6765. };
  6766. Share.prototype.wechatQr = function() {
  6767. if (!this.$wechatQr) {
  6768. var qrId = UI.utils.generateGUID('am-share-wechat');
  6769. var $qr = $('<div class="am-modal am-modal-no-btn am-share-wechat-qr">' +
  6770. '<div class="am-modal-dialog"><div class="am-modal-hd">分享到微信 ' +
  6771. '<a href="" class="am-close am-close-spin" ' +
  6772. 'data-am-modal-close>&times;</a> </div>' +
  6773. '<div class="am-modal-bd">' +
  6774. '<div class="am-share-wx-qr"></div>' +
  6775. '<div class="am-share-wechat-tip">' +
  6776. '打开微信,点击底部的<em>发现</em>,<br/> ' +
  6777. '使用<em>扫一扫</em>将网页分享至朋友圈</div></div></div></div>');
  6778. $qr.attr('id', qrId);
  6779. var qrNode = new QRCode({
  6780. render: 'canvas',
  6781. correctLevel: 0,
  6782. text: doc.location.href,
  6783. width: 180,
  6784. height: 180,
  6785. background: '#fff',
  6786. foreground: '#000'
  6787. });
  6788. $qr.find('.am-share-wx-qr').html(qrNode);
  6789. $qr.appendTo($('body'));
  6790. this.$wechatQr = $('#' + qrId);
  6791. }
  6792. this.$wechatQr.modal('open');
  6793. };
  6794. var share = new Share();
  6795. $doc.on('click.share.amui.data-api', '[data-am-toggle="share"]', function(e) {
  6796. e.preventDefault();
  6797. share.toggle();
  6798. });
  6799. $.AMUI.share = share;
  6800. module.exports = share;
  6801. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6802. },{"12":12,"2":2,"31":31}],22:[function(_dereq_,module,exports){
  6803. (function (global){
  6804. 'use strict';
  6805. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  6806. var UI = _dereq_(2);
  6807. var rAF = UI.utils.rAF;
  6808. var cAF = UI.utils.cancelAF;
  6809. /**
  6810. * Smooth Scroll
  6811. * @param position
  6812. * @via http://mir.aculo.us/2014/01/19/scrolling-dom-elements-to-the-top-a-zepto-plugin/
  6813. */
  6814. // Usage: $(window).smoothScroll([options])
  6815. // only allow one scroll to top operation to be in progress at a time,
  6816. // which is probably what you want
  6817. var smoothScrollInProgress = false;
  6818. var SmoothScroll = function(element, options) {
  6819. options = options || {};
  6820. var $this = $(element);
  6821. var targetY = parseInt(options.position) || SmoothScroll.DEFAULTS.position;
  6822. var initialY = $this.scrollTop();
  6823. var lastY = initialY;
  6824. var delta = targetY - initialY;
  6825. // duration in ms, make it a bit shorter for short distances
  6826. // this is not scientific and you might want to adjust this for
  6827. // your preferences
  6828. var speed = options.speed ||
  6829. Math.min(750, Math.min(1500, Math.abs(initialY - targetY)));
  6830. // temp variables (t will be a position between 0 and 1, y is the calculated scrollTop)
  6831. var start;
  6832. var t;
  6833. var y;
  6834. var cancelScroll = function() {
  6835. abort();
  6836. };
  6837. // abort if already in progress or nothing to scroll
  6838. if (smoothScrollInProgress) {
  6839. return;
  6840. }
  6841. if (delta === 0) {
  6842. return;
  6843. }
  6844. // quint ease-in-out smoothing, from
  6845. // https://github.com/madrobby/scripty2/blob/master/src/effects/transitions/penner.js#L127-L136
  6846. function smooth(pos) {
  6847. if ((pos /= 0.5) < 1) {
  6848. return 0.5 * Math.pow(pos, 5);
  6849. }
  6850. return 0.5 * (Math.pow((pos - 2), 5) + 2);
  6851. }
  6852. function abort() {
  6853. $this.off('touchstart.smoothscroll.amui', cancelScroll);
  6854. smoothScrollInProgress = false;
  6855. }
  6856. // when there's a touch detected while scrolling is in progress, abort
  6857. // the scrolling (emulates native scrolling behavior)
  6858. $this.on('touchstart.smoothscroll.amui', cancelScroll);
  6859. smoothScrollInProgress = true;
  6860. // start rendering away! note the function given to frame
  6861. // is named "render" so we can reference it again further down
  6862. function render(now) {
  6863. if (!smoothScrollInProgress) {
  6864. return;
  6865. }
  6866. if (!start) {
  6867. start = now;
  6868. }
  6869. // calculate t, position of animation in [0..1]
  6870. t = Math.min(1, Math.max((now - start) / speed, 0));
  6871. // calculate the new scrollTop position (don't forget to smooth)
  6872. y = Math.round(initialY + delta * smooth(t));
  6873. // bracket scrollTop so we're never over-scrolling
  6874. if (delta > 0 && y > targetY) {
  6875. y = targetY;
  6876. }
  6877. if (delta < 0 && y < targetY) {
  6878. y = targetY;
  6879. }
  6880. // only actually set scrollTop if there was a change fromt he last frame
  6881. if (lastY != y) {
  6882. $this.scrollTop(y);
  6883. }
  6884. lastY = y;
  6885. // if we're not done yet, queue up an other frame to render,
  6886. // or clean up
  6887. if (y !== targetY) {
  6888. cAF(scrollRAF);
  6889. scrollRAF = rAF(render);
  6890. } else {
  6891. cAF(scrollRAF);
  6892. abort();
  6893. }
  6894. }
  6895. var scrollRAF = rAF(render);
  6896. };
  6897. SmoothScroll.DEFAULTS = {
  6898. position: 0
  6899. };
  6900. $.fn.smoothScroll = function(option) {
  6901. return this.each(function() {
  6902. new SmoothScroll(this, option);
  6903. });
  6904. };
  6905. // Init code
  6906. $(document).on('click.smoothScroll.amui.data-api', '[data-am-smooth-scroll]',
  6907. function(e) {
  6908. e.preventDefault();
  6909. var options = UI.utils.parseOptions($(this).data('amSmoothScroll'));
  6910. $(window).smoothScroll(options);
  6911. });
  6912. module.exports = SmoothScroll;
  6913. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6914. },{"2":2}],23:[function(_dereq_,module,exports){
  6915. (function (global){
  6916. 'use strict';
  6917. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  6918. var UI = _dereq_(2);
  6919. /**
  6920. * @via https://github.com/uikit/uikit/blob/master/src/js/addons/sticky.js
  6921. * @license https://github.com/uikit/uikit/blob/master/LICENSE.md
  6922. */
  6923. // Sticky Class
  6924. var Sticky = function(element, options) {
  6925. var me = this;
  6926. this.options = $.extend({}, Sticky.DEFAULTS, options);
  6927. this.$element = $(element);
  6928. this.sticked = null;
  6929. this.inited = null;
  6930. this.$holder = undefined;
  6931. this.$window = $(window).
  6932. on('scroll.sticky.amui',
  6933. UI.utils.debounce($.proxy(this.checkPosition, this), 10)).
  6934. on('resize.sticky.amui orientationchange.sticky.amui',
  6935. UI.utils.debounce(function() {
  6936. me.reset(true, function() {
  6937. me.checkPosition();
  6938. });
  6939. }, 50)).
  6940. on('load.sticky.amui', $.proxy(this.checkPosition, this));
  6941. // the `.offset()` is diff between jQuery & Zepto.js
  6942. // jQuery: return `top` and `left`
  6943. // Zepto.js: return `top`, `left`, `width`, `height`
  6944. this.offset = this.$element.offset();
  6945. this.init();
  6946. };
  6947. Sticky.DEFAULTS = {
  6948. top: 0,
  6949. bottom: 0,
  6950. animation: '',
  6951. className: {
  6952. sticky: 'am-sticky',
  6953. resetting: 'am-sticky-resetting',
  6954. stickyBtm: 'am-sticky-bottom',
  6955. animationRev: 'am-animation-reverse'
  6956. }
  6957. };
  6958. Sticky.prototype.init = function() {
  6959. var result = this.check();
  6960. if (!result) {
  6961. return false;
  6962. }
  6963. var $element = this.$element;
  6964. var $elementMargin = '';
  6965. $.each($element.css(
  6966. ['marginTop', 'marginRight', 'marginBottom', 'marginLeft']),
  6967. function(name, value) {
  6968. return $elementMargin += ' ' + value;
  6969. });
  6970. var $holder = $('<div class="am-sticky-placeholder"></div>').css({
  6971. height: $element.css('position') != 'absolute' ?
  6972. $element.outerHeight() : '',
  6973. float: $element.css('float') != 'none' ? $element.css('float') : '',
  6974. margin: $elementMargin
  6975. });
  6976. this.$holder = $element.css('margin', 0).wrap($holder).parent();
  6977. this.inited = 1;
  6978. return true;
  6979. };
  6980. Sticky.prototype.reset = function(force, cb) {
  6981. var options = this.options;
  6982. var $element = this.$element;
  6983. var animation = (options.animation) ?
  6984. ' am-animation-' + options.animation : '';
  6985. var complete = function() {
  6986. $element.css({position: '', top: '', width: '', left: '', margin: 0});
  6987. $element.removeClass([
  6988. animation,
  6989. options.className.animationRev,
  6990. options.className.sticky,
  6991. options.className.resetting
  6992. ].join(' '));
  6993. this.animating = false;
  6994. this.sticked = false;
  6995. this.offset = $element.offset();
  6996. cb && cb();
  6997. }.bind(this);
  6998. $element.addClass(options.className.resetting);
  6999. if (!force && options.animation && UI.support.animation) {
  7000. this.animating = true;
  7001. $element.removeClass(animation).one(UI.support.animation.end, function() {
  7002. complete();
  7003. }).width(); // force redraw
  7004. $element.addClass(animation + ' ' + options.className.animationRev);
  7005. } else {
  7006. complete();
  7007. }
  7008. };
  7009. Sticky.prototype.check = function() {
  7010. if (!this.$element.is(':visible')) {
  7011. return false;
  7012. }
  7013. var media = this.options.media;
  7014. if (media) {
  7015. switch (typeof(media)) {
  7016. case 'number':
  7017. if (window.innerWidth < media) {
  7018. return false;
  7019. }
  7020. break;
  7021. case 'string':
  7022. if (window.matchMedia && !window.matchMedia(media).matches) {
  7023. return false;
  7024. }
  7025. break;
  7026. }
  7027. }
  7028. return true;
  7029. };
  7030. Sticky.prototype.checkPosition = function() {
  7031. if (!this.inited) {
  7032. var initialized = this.init();
  7033. if (!initialized) {
  7034. return;
  7035. }
  7036. }
  7037. var options = this.options;
  7038. var scrollTop = this.$window.scrollTop();
  7039. var offsetTop = options.top;
  7040. var offsetBottom = options.bottom;
  7041. var $element = this.$element;
  7042. var animation = (options.animation) ?
  7043. ' am-animation-' + options.animation : '';
  7044. var className = [options.className.sticky, animation].join(' ');
  7045. if (typeof offsetBottom == 'function') {
  7046. offsetBottom = offsetBottom(this.$element);
  7047. }
  7048. var checkResult = (scrollTop > this.$holder.offset().top);
  7049. if (!this.sticked && checkResult) {
  7050. $element.addClass(className);
  7051. } else if (this.sticked && !checkResult) {
  7052. this.reset();
  7053. }
  7054. this.$holder.height($element.is(':visible') ? $element.height() : 0);
  7055. if (checkResult) {
  7056. $element.css({
  7057. top: offsetTop,
  7058. left: this.$holder.offset().left,
  7059. width: this.$holder.width()
  7060. });
  7061. /*
  7062. if (offsetBottom) {
  7063. // (底部边距 + 元素高度 > 窗口高度) 时定位到底部
  7064. if ((offsetBottom + this.offset.height > $(window).height()) &&
  7065. (scrollTop + $(window).height() >= scrollHeight - offsetBottom)) {
  7066. $element.addClass(options.className.stickyBtm).
  7067. css({top: $(window).height() - offsetBottom - this.offset.height});
  7068. } else {
  7069. $element.removeClass(options.className.stickyBtm).css({top: offsetTop});
  7070. }
  7071. }
  7072. */
  7073. }
  7074. this.sticked = checkResult;
  7075. };
  7076. // Sticky Plugin
  7077. function Plugin(option) {
  7078. return this.each(function() {
  7079. var $this = $(this);
  7080. var data = $this.data('amui.sticky');
  7081. var options = typeof option == 'object' && option;
  7082. if (!data) {
  7083. $this.data('amui.sticky', (data = new Sticky(this, options)));
  7084. }
  7085. if (typeof option == 'string') {
  7086. data[option]();
  7087. }
  7088. });
  7089. }
  7090. $.fn.sticky = Plugin;
  7091. // Init code
  7092. $(window).on('load', function() {
  7093. $('[data-am-sticky]').each(function() {
  7094. var $this = $(this);
  7095. var options = UI.utils.options($this.attr('data-am-sticky'));
  7096. Plugin.call($this, options);
  7097. });
  7098. });
  7099. $.AMUI.sticky = Sticky;
  7100. module.exports = Sticky;
  7101. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7102. },{"2":2}],24:[function(_dereq_,module,exports){
  7103. (function (global){
  7104. 'use strict';
  7105. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  7106. var UI = _dereq_(2);
  7107. var Hammer = _dereq_(30);
  7108. var supportTransition = UI.support.transition;
  7109. var animation = UI.support.animation;
  7110. /**
  7111. * @via https://github.com/twbs/bootstrap/blob/master/js/tab.js
  7112. * @copyright 2011-2014 Twitter, Inc.
  7113. * @license MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  7114. */
  7115. var Tabs = function(element, options) {
  7116. this.$element = $(element);
  7117. this.options = $.extend({}, Tabs.DEFAULTS, options || {});
  7118. this.$tabNav = this.$element.find(this.options.selector.nav);
  7119. this.$navs = this.$tabNav.find('a');
  7120. this.$content = this.$element.find(this.options.selector.content);
  7121. this.$tabPanels = this.$content.find(this.options.selector.panel);
  7122. this.transitioning = null;
  7123. this.init();
  7124. };
  7125. Tabs.DEFAULTS = {
  7126. selector: {
  7127. nav: '> .am-tabs-nav',
  7128. content: '> .am-tabs-bd',
  7129. panel: '> .am-tab-panel'
  7130. },
  7131. className: {
  7132. active: 'am-active'
  7133. }
  7134. };
  7135. Tabs.prototype.init = function() {
  7136. var _this = this;
  7137. var options = this.options;
  7138. // Activate the first Tab when no active Tab or multiple active Tabs
  7139. if (this.$tabNav.find('> .am-active').length !== 1) {
  7140. var $tabNav = this.$tabNav;
  7141. this.activate($tabNav.children('li').first(), $tabNav);
  7142. this.activate(this.$tabPanels.first(), this.$content);
  7143. }
  7144. this.$navs.on('click.tabs.amui', function(e) {
  7145. e.preventDefault();
  7146. _this.open($(this));
  7147. });
  7148. // TODO: nested Tabs touch events
  7149. if (!options.noSwipe) {
  7150. if (!this.$content.length) {
  7151. return this;
  7152. }
  7153. var hammer = new Hammer(this.$content[0]);
  7154. hammer.get('pan').set({
  7155. direction: Hammer.DIRECTION_HORIZONTAL,
  7156. threshold: 120
  7157. });
  7158. hammer.on('panleft', UI.utils.debounce(function(e) {
  7159. e.preventDefault();
  7160. var $target = $(e.target);
  7161. if (!$target.is(options.selector.panel)) {
  7162. $target = $target.closest(options.selector.panel);
  7163. }
  7164. $target.focus();
  7165. var $nav = _this.getNextNav($target);
  7166. $nav && _this.open($nav);
  7167. }, 100));
  7168. hammer.on('panright', UI.utils.debounce(function(e) {
  7169. e.preventDefault();
  7170. var $target = $(e.target);
  7171. if (!$target.is(options.selector.panel)) {
  7172. $target = $target.closest(options.selector.panel);
  7173. }
  7174. var $nav = _this.getPrevNav($target);
  7175. $nav && _this.open($nav);
  7176. }, 100));
  7177. }
  7178. };
  7179. Tabs.prototype.open = function($nav) {
  7180. if (!$nav ||
  7181. this.transitioning ||
  7182. $nav.parent('li').hasClass('am-active')) {
  7183. return;
  7184. }
  7185. var $tabNav = this.$tabNav;
  7186. var $navs = this.$navs;
  7187. var $tabContent = this.$content;
  7188. var href = $nav.attr('href');
  7189. var regexHash = /^#.+$/;
  7190. var $target = regexHash.test(href) && this.$content.find(href) ||
  7191. this.$tabPanels.eq($navs.index($nav));
  7192. var previous = $tabNav.find('.am-active a')[0];
  7193. var e = $.Event('open.tabs.amui', {
  7194. relatedTarget: previous
  7195. });
  7196. $nav.trigger(e);
  7197. if (e.isDefaultPrevented()) {
  7198. return;
  7199. }
  7200. // activate Tab nav
  7201. this.activate($nav.closest('li'), $tabNav);
  7202. // activate Tab content
  7203. this.activate($target, $tabContent, function() {
  7204. $nav.trigger({
  7205. type: 'opened.tabs.amui',
  7206. relatedTarget: previous
  7207. });
  7208. });
  7209. };
  7210. Tabs.prototype.activate = function($element, $container, callback) {
  7211. this.transitioning = true;
  7212. var $active = $container.find('> .am-active');
  7213. var transition = callback && supportTransition && !!$active.length;
  7214. $active.removeClass('am-active am-in');
  7215. $element.addClass('am-active');
  7216. if (transition) {
  7217. $element.redraw(); // reflow for transition
  7218. $element.addClass('am-in');
  7219. } else {
  7220. $element.removeClass('am-fade');
  7221. }
  7222. function complete() {
  7223. callback && callback();
  7224. this.transitioning = false;
  7225. }
  7226. transition ?
  7227. $active.one(supportTransition.end, $.proxy(complete, this)) :
  7228. $.proxy(complete, this)();
  7229. };
  7230. Tabs.prototype.getNextNav = function($panel) {
  7231. var navIndex = this.$tabPanels.index($panel);
  7232. var rightSpring = 'am-animation-right-spring';
  7233. if (navIndex + 1 >= this.$navs.length) { // last one
  7234. animation && $panel.addClass(rightSpring).on(animation.end, function() {
  7235. $panel.removeClass(rightSpring);
  7236. });
  7237. return null;
  7238. } else {
  7239. return this.$navs.eq(navIndex + 1);
  7240. }
  7241. };
  7242. Tabs.prototype.getPrevNav = function($panel) {
  7243. var navIndex = this.$tabPanels.index($panel);
  7244. var leftSpring = 'am-animation-left-spring';
  7245. if (navIndex === 0) { // first one
  7246. animation && $panel.addClass(leftSpring).on(animation.end, function() {
  7247. $panel.removeClass(leftSpring);
  7248. });
  7249. return null;
  7250. } else {
  7251. return this.$navs.eq(navIndex - 1);
  7252. }
  7253. };
  7254. // Plugin
  7255. function Plugin(option) {
  7256. return this.each(function() {
  7257. var $this = $(this);
  7258. var $tabs = $this.is('.am-tabs') && $this || $this.closest('.am-tabs');
  7259. var data = $tabs.data('amui.tabs');
  7260. var options = $.extend({}, $.isPlainObject(option) ? option : {},
  7261. UI.utils.parseOptions($this.data('amTabs')));
  7262. if (!data) {
  7263. $tabs.data('amui.tabs', (data = new Tabs($tabs[0], options)));
  7264. }
  7265. if (typeof option == 'string' && $this.is('.am-tabs-nav a')) {
  7266. data[option]($this);
  7267. }
  7268. });
  7269. }
  7270. $.fn.tabs = Plugin;
  7271. // Init code
  7272. UI.ready(function(context) {
  7273. $('[data-am-tabs]', context).tabs();
  7274. });
  7275. $.AMUI.tabs = Tabs;
  7276. module.exports = Tabs;
  7277. // TODO: 1. Ajax 支持
  7278. // 2. touch 事件处理逻辑优化
  7279. // 3. 暴露方法 API
  7280. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7281. },{"2":2,"30":30}],25:[function(_dereq_,module,exports){
  7282. (function (global){
  7283. 'use strict';
  7284. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  7285. var UI = _dereq_(2);
  7286. /**
  7287. * UCheck
  7288. * @via https://github.com/designmodo/Flat-UI/blob/8ef98df23ba7f5033e596a9bd05b53b535a9fe99/js/radiocheck.js
  7289. * @license CC BY 3.0 & MIT
  7290. * @param element
  7291. * @param options
  7292. * @constructor
  7293. */
  7294. var UCheck = function(element, options) {
  7295. this.options = $.extend({}, UCheck.DEFAULTS, options);
  7296. // this.options = $.extend({}, UCheck.DEFAULTS, this.$element.data(), options);
  7297. this.$element = $(element);
  7298. this.init();
  7299. };
  7300. UCheck.DEFAULTS = {
  7301. checkboxClass: 'am-ucheck-checkbox',
  7302. radioClass: 'am-ucheck-radio',
  7303. checkboxTpl: '<span class="am-ucheck-icons">' +
  7304. '<i class="am-icon-unchecked"></i><i class="am-icon-checked"></i></span>',
  7305. radioTpl: '<span class="am-ucheck-icons">' +
  7306. '<i class="am-icon-unchecked"></i><i class="am-icon-checked"></i></span>'
  7307. };
  7308. UCheck.prototype.init = function() {
  7309. var $element = this.$element;
  7310. var element = $element[0];
  7311. var options = this.options;
  7312. if (element.type === 'checkbox') {
  7313. $element.addClass(options.checkboxClass).after(options.checkboxTpl);
  7314. } else if (element.type === 'radio') {
  7315. $element.addClass(options.radioClass).after(options.radioTpl);
  7316. }
  7317. };
  7318. UCheck.prototype.check = function() {
  7319. this.$element.prop('checked', true)
  7320. .trigger('change.ucheck.amui').trigger('checked.ucheck.amui');
  7321. },
  7322. UCheck.prototype.uncheck = function() {
  7323. this.$element.prop('checked', false)
  7324. .trigger('change.ucheck.amui').trigger('unchecked.ucheck.amui');
  7325. },
  7326. UCheck.prototype.toggle = function() {
  7327. this.$element.prop('checked', function(i, value) {
  7328. return !value;
  7329. }).trigger('change.ucheck.amui').trigger('toggled.ucheck.amui');
  7330. },
  7331. UCheck.prototype.disable = function() {
  7332. this.$element.prop('disabled', true).
  7333. trigger('change.ucheck.amui').trigger('disabled.ucheck.amui');
  7334. },
  7335. UCheck.prototype.enable = function() {
  7336. this.$element.prop('disabled', false);
  7337. this.$element.trigger('change.ucheck.amui').trigger('enabled.ucheck.amui');
  7338. },
  7339. UCheck.prototype.destroy = function() {
  7340. this.$element.removeData('amui.ucheck').
  7341. removeClass(this.options.checkboxClass + ' ' + this.options.radioClass).
  7342. next('.am-ucheck-icons').remove().
  7343. end().trigger('destroyed.ucheck.amui');
  7344. };
  7345. function Plugin(option) {
  7346. return this.each(function() {
  7347. var $this = $(this);
  7348. var data = $this.data('amui.ucheck');
  7349. var options = $.extend({}, UI.utils.parseOptions($this.data('amUcheck')),
  7350. typeof option === 'object' && option);
  7351. if (!data && option === 'destroy') {
  7352. return;
  7353. }
  7354. if (!data) {
  7355. $this.data('amui.ucheck', (data = new UCheck(this, options)));
  7356. }
  7357. if (typeof option == 'string') {
  7358. data[option] && data[option]();
  7359. }
  7360. // Adding 'am-nohover' class for touch devices
  7361. if (UI.support.touch) {
  7362. $this.parent().hover(function() {
  7363. $this.addClass('am-nohover');
  7364. }, function() {
  7365. $this.removeClass('am-nohover');
  7366. });
  7367. }
  7368. });
  7369. }
  7370. $.fn.uCheck = Plugin;
  7371. UI.ready(function(context) {
  7372. $('[data-am-ucheck]', context).uCheck();
  7373. });
  7374. $.AMUI.uCheck = UCheck;
  7375. module.exports = UCheck;
  7376. // TODO: 与表单验证结合使用的情况
  7377. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7378. },{"2":2}],26:[function(_dereq_,module,exports){
  7379. (function (global){
  7380. 'use strict';
  7381. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  7382. var UI = _dereq_(2);
  7383. var Validator = function(element, options) {
  7384. this.options = $.extend({}, Validator.DEFAULTS, options);
  7385. this.options.patterns = $.extend({}, Validator.patterns,
  7386. this.options.patterns);
  7387. var locales = this.options.locales;
  7388. !Validator.validationMessages[locales] && (this.options.locales = 'zh_CN');
  7389. this.$element = $(element);
  7390. this.init();
  7391. };
  7392. Validator.DEFAULTS = {
  7393. debug: false,
  7394. locales: 'zh_CN',
  7395. H5validation: false,
  7396. H5inputType: ['email', 'url', 'number'],
  7397. patterns: {},
  7398. patternClassPrefix: 'js-pattern-',
  7399. activeClass: 'am-active',
  7400. inValidClass: 'am-field-error',
  7401. validClass: 'am-field-valid',
  7402. validateOnSubmit: true,
  7403. // Elements to validate with allValid (only validating visible elements)
  7404. // :input: selects all input, textarea, select and button elements.
  7405. allFields: ':input:visible:not(:submit, :button, :disabled, .am-novalidate)',
  7406. // Custom events
  7407. customEvents: 'validate',
  7408. // Keyboard events
  7409. keyboardFields: ':input:not(:submit, :button, :disabled, .am-novalidate)',
  7410. keyboardEvents: 'focusout, change', // keyup, focusin
  7411. // bind `keyup` event to active field
  7412. activeKeyup: false,
  7413. textareaMaxlenthKeyup: true,
  7414. // Mouse events
  7415. pointerFields: 'input[type="range"]:not(:disabled, .am-novalidate), ' +
  7416. 'input[type="radio"]:not(:disabled, .am-novalidate), ' +
  7417. 'input[type="checkbox"]:not(:disabled, .am-novalidate), ' +
  7418. 'select:not(:disabled, .am-novalidate), ' +
  7419. 'option:not(:disabled, .am-novalidate)',
  7420. pointerEvents: 'click',
  7421. onValid: function(validity) {
  7422. },
  7423. onInValid: function(validity) {
  7424. },
  7425. markValid: function(validity) {
  7426. // this is Validator instance
  7427. var options = this.options;
  7428. var $field = $(validity.field);
  7429. var $parent = $field.closest('.am-form-group');
  7430. $field.addClass(options.validClass).removeClass(options.inValidClass);
  7431. $parent.addClass('am-form-success').removeClass('am-form-error');
  7432. options.onValid.call(this, validity);
  7433. },
  7434. markInValid: function(validity) {
  7435. var options = this.options;
  7436. var $field = $(validity.field);
  7437. var $parent = $field.closest('.am-form-group');
  7438. $field.addClass(options.inValidClass + ' ' + options.activeClass).
  7439. removeClass(options.validClass);
  7440. $parent.addClass('am-form-error').removeClass('am-form-success');
  7441. options.onInValid.call(this, validity);
  7442. },
  7443. validate: function(validity) {
  7444. // return validity;
  7445. },
  7446. submit: null
  7447. };
  7448. Validator.VERSION = '2.0.0';
  7449. /* jshint -W101 */
  7450. Validator.patterns = {
  7451. email: /^((([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-zA-Z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/,
  7452. url: /^(https?|ftp):\/\/(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/,
  7453. // Number, including positive, negative, and floating decimal
  7454. number: /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/,
  7455. dateISO: /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/,
  7456. integer: /^-?\d+$/
  7457. };
  7458. /* jshint +W101 */
  7459. Validator.validationMessages = {
  7460. zh_CN: {
  7461. valueMissing: '请填写(选择)此字段',
  7462. customError: {
  7463. tooShort: '至少填写 %s 个字符',
  7464. checkedOverflow: '至多选择 %s 项',
  7465. checkedUnderflow: '至少选择 %s 项'
  7466. },
  7467. patternMismatch: '请按照要求的格式填写',
  7468. rangeOverflow: '请填写小于等于 %s 的值',
  7469. rangeUnderflow: '请填写大于等于 %s 的值',
  7470. stepMismatch: '',
  7471. tooLong: '至多填写 %s 个字符',
  7472. typeMismatch: '请按照要求的类型填写'
  7473. }
  7474. };
  7475. Validator.ERROR_MAP = {
  7476. tooShort: 'minlength',
  7477. checkedOverflow: 'maxchecked',
  7478. checkedUnderflow: 'minchecked',
  7479. rangeOverflow: 'max',
  7480. rangeUnderflow: 'min',
  7481. tooLong: 'maxlength'
  7482. };
  7483. // TODO: 考虑表单元素不是 form 子元素的情形
  7484. // TODO: change/click/focusout 同时触发时处理重复
  7485. // TODO: 显示提示信息
  7486. Validator.prototype.init = function() {
  7487. var _this = this;
  7488. var $element = this.$element;
  7489. var options = this.options;
  7490. // using H5 form validation if option set and supported
  7491. if (options.H5validation && UI.support.formValidation) {
  7492. return false;
  7493. }
  7494. // disable HTML5 form validation
  7495. $element.attr('novalidate', 'novalidate');
  7496. function regexToPattern(regex) {
  7497. var pattern = regex.toString();
  7498. return pattern.substring(1, pattern.length - 1);
  7499. }
  7500. // add pattern to H5 input type
  7501. $.each(options.H5inputType, function(i, type) {
  7502. var $field = $element.find('input[type=' + type + ']');
  7503. if (!$field.attr('pattern') &&
  7504. !$field.is('[class*=' + options.patternClassPrefix + ']')) {
  7505. $field.attr('pattern', regexToPattern(options.patterns[type]));
  7506. }
  7507. });
  7508. // add pattern to .js-pattern-xx
  7509. $.each(options.patterns, function(key, value) {
  7510. var $field = $element.find('.' + options.patternClassPrefix + key);
  7511. !$field.attr('pattern') && $field.attr('pattern', regexToPattern(value));
  7512. });
  7513. $element.submit(function(e) {
  7514. // user custom submit handler
  7515. if (typeof options.submit === 'function') {
  7516. return options.submit.call(_this, e);
  7517. }
  7518. if (options.validateOnSubmit) {
  7519. var formValidity = _this.isFormValid();
  7520. // sync validate, return result
  7521. if ($.type(formValidity) === 'boolean') {
  7522. return formValidity;
  7523. }
  7524. if ($element.data('amui.checked')) {
  7525. return true;
  7526. } else {
  7527. $.when(formValidity).then(function() {
  7528. // done, submit form
  7529. $element.data('amui.checked', true).submit();
  7530. }, function() {
  7531. // fail
  7532. $element.data('amui.checked', false).
  7533. find('.' + options.inValidClass).eq(0).focus();
  7534. });
  7535. return false;
  7536. }
  7537. }
  7538. });
  7539. function bindEvents(fields, eventFlags, debounce) {
  7540. var events = eventFlags.split(',');
  7541. var validate = function(e) {
  7542. // console.log(e.type);
  7543. _this.validate(this);
  7544. };
  7545. if (debounce) {
  7546. validate = UI.utils.debounce(validate, debounce);
  7547. }
  7548. $.each(events, function(i, event) {
  7549. $element.on(event + '.validator.amui', fields, validate);
  7550. });
  7551. }
  7552. bindEvents(':input', options.customEvents);
  7553. bindEvents(options.keyboardFields, options.keyboardEvents);
  7554. bindEvents(options.pointerFields, options.pointerEvents);
  7555. if (options.textareaMaxlenthKeyup) {
  7556. bindEvents('textarea[maxlength]', 'keyup', 50);
  7557. }
  7558. if (options.activeKeyup) {
  7559. bindEvents('.am-active', 'keyup', 50);
  7560. }
  7561. /*if (options.errorMessage === 'tooltip') {
  7562. this.$tooltip = $('<div></div>', {
  7563. 'class': 'am-validator-message',
  7564. id: UI.utils.generateGUID('am-validator-message')
  7565. });
  7566. $(document.body).append(this.$tooltip);
  7567. }*/
  7568. };
  7569. Validator.prototype.isValid = function(field) {
  7570. var $field = $(field);
  7571. // valid field not has been validated
  7572. if ($field.data('validity') === undefined) {
  7573. this.validate(field);
  7574. }
  7575. return $field.data('validity') && $field.data('validity').valid;
  7576. };
  7577. Validator.prototype.validate = function(field) {
  7578. var _this = this;
  7579. var $element = this.$element;
  7580. var options = this.options;
  7581. var $field = $(field);
  7582. // Validate equal, e.g. confirm password
  7583. var equalTo = $field.data('equalTo');
  7584. if (equalTo) {
  7585. $field.attr('pattern', '^' + $element.find(equalTo).val() + '$');
  7586. }
  7587. var pattern = $field.attr('pattern') || false;
  7588. var re = new RegExp(pattern);
  7589. var $radioGroup = null;
  7590. var $checkboxGroup = null;
  7591. // if checkbox, return `:chcked` length
  7592. // NOTE: checkbox and radio should have name attribute
  7593. var value = ($field.is('[type=checkbox]')) ?
  7594. ($checkboxGroup = $element.find('input[name="' + field.name + '"]')).
  7595. filter(':checked').length : ($field.is('[type=radio]') ?
  7596. ($radioGroup = this.$element.find('input[name="' + field.name + '"]')).
  7597. filter(':checked').length > 0 : $field.val());
  7598. // if checkbox, valid the first input of checkbox group
  7599. $field = ($checkboxGroup && $checkboxGroup.length) ?
  7600. $checkboxGroup.first() : $field;
  7601. var required = ($field.attr('required') !== undefined) &&
  7602. ($field.attr('required') !== 'false');
  7603. var maxLength = parseInt($field.attr('maxlength'), 10);
  7604. var minLength = parseInt($field.attr('minlength'), 10);
  7605. var min = Number($field.attr('min'));
  7606. var max = Number($field.attr('max'));
  7607. var validity = this.createValidity({field: $field[0], valid: true});
  7608. // Debug
  7609. if (options.debug && window.console) {
  7610. console.log('Validate: value -> [' + value + ', regex -> [' + re +
  7611. '], required -> ' + required);
  7612. console.log('Regex test: ' + re.test(value) + ', Pattern: ' + pattern);
  7613. }
  7614. // check value length
  7615. if (!isNaN(maxLength) && value.length > maxLength) {
  7616. validity.valid = false;
  7617. validity.tooLong = true;
  7618. }
  7619. if (!isNaN(minLength) && value.length < minLength) {
  7620. validity.valid = false;
  7621. validity.customError = 'tooShort';
  7622. }
  7623. // check minimum and maximum
  7624. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input
  7625. // TODO: 日期验证最小值和最大值 min/max
  7626. if (!isNaN(min) && Number(value) < min) {
  7627. validity.valid = false;
  7628. validity.rangeUnderflow = true;
  7629. }
  7630. if (!isNaN(max) && Number(value) > max) {
  7631. validity.valid = false;
  7632. validity.rangeOverflow = true;
  7633. }
  7634. // check required
  7635. if (required && !value) {
  7636. validity.valid = false;
  7637. validity.valueMissing = true;
  7638. } else if (($checkboxGroup || $field.is('select[multiple="multiple"]')) &&
  7639. value) {
  7640. // check checkboxes / multiple select with `minchecked`/`maxchecked` attr
  7641. // var $multipleField = $checkboxGroup ? $checkboxGroup.first() : $field;
  7642. // if is select[multiple="multiple"], return selected length
  7643. value = $checkboxGroup ? value : value.length;
  7644. // at least checked
  7645. var minChecked = parseInt($field.attr('minchecked'), 10);
  7646. // at most checked
  7647. var maxChecked = parseInt($field.attr('maxchecked'), 10);
  7648. if (!isNaN(minChecked) && value < minChecked) {
  7649. // console.log('At least [%d] items checked!', maxChecked);
  7650. validity.valid = false;
  7651. validity.customError = 'checkedUnderflow';
  7652. }
  7653. if (!isNaN(maxChecked) && value > maxChecked) {
  7654. // console.log('At most [%d] items checked!', maxChecked);
  7655. validity.valid = false;
  7656. validity.customError = 'checkedOverflow';
  7657. }
  7658. } else if (pattern && !re.test(value) && value) { // check pattern
  7659. validity.valid = false;
  7660. validity.patternMismatch = true;
  7661. }
  7662. var validateComplete = function(validity) {
  7663. this.markField(validity);
  7664. $field.trigger('validated.field.validator.amui', validity).
  7665. data('validity', validity);
  7666. // validate the radios/checkboxes with the same name
  7667. var $fields = $radioGroup || $checkboxGroup;
  7668. if ($fields) {
  7669. $fields.not($field).data('validity', validity).each(function() {
  7670. validity.field = this;
  7671. _this.markField(validity);
  7672. });
  7673. }
  7674. };
  7675. // Run custom validate
  7676. // NOTE: async custom validate should return Deferred project
  7677. var customValidate;
  7678. (typeof options.validate === 'function') &&
  7679. (customValidate = options.validate.call(this, validity));
  7680. // Deferred
  7681. if (customValidate) {
  7682. var dfd = new $.Deferred();
  7683. $field.data('amui.dfdValidity', dfd.promise());
  7684. return $.when(customValidate).always(function(validity) {
  7685. dfd[validity.valid ? 'resolve' : 'reject'](validity);
  7686. validateComplete.call(_this, validity);
  7687. });
  7688. }
  7689. validateComplete.call(this, validity);
  7690. };
  7691. Validator.prototype.markField = function(validity) {
  7692. var options = this.options;
  7693. var flag = 'mark' + (validity.valid ? '' : 'In') + 'Valid';
  7694. options[flag] && options[flag].call(this, validity);
  7695. };
  7696. // check all fields in the form are valid
  7697. Validator.prototype.validateForm = function() {
  7698. var _this = this;
  7699. var $element = this.$element;
  7700. var options = this.options;
  7701. var $allFields = $element.find(options.allFields);
  7702. var radioNames = [];
  7703. var valid = true;
  7704. var formValidity = [];
  7705. var $inValidFields = $([]);
  7706. var promises = [];
  7707. // for async validate
  7708. var async = false;
  7709. $element.trigger('validate.form.validator.amui');
  7710. // Filter radio with the same name and keep only one,
  7711. // since they will be checked as a group by validate()
  7712. var $filteredFields = $allFields.filter(function(index) {
  7713. var name;
  7714. if (this.tagName === 'INPUT' && this.type === 'radio') {
  7715. name = this.name;
  7716. if (radioNames[name] === true) {
  7717. return false;
  7718. }
  7719. radioNames[name] = true;
  7720. }
  7721. return true;
  7722. });
  7723. $filteredFields.each(function() {
  7724. var $this = $(this);
  7725. var fieldValid = _this.isValid(this);
  7726. var fieldValidity = $this.data('validity');
  7727. valid = !!fieldValid && valid;
  7728. formValidity.push(fieldValidity);
  7729. if (!fieldValid) {
  7730. $inValidFields = $inValidFields.add($(this), $element);
  7731. }
  7732. // async validity
  7733. var promise = $this.data('amui.dfdValidity');
  7734. if (promise) {
  7735. promises.push(promise);
  7736. async = true;
  7737. } else {
  7738. // convert sync validity to Promise
  7739. var dfd = new $.Deferred();
  7740. promises.push(dfd.promise());
  7741. dfd[fieldValid ? 'resolve' : 'reject'](fieldValidity);
  7742. }
  7743. });
  7744. // NOTE: If there are async validity, the valid may be not exact result.
  7745. var validity = {
  7746. valid: valid,
  7747. $invalidFields: $inValidFields,
  7748. validity: formValidity,
  7749. promises: promises,
  7750. async: async
  7751. };
  7752. $element.trigger('validated.form.validator.amui', validity);
  7753. return validity;
  7754. };
  7755. Validator.prototype.isFormValid = function() {
  7756. var _this = this;
  7757. var formValidity = this.validateForm();
  7758. var triggerValid = function(type) {
  7759. _this.$element.trigger(type + '.validator.amui');
  7760. };
  7761. if (formValidity.async) {
  7762. var masterDfd = new $.Deferred();
  7763. $.when.apply(null, formValidity.promises).then(function() {
  7764. masterDfd.resolve();
  7765. triggerValid('valid');
  7766. }, function() {
  7767. masterDfd.reject();
  7768. triggerValid('invalid');
  7769. });
  7770. return masterDfd.promise();
  7771. } else {
  7772. if (!formValidity.valid) {
  7773. formValidity.$invalidFields.first().focus();
  7774. triggerValid('invalid');
  7775. return false;
  7776. }
  7777. triggerValid('valid');
  7778. return true;
  7779. }
  7780. };
  7781. // customErrors:
  7782. // 1. tooShort
  7783. // 2. checkedOverflow
  7784. // 3. checkedUnderflow
  7785. Validator.prototype.createValidity = function(validity) {
  7786. return $.extend({
  7787. customError: validity.customError || false,
  7788. patternMismatch: validity.patternMismatch || false,
  7789. rangeOverflow: validity.rangeOverflow || false, // higher than maximum
  7790. rangeUnderflow: validity.rangeUnderflow || false, // lower than minimum
  7791. stepMismatch: validity.stepMismatch || false,
  7792. tooLong: validity.tooLong || false,
  7793. // value is not in the correct syntax
  7794. typeMismatch: validity.typeMismatch || false,
  7795. valid: validity.valid || true,
  7796. // Returns true if the element has no value but is a required field
  7797. valueMissing: validity.valueMissing || false
  7798. }, validity);
  7799. };
  7800. Validator.prototype.getValidationMessage = function(validity) {
  7801. var messages = Validator.validationMessages[this.options.locales];
  7802. var error;
  7803. var message;
  7804. var placeholder = '%s';
  7805. var $field = $(validity.field);
  7806. if ($field.is('[type="checkbox"]') || $field.is('[type="radio"]')) {
  7807. $field = this.$element.find('[name=' + $field.attr('name') + ']').first();
  7808. }
  7809. // get error name
  7810. $.each(validity, function(key, val) {
  7811. // skip `field` and `valid`
  7812. if (key === 'field' || key === 'valid') {
  7813. return key;
  7814. }
  7815. // Amaze UI custom error type
  7816. if (key === 'customError' && val) {
  7817. error = val;
  7818. messages = messages.customError;
  7819. return false;
  7820. }
  7821. // W3C specs error type
  7822. if (val === true) {
  7823. error = key;
  7824. return false;
  7825. }
  7826. });
  7827. message = messages[error] || undefined;
  7828. if (message && Validator.ERROR_MAP[error]) {
  7829. message = message.replace(placeholder,
  7830. $field.attr(Validator.ERROR_MAP[error]) || '规定的');
  7831. }
  7832. return message;
  7833. };
  7834. function Plugin(option) {
  7835. return this.each(function() {
  7836. var $this = $(this);
  7837. var data = $this.data('amui.validator');
  7838. var options = $.extend({}, UI.utils.parseOptions($this.data('amValidator')),
  7839. typeof option === 'object' && option);
  7840. if (!data) {
  7841. $this.data('amui.validator', (data = new Validator(this, options)));
  7842. }
  7843. if (typeof option === 'string') {
  7844. data[option] && data[option]();
  7845. }
  7846. });
  7847. }
  7848. $.fn.validator = Plugin;
  7849. // init code
  7850. UI.ready(function(context) {
  7851. $('[data-am-validator]', context).validator();
  7852. });
  7853. $.AMUI.validator = Validator;
  7854. module.exports = Validator;
  7855. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7856. },{"2":2}],27:[function(_dereq_,module,exports){
  7857. (function (global){
  7858. 'use strict';
  7859. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  7860. _dereq_(2);
  7861. var cookie = {
  7862. get: function(name) {
  7863. var cookieName = encodeURIComponent(name) + '=';
  7864. var cookieStart = document.cookie.indexOf(cookieName);
  7865. var cookieValue = null;
  7866. var cookieEnd;
  7867. if (cookieStart > -1) {
  7868. cookieEnd = document.cookie.indexOf(';', cookieStart);
  7869. if (cookieEnd == -1) {
  7870. cookieEnd = document.cookie.length;
  7871. }
  7872. cookieValue = decodeURIComponent(document.cookie.substring(cookieStart +
  7873. cookieName.length, cookieEnd));
  7874. }
  7875. return cookieValue;
  7876. },
  7877. set: function(name, value, expires, path, domain, secure) {
  7878. var cookieText = encodeURIComponent(name) + '=' +
  7879. encodeURIComponent(value);
  7880. if (expires instanceof Date) {
  7881. cookieText += '; expires=' + expires.toUTCString();
  7882. }
  7883. if (path) {
  7884. cookieText += '; path=' + path;
  7885. }
  7886. if (domain) {
  7887. cookieText += '; domain=' + domain;
  7888. }
  7889. if (secure) {
  7890. cookieText += '; secure';
  7891. }
  7892. document.cookie = cookieText;
  7893. },
  7894. unset: function(name, path, domain, secure) {
  7895. this.set(name, '', new Date(0), path, domain, secure);
  7896. }
  7897. };
  7898. $.AMUI.utils.cookie = cookie;
  7899. module.exports = cookie;
  7900. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  7901. },{"2":2}],28:[function(_dereq_,module,exports){
  7902. (function (global){
  7903. 'use strict';
  7904. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  7905. var UI = _dereq_(2);
  7906. /**
  7907. * @via https://github.com/sindresorhus/screenfull.js
  7908. * @license MIT © Sindre Sorhus
  7909. * @version 2.0.0
  7910. */
  7911. var keyboardAllowed = typeof Element !== 'undefined' &&
  7912. 'ALLOW_KEYBOARD_INPUT' in Element;
  7913. var fn = (function () {
  7914. var val;
  7915. var valLength;
  7916. var fnMap = [
  7917. [
  7918. 'requestFullscreen',
  7919. 'exitFullscreen',
  7920. 'fullscreenElement',
  7921. 'fullscreenEnabled',
  7922. 'fullscreenchange',
  7923. 'fullscreenerror'
  7924. ],
  7925. // new WebKit
  7926. [
  7927. 'webkitRequestFullscreen',
  7928. 'webkitExitFullscreen',
  7929. 'webkitFullscreenElement',
  7930. 'webkitFullscreenEnabled',
  7931. 'webkitfullscreenchange',
  7932. 'webkitfullscreenerror'
  7933. ],
  7934. // old WebKit (Safari 5.1)
  7935. [
  7936. 'webkitRequestFullScreen',
  7937. 'webkitCancelFullScreen',
  7938. 'webkitCurrentFullScreenElement',
  7939. 'webkitCancelFullScreen',
  7940. 'webkitfullscreenchange',
  7941. 'webkitfullscreenerror'
  7942. ],
  7943. [
  7944. 'mozRequestFullScreen',
  7945. 'mozCancelFullScreen',
  7946. 'mozFullScreenElement',
  7947. 'mozFullScreenEnabled',
  7948. 'mozfullscreenchange',
  7949. 'mozfullscreenerror'
  7950. ],
  7951. [
  7952. 'msRequestFullscreen',
  7953. 'msExitFullscreen',
  7954. 'msFullscreenElement',
  7955. 'msFullscreenEnabled',
  7956. 'MSFullscreenChange',
  7957. 'MSFullscreenError'
  7958. ]
  7959. ];
  7960. var i = 0;
  7961. var l = fnMap.length;
  7962. var ret = {};
  7963. for (; i < l; i++) {
  7964. val = fnMap[i];
  7965. if (val && val[1] in document) {
  7966. for (i = 0, valLength = val.length; i < valLength; i++) {
  7967. ret[fnMap[0][i]] = val[i];
  7968. }
  7969. return ret;
  7970. }
  7971. }
  7972. return false;
  7973. })();
  7974. var screenfull = {
  7975. request: function (elem) {
  7976. var request = fn.requestFullscreen;
  7977. elem = elem || document.documentElement;
  7978. // Work around Safari 5.1 bug: reports support for
  7979. // keyboard in fullscreen even though it doesn't.
  7980. // Browser sniffing, since the alternative with
  7981. // setTimeout is even worse.
  7982. if (/5\.1[\.\d]* Safari/.test(navigator.userAgent)) {
  7983. elem[request]();
  7984. } else {
  7985. elem[request](keyboardAllowed && Element.ALLOW_KEYBOARD_INPUT);
  7986. }
  7987. },
  7988. exit: function () {
  7989. document[fn.exitFullscreen]();
  7990. },
  7991. toggle: function (elem) {
  7992. if (this.isFullscreen) {
  7993. this.exit();
  7994. } else {
  7995. this.request(elem);
  7996. }
  7997. },
  7998. raw: fn
  7999. };
  8000. if (!fn) {
  8001. module.exports = false;
  8002. return;
  8003. }
  8004. Object.defineProperties(screenfull, {
  8005. isFullscreen: {
  8006. get: function () {
  8007. return !!document[fn.fullscreenElement];
  8008. }
  8009. },
  8010. element: {
  8011. enumerable: true,
  8012. get: function () {
  8013. return document[fn.fullscreenElement];
  8014. }
  8015. },
  8016. enabled: {
  8017. enumerable: true,
  8018. get: function () {
  8019. // Coerce to boolean in case of old WebKit
  8020. return !!document[fn.fullscreenEnabled];
  8021. }
  8022. }
  8023. });
  8024. screenfull.VERSION = '2.0.0';
  8025. $.AMUI.fullscreen = screenfull;
  8026. module.exports = screenfull;
  8027. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  8028. },{"2":2}],29:[function(_dereq_,module,exports){
  8029. (function (global){
  8030. 'use strict';
  8031. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  8032. var UI = _dereq_(2);
  8033. UI.support.geolocation = window.navigator && window.navigator.geolocation;
  8034. var geo = UI.support.geolocation;
  8035. var Geolocation = function(options) {
  8036. this.options = options || {};
  8037. };
  8038. Geolocation.MESSAGES = {
  8039. unsupportedBrowser: 'Browser does not support location services',
  8040. permissionDenied: 'You have rejected access to your location',
  8041. positionUnavailable: 'Unable to determine your location',
  8042. timeout: 'Service timeout has been reached'
  8043. };
  8044. Geolocation.ERROR_CODE = {
  8045. 0: 'unsupportedBrowser',
  8046. 1: 'permissionDenied',
  8047. 2: 'positionUnavailable',
  8048. 3: 'timeout'
  8049. };
  8050. Geolocation.prototype.get = function(options) {
  8051. var _this = this;
  8052. options = $.extend({}, this.options, options);
  8053. var deferred = new $.Deferred();
  8054. if (geo) {
  8055. this.watchID = geo.getCurrentPosition(function(position) {
  8056. deferred.resolve.call(_this, position);
  8057. }, function(error) {
  8058. deferred.reject(Geolocation.MESSAGES[Geolocation.ERROR_CODE[error.code]]);
  8059. }, options);
  8060. } else {
  8061. deferred.reject(Geolocation.MESSAGES.unsupportedBrowser);
  8062. }
  8063. return deferred.promise();
  8064. };
  8065. Geolocation.prototype.watch = function(options) {
  8066. if (!geo) {
  8067. return;
  8068. }
  8069. options = $.extend({}, this.options, options);
  8070. if (!$.isFunction(options.done)) {
  8071. return;
  8072. }
  8073. this.clearWatch();
  8074. var fail = $.isFunction(options.fail) ? options.fail : null;
  8075. this.watchID = geo.watchPosition(options.done, fail, options);
  8076. return this.watchID;
  8077. };
  8078. Geolocation.prototype.clearWatch = function() {
  8079. if (!geo || !this.watchID) {
  8080. return;
  8081. }
  8082. geo.clearWatch(this.watchID);
  8083. this.watchID = null;
  8084. };
  8085. $.AMUI.Geolocation = Geolocation;
  8086. module.exports = Geolocation;
  8087. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  8088. },{"2":2}],30:[function(_dereq_,module,exports){
  8089. (function (global){
  8090. /*! Hammer.JS - v2.0.4 - 2014-09-28
  8091. * http://hammerjs.github.io/
  8092. *
  8093. * Copyright (c) 2014 Jorik Tangelder;
  8094. * Licensed under the MIT license */
  8095. 'use strict';
  8096. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  8097. var UI = _dereq_(2);
  8098. var VENDOR_PREFIXES = ['', 'webkit', 'moz', 'MS', 'ms', 'o'];
  8099. var TEST_ELEMENT = document.createElement('div');
  8100. var TYPE_FUNCTION = 'function';
  8101. var round = Math.round;
  8102. var abs = Math.abs;
  8103. var now = Date.now;
  8104. /**
  8105. * set a timeout with a given scope
  8106. * @param {Function} fn
  8107. * @param {Number} timeout
  8108. * @param {Object} context
  8109. * @returns {number}
  8110. */
  8111. function setTimeoutContext(fn, timeout, context) {
  8112. return setTimeout(bindFn(fn, context), timeout);
  8113. }
  8114. /**
  8115. * if the argument is an array, we want to execute the fn on each entry
  8116. * if it aint an array we don't want to do a thing.
  8117. * this is used by all the methods that accept a single and array argument.
  8118. * @param {*|Array} arg
  8119. * @param {String} fn
  8120. * @param {Object} [context]
  8121. * @returns {Boolean}
  8122. */
  8123. function invokeArrayArg(arg, fn, context) {
  8124. if (Array.isArray(arg)) {
  8125. each(arg, context[fn], context);
  8126. return true;
  8127. }
  8128. return false;
  8129. }
  8130. /**
  8131. * walk objects and arrays
  8132. * @param {Object} obj
  8133. * @param {Function} iterator
  8134. * @param {Object} context
  8135. */
  8136. function each(obj, iterator, context) {
  8137. var i;
  8138. if (!obj) {
  8139. return;
  8140. }
  8141. if (obj.forEach) {
  8142. obj.forEach(iterator, context);
  8143. } else if (obj.length !== undefined) {
  8144. i = 0;
  8145. while (i < obj.length) {
  8146. iterator.call(context, obj[i], i, obj);
  8147. i++;
  8148. }
  8149. } else {
  8150. for (i in obj) {
  8151. obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
  8152. }
  8153. }
  8154. }
  8155. /**
  8156. * extend object.
  8157. * means that properties in dest will be overwritten by the ones in src.
  8158. * @param {Object} dest
  8159. * @param {Object} src
  8160. * @param {Boolean} [merge]
  8161. * @returns {Object} dest
  8162. */
  8163. function extend(dest, src, merge) {
  8164. var keys = Object.keys(src);
  8165. var i = 0;
  8166. while (i < keys.length) {
  8167. if (!merge || (merge && dest[keys[i]] === undefined)) {
  8168. dest[keys[i]] = src[keys[i]];
  8169. }
  8170. i++;
  8171. }
  8172. return dest;
  8173. }
  8174. /**
  8175. * merge the values from src in the dest.
  8176. * means that properties that exist in dest will not be overwritten by src
  8177. * @param {Object} dest
  8178. * @param {Object} src
  8179. * @returns {Object} dest
  8180. */
  8181. function merge(dest, src) {
  8182. return extend(dest, src, true);
  8183. }
  8184. /**
  8185. * simple class inheritance
  8186. * @param {Function} child
  8187. * @param {Function} base
  8188. * @param {Object} [properties]
  8189. */
  8190. function inherit(child, base, properties) {
  8191. var baseP = base.prototype,
  8192. childP;
  8193. childP = child.prototype = Object.create(baseP);
  8194. childP.constructor = child;
  8195. childP._super = baseP;
  8196. if (properties) {
  8197. extend(childP, properties);
  8198. }
  8199. }
  8200. /**
  8201. * simple function bind
  8202. * @param {Function} fn
  8203. * @param {Object} context
  8204. * @returns {Function}
  8205. */
  8206. function bindFn(fn, context) {
  8207. return function boundFn() {
  8208. return fn.apply(context, arguments);
  8209. };
  8210. }
  8211. /**
  8212. * let a boolean value also be a function that must return a boolean
  8213. * this first item in args will be used as the context
  8214. * @param {Boolean|Function} val
  8215. * @param {Array} [args]
  8216. * @returns {Boolean}
  8217. */
  8218. function boolOrFn(val, args) {
  8219. if (typeof val == TYPE_FUNCTION) {
  8220. return val.apply(args ? args[0] || undefined : undefined, args);
  8221. }
  8222. return val;
  8223. }
  8224. /**
  8225. * use the val2 when val1 is undefined
  8226. * @param {*} val1
  8227. * @param {*} val2
  8228. * @returns {*}
  8229. */
  8230. function ifUndefined(val1, val2) {
  8231. return (val1 === undefined) ? val2 : val1;
  8232. }
  8233. /**
  8234. * addEventListener with multiple events at once
  8235. * @param {EventTarget} target
  8236. * @param {String} types
  8237. * @param {Function} handler
  8238. */
  8239. function addEventListeners(target, types, handler) {
  8240. each(splitStr(types), function(type) {
  8241. target.addEventListener(type, handler, false);
  8242. });
  8243. }
  8244. /**
  8245. * removeEventListener with multiple events at once
  8246. * @param {EventTarget} target
  8247. * @param {String} types
  8248. * @param {Function} handler
  8249. */
  8250. function removeEventListeners(target, types, handler) {
  8251. each(splitStr(types), function(type) {
  8252. target.removeEventListener(type, handler, false);
  8253. });
  8254. }
  8255. /**
  8256. * find if a node is in the given parent
  8257. * @method hasParent
  8258. * @param {HTMLElement} node
  8259. * @param {HTMLElement} parent
  8260. * @return {Boolean} found
  8261. */
  8262. function hasParent(node, parent) {
  8263. while (node) {
  8264. if (node == parent) {
  8265. return true;
  8266. }
  8267. node = node.parentNode;
  8268. }
  8269. return false;
  8270. }
  8271. /**
  8272. * small indexOf wrapper
  8273. * @param {String} str
  8274. * @param {String} find
  8275. * @returns {Boolean} found
  8276. */
  8277. function inStr(str, find) {
  8278. return str.indexOf(find) > -1;
  8279. }
  8280. /**
  8281. * split string on whitespace
  8282. * @param {String} str
  8283. * @returns {Array} words
  8284. */
  8285. function splitStr(str) {
  8286. return str.trim().split(/\s+/g);
  8287. }
  8288. /**
  8289. * find if a array contains the object using indexOf or a simple polyFill
  8290. * @param {Array} src
  8291. * @param {String} find
  8292. * @param {String} [findByKey]
  8293. * @return {Boolean|Number} false when not found, or the index
  8294. */
  8295. function inArray(src, find, findByKey) {
  8296. if (src.indexOf && !findByKey) {
  8297. return src.indexOf(find);
  8298. } else {
  8299. var i = 0;
  8300. while (i < src.length) {
  8301. if ((findByKey && src[i][findByKey] == find) || (!findByKey && src[i] === find)) {
  8302. return i;
  8303. }
  8304. i++;
  8305. }
  8306. return -1;
  8307. }
  8308. }
  8309. /**
  8310. * convert array-like objects to real arrays
  8311. * @param {Object} obj
  8312. * @returns {Array}
  8313. */
  8314. function toArray(obj) {
  8315. return Array.prototype.slice.call(obj, 0);
  8316. }
  8317. /**
  8318. * unique array with objects based on a key (like 'id') or just by the array's value
  8319. * @param {Array} src [{id:1},{id:2},{id:1}]
  8320. * @param {String} [key]
  8321. * @param {Boolean} [sort=False]
  8322. * @returns {Array} [{id:1},{id:2}]
  8323. */
  8324. function uniqueArray(src, key, sort) {
  8325. var results = [];
  8326. var values = [];
  8327. var i = 0;
  8328. while (i < src.length) {
  8329. var val = key ? src[i][key] : src[i];
  8330. if (inArray(values, val) < 0) {
  8331. results.push(src[i]);
  8332. }
  8333. values[i] = val;
  8334. i++;
  8335. }
  8336. if (sort) {
  8337. if (!key) {
  8338. results = results.sort();
  8339. } else {
  8340. results = results.sort(function sortUniqueArray(a, b) {
  8341. return a[key] > b[key];
  8342. });
  8343. }
  8344. }
  8345. return results;
  8346. }
  8347. /**
  8348. * get the prefixed property
  8349. * @param {Object} obj
  8350. * @param {String} property
  8351. * @returns {String|Undefined} prefixed
  8352. */
  8353. function prefixed(obj, property) {
  8354. var prefix, prop;
  8355. var camelProp = property[0].toUpperCase() + property.slice(1);
  8356. var i = 0;
  8357. while (i < VENDOR_PREFIXES.length) {
  8358. prefix = VENDOR_PREFIXES[i];
  8359. prop = (prefix) ? prefix + camelProp : property;
  8360. if (prop in obj) {
  8361. return prop;
  8362. }
  8363. i++;
  8364. }
  8365. return undefined;
  8366. }
  8367. /**
  8368. * get a unique id
  8369. * @returns {number} uniqueId
  8370. */
  8371. var _uniqueId = 1;
  8372. function uniqueId() {
  8373. return _uniqueId++;
  8374. }
  8375. /**
  8376. * get the window object of an element
  8377. * @param {HTMLElement} element
  8378. * @returns {DocumentView|Window}
  8379. */
  8380. function getWindowForElement(element) {
  8381. var doc = element.ownerDocument;
  8382. return (doc.defaultView || doc.parentWindow);
  8383. }
  8384. var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
  8385. var SUPPORT_TOUCH = ('ontouchstart' in window);
  8386. var SUPPORT_POINTER_EVENTS = prefixed(window, 'PointerEvent') !== undefined;
  8387. var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
  8388. var INPUT_TYPE_TOUCH = 'touch';
  8389. var INPUT_TYPE_PEN = 'pen';
  8390. var INPUT_TYPE_MOUSE = 'mouse';
  8391. var INPUT_TYPE_KINECT = 'kinect';
  8392. var COMPUTE_INTERVAL = 25;
  8393. var INPUT_START = 1;
  8394. var INPUT_MOVE = 2;
  8395. var INPUT_END = 4;
  8396. var INPUT_CANCEL = 8;
  8397. var DIRECTION_NONE = 1;
  8398. var DIRECTION_LEFT = 2;
  8399. var DIRECTION_RIGHT = 4;
  8400. var DIRECTION_UP = 8;
  8401. var DIRECTION_DOWN = 16;
  8402. var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
  8403. var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
  8404. var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
  8405. var PROPS_XY = ['x', 'y'];
  8406. var PROPS_CLIENT_XY = ['clientX', 'clientY'];
  8407. /**
  8408. * create new input type manager
  8409. * @param {Manager} manager
  8410. * @param {Function} callback
  8411. * @returns {Input}
  8412. * @constructor
  8413. */
  8414. function Input(manager, callback) {
  8415. var self = this;
  8416. this.manager = manager;
  8417. this.callback = callback;
  8418. this.element = manager.element;
  8419. this.target = manager.options.inputTarget;
  8420. // smaller wrapper around the handler, for the scope and the enabled state of the manager,
  8421. // so when disabled the input events are completely bypassed.
  8422. this.domHandler = function(ev) {
  8423. if (boolOrFn(manager.options.enable, [manager])) {
  8424. self.handler(ev);
  8425. }
  8426. };
  8427. this.init();
  8428. }
  8429. Input.prototype = {
  8430. /**
  8431. * should handle the inputEvent data and trigger the callback
  8432. * @virtual
  8433. */
  8434. handler: function() {
  8435. },
  8436. /**
  8437. * bind the events
  8438. */
  8439. init: function() {
  8440. this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
  8441. this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
  8442. this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
  8443. },
  8444. /**
  8445. * unbind the events
  8446. */
  8447. destroy: function() {
  8448. this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
  8449. this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
  8450. this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
  8451. }
  8452. };
  8453. /**
  8454. * create new input type manager
  8455. * called by the Manager constructor
  8456. * @param {Hammer} manager
  8457. * @returns {Input}
  8458. */
  8459. function createInputInstance(manager) {
  8460. var Type;
  8461. var inputClass = manager.options.inputClass;
  8462. if (inputClass) {
  8463. Type = inputClass;
  8464. } else if (SUPPORT_POINTER_EVENTS) {
  8465. Type = PointerEventInput;
  8466. } else if (SUPPORT_ONLY_TOUCH) {
  8467. Type = TouchInput;
  8468. } else if (!SUPPORT_TOUCH) {
  8469. Type = MouseInput;
  8470. } else {
  8471. Type = TouchMouseInput;
  8472. }
  8473. return new (Type)(manager, inputHandler);
  8474. }
  8475. /**
  8476. * handle input events
  8477. * @param {Manager} manager
  8478. * @param {String} eventType
  8479. * @param {Object} input
  8480. */
  8481. function inputHandler(manager, eventType, input) {
  8482. var pointersLen = input.pointers.length;
  8483. var changedPointersLen = input.changedPointers.length;
  8484. var isFirst = (eventType & INPUT_START && (pointersLen - changedPointersLen === 0));
  8485. var isFinal = (eventType & (INPUT_END | INPUT_CANCEL) && (pointersLen - changedPointersLen === 0));
  8486. input.isFirst = !!isFirst;
  8487. input.isFinal = !!isFinal;
  8488. if (isFirst) {
  8489. manager.session = {};
  8490. }
  8491. // source event is the normalized value of the domEvents
  8492. // like 'touchstart, mouseup, pointerdown'
  8493. input.eventType = eventType;
  8494. // compute scale, rotation etc
  8495. computeInputData(manager, input);
  8496. // emit secret event
  8497. manager.emit('hammer.input', input);
  8498. manager.recognize(input);
  8499. manager.session.prevInput = input;
  8500. }
  8501. /**
  8502. * extend the data with some usable properties like scale, rotate, velocity etc
  8503. * @param {Object} manager
  8504. * @param {Object} input
  8505. */
  8506. function computeInputData(manager, input) {
  8507. var session = manager.session;
  8508. var pointers = input.pointers;
  8509. var pointersLength = pointers.length;
  8510. // store the first input to calculate the distance and direction
  8511. if (!session.firstInput) {
  8512. session.firstInput = simpleCloneInputData(input);
  8513. }
  8514. // to compute scale and rotation we need to store the multiple touches
  8515. if (pointersLength > 1 && !session.firstMultiple) {
  8516. session.firstMultiple = simpleCloneInputData(input);
  8517. } else if (pointersLength === 1) {
  8518. session.firstMultiple = false;
  8519. }
  8520. var firstInput = session.firstInput;
  8521. var firstMultiple = session.firstMultiple;
  8522. var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
  8523. var center = input.center = getCenter(pointers);
  8524. input.timeStamp = now();
  8525. input.deltaTime = input.timeStamp - firstInput.timeStamp;
  8526. input.angle = getAngle(offsetCenter, center);
  8527. input.distance = getDistance(offsetCenter, center);
  8528. computeDeltaXY(session, input);
  8529. input.offsetDirection = getDirection(input.deltaX, input.deltaY);
  8530. input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
  8531. input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
  8532. computeIntervalInputData(session, input);
  8533. // find the correct target
  8534. var target = manager.element;
  8535. if (hasParent(input.srcEvent.target, target)) {
  8536. target = input.srcEvent.target;
  8537. }
  8538. input.target = target;
  8539. }
  8540. function computeDeltaXY(session, input) {
  8541. var center = input.center;
  8542. var offset = session.offsetDelta || {};
  8543. var prevDelta = session.prevDelta || {};
  8544. var prevInput = session.prevInput || {};
  8545. if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
  8546. prevDelta = session.prevDelta = {
  8547. x: prevInput.deltaX || 0,
  8548. y: prevInput.deltaY || 0
  8549. };
  8550. offset = session.offsetDelta = {
  8551. x: center.x,
  8552. y: center.y
  8553. };
  8554. }
  8555. input.deltaX = prevDelta.x + (center.x - offset.x);
  8556. input.deltaY = prevDelta.y + (center.y - offset.y);
  8557. }
  8558. /**
  8559. * velocity is calculated every x ms
  8560. * @param {Object} session
  8561. * @param {Object} input
  8562. */
  8563. function computeIntervalInputData(session, input) {
  8564. var last = session.lastInterval || input,
  8565. deltaTime = input.timeStamp - last.timeStamp,
  8566. velocity, velocityX, velocityY, direction;
  8567. if (input.eventType != INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
  8568. var deltaX = last.deltaX - input.deltaX;
  8569. var deltaY = last.deltaY - input.deltaY;
  8570. var v = getVelocity(deltaTime, deltaX, deltaY);
  8571. velocityX = v.x;
  8572. velocityY = v.y;
  8573. velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y;
  8574. direction = getDirection(deltaX, deltaY);
  8575. session.lastInterval = input;
  8576. } else {
  8577. // use latest velocity info if it doesn't overtake a minimum period
  8578. velocity = last.velocity;
  8579. velocityX = last.velocityX;
  8580. velocityY = last.velocityY;
  8581. direction = last.direction;
  8582. }
  8583. input.velocity = velocity;
  8584. input.velocityX = velocityX;
  8585. input.velocityY = velocityY;
  8586. input.direction = direction;
  8587. }
  8588. /**
  8589. * create a simple clone from the input used for storage of firstInput and firstMultiple
  8590. * @param {Object} input
  8591. * @returns {Object} clonedInputData
  8592. */
  8593. function simpleCloneInputData(input) {
  8594. // make a simple copy of the pointers because we will get a reference if we don't
  8595. // we only need clientXY for the calculations
  8596. var pointers = [];
  8597. var i = 0;
  8598. while (i < input.pointers.length) {
  8599. pointers[i] = {
  8600. clientX: round(input.pointers[i].clientX),
  8601. clientY: round(input.pointers[i].clientY)
  8602. };
  8603. i++;
  8604. }
  8605. return {
  8606. timeStamp: now(),
  8607. pointers: pointers,
  8608. center: getCenter(pointers),
  8609. deltaX: input.deltaX,
  8610. deltaY: input.deltaY
  8611. };
  8612. }
  8613. /**
  8614. * get the center of all the pointers
  8615. * @param {Array} pointers
  8616. * @return {Object} center contains `x` and `y` properties
  8617. */
  8618. function getCenter(pointers) {
  8619. var pointersLength = pointers.length;
  8620. // no need to loop when only one touch
  8621. if (pointersLength === 1) {
  8622. return {
  8623. x: round(pointers[0].clientX),
  8624. y: round(pointers[0].clientY)
  8625. };
  8626. }
  8627. var x = 0, y = 0, i = 0;
  8628. while (i < pointersLength) {
  8629. x += pointers[i].clientX;
  8630. y += pointers[i].clientY;
  8631. i++;
  8632. }
  8633. return {
  8634. x: round(x / pointersLength),
  8635. y: round(y / pointersLength)
  8636. };
  8637. }
  8638. /**
  8639. * calculate the velocity between two points. unit is in px per ms.
  8640. * @param {Number} deltaTime
  8641. * @param {Number} x
  8642. * @param {Number} y
  8643. * @return {Object} velocity `x` and `y`
  8644. */
  8645. function getVelocity(deltaTime, x, y) {
  8646. return {
  8647. x: x / deltaTime || 0,
  8648. y: y / deltaTime || 0
  8649. };
  8650. }
  8651. /**
  8652. * get the direction between two points
  8653. * @param {Number} x
  8654. * @param {Number} y
  8655. * @return {Number} direction
  8656. */
  8657. function getDirection(x, y) {
  8658. if (x === y) {
  8659. return DIRECTION_NONE;
  8660. }
  8661. if (abs(x) >= abs(y)) {
  8662. return x > 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
  8663. }
  8664. return y > 0 ? DIRECTION_UP : DIRECTION_DOWN;
  8665. }
  8666. /**
  8667. * calculate the absolute distance between two points
  8668. * @param {Object} p1 {x, y}
  8669. * @param {Object} p2 {x, y}
  8670. * @param {Array} [props] containing x and y keys
  8671. * @return {Number} distance
  8672. */
  8673. function getDistance(p1, p2, props) {
  8674. if (!props) {
  8675. props = PROPS_XY;
  8676. }
  8677. var x = p2[props[0]] - p1[props[0]],
  8678. y = p2[props[1]] - p1[props[1]];
  8679. return Math.sqrt((x * x) + (y * y));
  8680. }
  8681. /**
  8682. * calculate the angle between two coordinates
  8683. * @param {Object} p1
  8684. * @param {Object} p2
  8685. * @param {Array} [props] containing x and y keys
  8686. * @return {Number} angle
  8687. */
  8688. function getAngle(p1, p2, props) {
  8689. if (!props) {
  8690. props = PROPS_XY;
  8691. }
  8692. var x = p2[props[0]] - p1[props[0]],
  8693. y = p2[props[1]] - p1[props[1]];
  8694. return Math.atan2(y, x) * 180 / Math.PI;
  8695. }
  8696. /**
  8697. * calculate the rotation degrees between two pointersets
  8698. * @param {Array} start array of pointers
  8699. * @param {Array} end array of pointers
  8700. * @return {Number} rotation
  8701. */
  8702. function getRotation(start, end) {
  8703. return getAngle(end[1], end[0], PROPS_CLIENT_XY) - getAngle(start[1], start[0], PROPS_CLIENT_XY);
  8704. }
  8705. /**
  8706. * calculate the scale factor between two pointersets
  8707. * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
  8708. * @param {Array} start array of pointers
  8709. * @param {Array} end array of pointers
  8710. * @return {Number} scale
  8711. */
  8712. function getScale(start, end) {
  8713. return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
  8714. }
  8715. var MOUSE_INPUT_MAP = {
  8716. mousedown: INPUT_START,
  8717. mousemove: INPUT_MOVE,
  8718. mouseup: INPUT_END
  8719. };
  8720. var MOUSE_ELEMENT_EVENTS = 'mousedown';
  8721. var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
  8722. /**
  8723. * Mouse events input
  8724. * @constructor
  8725. * @extends Input
  8726. */
  8727. function MouseInput() {
  8728. this.evEl = MOUSE_ELEMENT_EVENTS;
  8729. this.evWin = MOUSE_WINDOW_EVENTS;
  8730. this.allow = true; // used by Input.TouchMouse to disable mouse events
  8731. this.pressed = false; // mousedown state
  8732. Input.apply(this, arguments);
  8733. }
  8734. inherit(MouseInput, Input, {
  8735. /**
  8736. * handle mouse events
  8737. * @param {Object} ev
  8738. */
  8739. handler: function MEhandler(ev) {
  8740. var eventType = MOUSE_INPUT_MAP[ev.type];
  8741. // on start we want to have the left mouse button down
  8742. if (eventType & INPUT_START && ev.button === 0) {
  8743. this.pressed = true;
  8744. }
  8745. if (eventType & INPUT_MOVE && ev.which !== 1) {
  8746. eventType = INPUT_END;
  8747. }
  8748. // mouse must be down, and mouse events are allowed (see the TouchMouse input)
  8749. if (!this.pressed || !this.allow) {
  8750. return;
  8751. }
  8752. if (eventType & INPUT_END) {
  8753. this.pressed = false;
  8754. }
  8755. this.callback(this.manager, eventType, {
  8756. pointers: [ev],
  8757. changedPointers: [ev],
  8758. pointerType: INPUT_TYPE_MOUSE,
  8759. srcEvent: ev
  8760. });
  8761. }
  8762. });
  8763. var POINTER_INPUT_MAP = {
  8764. pointerdown: INPUT_START,
  8765. pointermove: INPUT_MOVE,
  8766. pointerup: INPUT_END,
  8767. pointercancel: INPUT_CANCEL,
  8768. pointerout: INPUT_CANCEL
  8769. };
  8770. // in IE10 the pointer types is defined as an enum
  8771. var IE10_POINTER_TYPE_ENUM = {
  8772. 2: INPUT_TYPE_TOUCH,
  8773. 3: INPUT_TYPE_PEN,
  8774. 4: INPUT_TYPE_MOUSE,
  8775. 5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816
  8776. };
  8777. var POINTER_ELEMENT_EVENTS = 'pointerdown';
  8778. var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
  8779. // IE10 has prefixed support, and case-sensitive
  8780. if (window.MSPointerEvent) {
  8781. POINTER_ELEMENT_EVENTS = 'MSPointerDown';
  8782. POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
  8783. }
  8784. /**
  8785. * Pointer events input
  8786. * @constructor
  8787. * @extends Input
  8788. */
  8789. function PointerEventInput() {
  8790. this.evEl = POINTER_ELEMENT_EVENTS;
  8791. this.evWin = POINTER_WINDOW_EVENTS;
  8792. Input.apply(this, arguments);
  8793. this.store = (this.manager.session.pointerEvents = []);
  8794. }
  8795. inherit(PointerEventInput, Input, {
  8796. /**
  8797. * handle mouse events
  8798. * @param {Object} ev
  8799. */
  8800. handler: function PEhandler(ev) {
  8801. var store = this.store;
  8802. var removePointer = false;
  8803. var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
  8804. var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
  8805. var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
  8806. var isTouch = (pointerType == INPUT_TYPE_TOUCH);
  8807. // get index of the event in the store
  8808. var storeIndex = inArray(store, ev.pointerId, 'pointerId');
  8809. // start and mouse must be down
  8810. if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
  8811. if (storeIndex < 0) {
  8812. store.push(ev);
  8813. storeIndex = store.length - 1;
  8814. }
  8815. } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
  8816. removePointer = true;
  8817. }
  8818. // it not found, so the pointer hasn't been down (so it's probably a hover)
  8819. if (storeIndex < 0) {
  8820. return;
  8821. }
  8822. // update the event in the store
  8823. store[storeIndex] = ev;
  8824. this.callback(this.manager, eventType, {
  8825. pointers: store,
  8826. changedPointers: [ev],
  8827. pointerType: pointerType,
  8828. srcEvent: ev
  8829. });
  8830. if (removePointer) {
  8831. // remove from the store
  8832. store.splice(storeIndex, 1);
  8833. }
  8834. }
  8835. });
  8836. var SINGLE_TOUCH_INPUT_MAP = {
  8837. touchstart: INPUT_START,
  8838. touchmove: INPUT_MOVE,
  8839. touchend: INPUT_END,
  8840. touchcancel: INPUT_CANCEL
  8841. };
  8842. var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
  8843. var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
  8844. /**
  8845. * Touch events input
  8846. * @constructor
  8847. * @extends Input
  8848. */
  8849. function SingleTouchInput() {
  8850. this.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
  8851. this.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
  8852. this.started = false;
  8853. Input.apply(this, arguments);
  8854. }
  8855. inherit(SingleTouchInput, Input, {
  8856. handler: function TEhandler(ev) {
  8857. var type = SINGLE_TOUCH_INPUT_MAP[ev.type];
  8858. // should we handle the touch events?
  8859. if (type === INPUT_START) {
  8860. this.started = true;
  8861. }
  8862. if (!this.started) {
  8863. return;
  8864. }
  8865. var touches = normalizeSingleTouches.call(this, ev, type);
  8866. // when done, reset the started state
  8867. if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
  8868. this.started = false;
  8869. }
  8870. this.callback(this.manager, type, {
  8871. pointers: touches[0],
  8872. changedPointers: touches[1],
  8873. pointerType: INPUT_TYPE_TOUCH,
  8874. srcEvent: ev
  8875. });
  8876. }
  8877. });
  8878. /**
  8879. * @this {TouchInput}
  8880. * @param {Object} ev
  8881. * @param {Number} type flag
  8882. * @returns {undefined|Array} [all, changed]
  8883. */
  8884. function normalizeSingleTouches(ev, type) {
  8885. var all = toArray(ev.touches);
  8886. var changed = toArray(ev.changedTouches);
  8887. if (type & (INPUT_END | INPUT_CANCEL)) {
  8888. all = uniqueArray(all.concat(changed), 'identifier', true);
  8889. }
  8890. return [all, changed];
  8891. }
  8892. var TOUCH_INPUT_MAP = {
  8893. touchstart: INPUT_START,
  8894. touchmove: INPUT_MOVE,
  8895. touchend: INPUT_END,
  8896. touchcancel: INPUT_CANCEL
  8897. };
  8898. var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
  8899. /**
  8900. * Multi-user touch events input
  8901. * @constructor
  8902. * @extends Input
  8903. */
  8904. function TouchInput() {
  8905. this.evTarget = TOUCH_TARGET_EVENTS;
  8906. this.targetIds = {};
  8907. Input.apply(this, arguments);
  8908. }
  8909. inherit(TouchInput, Input, {
  8910. handler: function MTEhandler(ev) {
  8911. var type = TOUCH_INPUT_MAP[ev.type];
  8912. var touches = getTouches.call(this, ev, type);
  8913. if (!touches) {
  8914. return;
  8915. }
  8916. this.callback(this.manager, type, {
  8917. pointers: touches[0],
  8918. changedPointers: touches[1],
  8919. pointerType: INPUT_TYPE_TOUCH,
  8920. srcEvent: ev
  8921. });
  8922. }
  8923. });
  8924. /**
  8925. * @this {TouchInput}
  8926. * @param {Object} ev
  8927. * @param {Number} type flag
  8928. * @returns {undefined|Array} [all, changed]
  8929. */
  8930. function getTouches(ev, type) {
  8931. var allTouches = toArray(ev.touches);
  8932. var targetIds = this.targetIds;
  8933. // when there is only one touch, the process can be simplified
  8934. if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
  8935. targetIds[allTouches[0].identifier] = true;
  8936. return [allTouches, allTouches];
  8937. }
  8938. var i,
  8939. targetTouches,
  8940. changedTouches = toArray(ev.changedTouches),
  8941. changedTargetTouches = [],
  8942. target = this.target;
  8943. // get target touches from touches
  8944. targetTouches = allTouches.filter(function(touch) {
  8945. return hasParent(touch.target, target);
  8946. });
  8947. // collect touches
  8948. if (type === INPUT_START) {
  8949. i = 0;
  8950. while (i < targetTouches.length) {
  8951. targetIds[targetTouches[i].identifier] = true;
  8952. i++;
  8953. }
  8954. }
  8955. // filter changed touches to only contain touches that exist in the collected target ids
  8956. i = 0;
  8957. while (i < changedTouches.length) {
  8958. if (targetIds[changedTouches[i].identifier]) {
  8959. changedTargetTouches.push(changedTouches[i]);
  8960. }
  8961. // cleanup removed touches
  8962. if (type & (INPUT_END | INPUT_CANCEL)) {
  8963. delete targetIds[changedTouches[i].identifier];
  8964. }
  8965. i++;
  8966. }
  8967. if (!changedTargetTouches.length) {
  8968. return;
  8969. }
  8970. return [
  8971. // merge targetTouches with changedTargetTouches so it contains ALL touches, including 'end' and 'cancel'
  8972. uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true),
  8973. changedTargetTouches
  8974. ];
  8975. }
  8976. /**
  8977. * Combined touch and mouse input
  8978. *
  8979. * Touch has a higher priority then mouse, and while touching no mouse events are allowed.
  8980. * This because touch devices also emit mouse events while doing a touch.
  8981. *
  8982. * @constructor
  8983. * @extends Input
  8984. */
  8985. function TouchMouseInput() {
  8986. Input.apply(this, arguments);
  8987. var handler = bindFn(this.handler, this);
  8988. this.touch = new TouchInput(this.manager, handler);
  8989. this.mouse = new MouseInput(this.manager, handler);
  8990. }
  8991. inherit(TouchMouseInput, Input, {
  8992. /**
  8993. * handle mouse and touch events
  8994. * @param {Hammer} manager
  8995. * @param {String} inputEvent
  8996. * @param {Object} inputData
  8997. */
  8998. handler: function TMEhandler(manager, inputEvent, inputData) {
  8999. var isTouch = (inputData.pointerType == INPUT_TYPE_TOUCH),
  9000. isMouse = (inputData.pointerType == INPUT_TYPE_MOUSE);
  9001. // when we're in a touch event, so block all upcoming mouse events
  9002. // most mobile browser also emit mouseevents, right after touchstart
  9003. if (isTouch) {
  9004. this.mouse.allow = false;
  9005. } else if (isMouse && !this.mouse.allow) {
  9006. return;
  9007. }
  9008. // reset the allowMouse when we're done
  9009. if (inputEvent & (INPUT_END | INPUT_CANCEL)) {
  9010. this.mouse.allow = true;
  9011. }
  9012. this.callback(manager, inputEvent, inputData);
  9013. },
  9014. /**
  9015. * remove the event listeners
  9016. */
  9017. destroy: function destroy() {
  9018. this.touch.destroy();
  9019. this.mouse.destroy();
  9020. }
  9021. });
  9022. var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
  9023. var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
  9024. // magical touchAction value
  9025. var TOUCH_ACTION_COMPUTE = 'compute';
  9026. var TOUCH_ACTION_AUTO = 'auto';
  9027. var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented
  9028. var TOUCH_ACTION_NONE = 'none';
  9029. var TOUCH_ACTION_PAN_X = 'pan-x';
  9030. var TOUCH_ACTION_PAN_Y = 'pan-y';
  9031. /**
  9032. * Touch Action
  9033. * sets the touchAction property or uses the js alternative
  9034. * @param {Manager} manager
  9035. * @param {String} value
  9036. * @constructor
  9037. */
  9038. function TouchAction(manager, value) {
  9039. this.manager = manager;
  9040. this.set(value);
  9041. }
  9042. TouchAction.prototype = {
  9043. /**
  9044. * set the touchAction value on the element or enable the polyfill
  9045. * @param {String} value
  9046. */
  9047. set: function(value) {
  9048. // find out the touch-action by the event handlers
  9049. if (value == TOUCH_ACTION_COMPUTE) {
  9050. value = this.compute();
  9051. }
  9052. if (NATIVE_TOUCH_ACTION) {
  9053. this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
  9054. }
  9055. this.actions = value.toLowerCase().trim();
  9056. },
  9057. /**
  9058. * just re-set the touchAction value
  9059. */
  9060. update: function() {
  9061. this.set(this.manager.options.touchAction);
  9062. },
  9063. /**
  9064. * compute the value for the touchAction property based on the recognizer's settings
  9065. * @returns {String} value
  9066. */
  9067. compute: function() {
  9068. var actions = [];
  9069. each(this.manager.recognizers, function(recognizer) {
  9070. if (boolOrFn(recognizer.options.enable, [recognizer])) {
  9071. actions = actions.concat(recognizer.getTouchAction());
  9072. }
  9073. });
  9074. return cleanTouchActions(actions.join(' '));
  9075. },
  9076. /**
  9077. * this method is called on each input cycle and provides the preventing of the browser behavior
  9078. * @param {Object} input
  9079. */
  9080. preventDefaults: function(input) {
  9081. // not needed with native support for the touchAction property
  9082. if (NATIVE_TOUCH_ACTION) {
  9083. return;
  9084. }
  9085. var srcEvent = input.srcEvent;
  9086. var direction = input.offsetDirection;
  9087. // if the touch action did prevented once this session
  9088. if (this.manager.session.prevented) {
  9089. srcEvent.preventDefault();
  9090. return;
  9091. }
  9092. var actions = this.actions;
  9093. var hasNone = inStr(actions, TOUCH_ACTION_NONE);
  9094. var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
  9095. var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
  9096. if (hasNone ||
  9097. (hasPanY && direction & DIRECTION_HORIZONTAL) ||
  9098. (hasPanX && direction & DIRECTION_VERTICAL)) {
  9099. return this.preventSrc(srcEvent);
  9100. }
  9101. },
  9102. /**
  9103. * call preventDefault to prevent the browser's default behavior (scrolling in most cases)
  9104. * @param {Object} srcEvent
  9105. */
  9106. preventSrc: function(srcEvent) {
  9107. this.manager.session.prevented = true;
  9108. srcEvent.preventDefault();
  9109. }
  9110. };
  9111. /**
  9112. * when the touchActions are collected they are not a valid value, so we need to clean things up. *
  9113. * @param {String} actions
  9114. * @returns {*}
  9115. */
  9116. function cleanTouchActions(actions) {
  9117. // none
  9118. if (inStr(actions, TOUCH_ACTION_NONE)) {
  9119. return TOUCH_ACTION_NONE;
  9120. }
  9121. var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
  9122. var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y);
  9123. // pan-x and pan-y can be combined
  9124. if (hasPanX && hasPanY) {
  9125. return TOUCH_ACTION_PAN_X + ' ' + TOUCH_ACTION_PAN_Y;
  9126. }
  9127. // pan-x OR pan-y
  9128. if (hasPanX || hasPanY) {
  9129. return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
  9130. }
  9131. // manipulation
  9132. if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
  9133. return TOUCH_ACTION_MANIPULATION;
  9134. }
  9135. return TOUCH_ACTION_AUTO;
  9136. }
  9137. /**
  9138. * Recognizer flow explained; *
  9139. * All recognizers have the initial state of POSSIBLE when a input session starts.
  9140. * The definition of a input session is from the first input until the last input, with all it's movement in it. *
  9141. * Example session for mouse-input: mousedown -> mousemove -> mouseup
  9142. *
  9143. * On each recognizing cycle (see Manager.recognize) the .recognize() method is executed
  9144. * which determines with state it should be.
  9145. *
  9146. * If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to
  9147. * POSSIBLE to give it another change on the next cycle.
  9148. *
  9149. * Possible
  9150. * |
  9151. * +-----+---------------+
  9152. * | |
  9153. * +-----+-----+ |
  9154. * | | |
  9155. * Failed Cancelled |
  9156. * +-------+------+
  9157. * | |
  9158. * Recognized Began
  9159. * |
  9160. * Changed
  9161. * |
  9162. * Ended/Recognized
  9163. */
  9164. var STATE_POSSIBLE = 1;
  9165. var STATE_BEGAN = 2;
  9166. var STATE_CHANGED = 4;
  9167. var STATE_ENDED = 8;
  9168. var STATE_RECOGNIZED = STATE_ENDED;
  9169. var STATE_CANCELLED = 16;
  9170. var STATE_FAILED = 32;
  9171. /**
  9172. * Recognizer
  9173. * Every recognizer needs to extend from this class.
  9174. * @constructor
  9175. * @param {Object} options
  9176. */
  9177. function Recognizer(options) {
  9178. this.id = uniqueId();
  9179. this.manager = null;
  9180. this.options = merge(options || {}, this.defaults);
  9181. // default is enable true
  9182. this.options.enable = ifUndefined(this.options.enable, true);
  9183. this.state = STATE_POSSIBLE;
  9184. this.simultaneous = {};
  9185. this.requireFail = [];
  9186. }
  9187. Recognizer.prototype = {
  9188. /**
  9189. * @virtual
  9190. * @type {Object}
  9191. */
  9192. defaults: {},
  9193. /**
  9194. * set options
  9195. * @param {Object} options
  9196. * @return {Recognizer}
  9197. */
  9198. set: function(options) {
  9199. extend(this.options, options);
  9200. // also update the touchAction, in case something changed about the directions/enabled state
  9201. this.manager && this.manager.touchAction.update();
  9202. return this;
  9203. },
  9204. /**
  9205. * recognize simultaneous with an other recognizer.
  9206. * @param {Recognizer} otherRecognizer
  9207. * @returns {Recognizer} this
  9208. */
  9209. recognizeWith: function(otherRecognizer) {
  9210. if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
  9211. return this;
  9212. }
  9213. var simultaneous = this.simultaneous;
  9214. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  9215. if (!simultaneous[otherRecognizer.id]) {
  9216. simultaneous[otherRecognizer.id] = otherRecognizer;
  9217. otherRecognizer.recognizeWith(this);
  9218. }
  9219. return this;
  9220. },
  9221. /**
  9222. * drop the simultaneous link. it doesnt remove the link on the other recognizer.
  9223. * @param {Recognizer} otherRecognizer
  9224. * @returns {Recognizer} this
  9225. */
  9226. dropRecognizeWith: function(otherRecognizer) {
  9227. if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
  9228. return this;
  9229. }
  9230. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  9231. delete this.simultaneous[otherRecognizer.id];
  9232. return this;
  9233. },
  9234. /**
  9235. * recognizer can only run when an other is failing
  9236. * @param {Recognizer} otherRecognizer
  9237. * @returns {Recognizer} this
  9238. */
  9239. requireFailure: function(otherRecognizer) {
  9240. if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
  9241. return this;
  9242. }
  9243. var requireFail = this.requireFail;
  9244. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  9245. if (inArray(requireFail, otherRecognizer) === -1) {
  9246. requireFail.push(otherRecognizer);
  9247. otherRecognizer.requireFailure(this);
  9248. }
  9249. return this;
  9250. },
  9251. /**
  9252. * drop the requireFailure link. it does not remove the link on the other recognizer.
  9253. * @param {Recognizer} otherRecognizer
  9254. * @returns {Recognizer} this
  9255. */
  9256. dropRequireFailure: function(otherRecognizer) {
  9257. if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
  9258. return this;
  9259. }
  9260. otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
  9261. var index = inArray(this.requireFail, otherRecognizer);
  9262. if (index > -1) {
  9263. this.requireFail.splice(index, 1);
  9264. }
  9265. return this;
  9266. },
  9267. /**
  9268. * has require failures boolean
  9269. * @returns {boolean}
  9270. */
  9271. hasRequireFailures: function() {
  9272. return this.requireFail.length > 0;
  9273. },
  9274. /**
  9275. * if the recognizer can recognize simultaneous with an other recognizer
  9276. * @param {Recognizer} otherRecognizer
  9277. * @returns {Boolean}
  9278. */
  9279. canRecognizeWith: function(otherRecognizer) {
  9280. return !!this.simultaneous[otherRecognizer.id];
  9281. },
  9282. /**
  9283. * You should use `tryEmit` instead of `emit` directly to check
  9284. * that all the needed recognizers has failed before emitting.
  9285. * @param {Object} input
  9286. */
  9287. emit: function(input) {
  9288. var self = this;
  9289. var state = this.state;
  9290. function emit(withState) {
  9291. self.manager.emit(self.options.event + (withState ? stateStr(state) : ''), input);
  9292. }
  9293. // 'panstart' and 'panmove'
  9294. if (state < STATE_ENDED) {
  9295. emit(true);
  9296. }
  9297. emit(); // simple 'eventName' events
  9298. // panend and pancancel
  9299. if (state >= STATE_ENDED) {
  9300. emit(true);
  9301. }
  9302. },
  9303. /**
  9304. * Check that all the require failure recognizers has failed,
  9305. * if true, it emits a gesture event,
  9306. * otherwise, setup the state to FAILED.
  9307. * @param {Object} input
  9308. */
  9309. tryEmit: function(input) {
  9310. if (this.canEmit()) {
  9311. return this.emit(input);
  9312. }
  9313. // it's failing anyway
  9314. this.state = STATE_FAILED;
  9315. },
  9316. /**
  9317. * can we emit?
  9318. * @returns {boolean}
  9319. */
  9320. canEmit: function() {
  9321. var i = 0;
  9322. while (i < this.requireFail.length) {
  9323. if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
  9324. return false;
  9325. }
  9326. i++;
  9327. }
  9328. return true;
  9329. },
  9330. /**
  9331. * update the recognizer
  9332. * @param {Object} inputData
  9333. */
  9334. recognize: function(inputData) {
  9335. // make a new copy of the inputData
  9336. // so we can change the inputData without messing up the other recognizers
  9337. var inputDataClone = extend({}, inputData);
  9338. // is is enabled and allow recognizing?
  9339. if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
  9340. this.reset();
  9341. this.state = STATE_FAILED;
  9342. return;
  9343. }
  9344. // reset when we've reached the end
  9345. if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
  9346. this.state = STATE_POSSIBLE;
  9347. }
  9348. this.state = this.process(inputDataClone);
  9349. // the recognizer has recognized a gesture
  9350. // so trigger an event
  9351. if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
  9352. this.tryEmit(inputDataClone);
  9353. }
  9354. },
  9355. /**
  9356. * return the state of the recognizer
  9357. * the actual recognizing happens in this method
  9358. * @virtual
  9359. * @param {Object} inputData
  9360. * @returns {Const} STATE
  9361. */
  9362. process: function(inputData) {
  9363. }, // jshint ignore:line
  9364. /**
  9365. * return the preferred touch-action
  9366. * @virtual
  9367. * @returns {Array}
  9368. */
  9369. getTouchAction: function() {
  9370. },
  9371. /**
  9372. * called when the gesture isn't allowed to recognize
  9373. * like when another is being recognized or it is disabled
  9374. * @virtual
  9375. */
  9376. reset: function() {
  9377. }
  9378. };
  9379. /**
  9380. * get a usable string, used as event postfix
  9381. * @param {Const} state
  9382. * @returns {String} state
  9383. */
  9384. function stateStr(state) {
  9385. if (state & STATE_CANCELLED) {
  9386. return 'cancel';
  9387. } else if (state & STATE_ENDED) {
  9388. return 'end';
  9389. } else if (state & STATE_CHANGED) {
  9390. return 'move';
  9391. } else if (state & STATE_BEGAN) {
  9392. return 'start';
  9393. }
  9394. return '';
  9395. }
  9396. /**
  9397. * direction cons to string
  9398. * @param {Const} direction
  9399. * @returns {String}
  9400. */
  9401. function directionStr(direction) {
  9402. if (direction == DIRECTION_DOWN) {
  9403. return 'down';
  9404. } else if (direction == DIRECTION_UP) {
  9405. return 'up';
  9406. } else if (direction == DIRECTION_LEFT) {
  9407. return 'left';
  9408. } else if (direction == DIRECTION_RIGHT) {
  9409. return 'right';
  9410. }
  9411. return '';
  9412. }
  9413. /**
  9414. * get a recognizer by name if it is bound to a manager
  9415. * @param {Recognizer|String} otherRecognizer
  9416. * @param {Recognizer} recognizer
  9417. * @returns {Recognizer}
  9418. */
  9419. function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
  9420. var manager = recognizer.manager;
  9421. if (manager) {
  9422. return manager.get(otherRecognizer);
  9423. }
  9424. return otherRecognizer;
  9425. }
  9426. /**
  9427. * This recognizer is just used as a base for the simple attribute recognizers.
  9428. * @constructor
  9429. * @extends Recognizer
  9430. */
  9431. function AttrRecognizer() {
  9432. Recognizer.apply(this, arguments);
  9433. }
  9434. inherit(AttrRecognizer, Recognizer, {
  9435. /**
  9436. * @namespace
  9437. * @memberof AttrRecognizer
  9438. */
  9439. defaults: {
  9440. /**
  9441. * @type {Number}
  9442. * @default 1
  9443. */
  9444. pointers: 1
  9445. },
  9446. /**
  9447. * Used to check if it the recognizer receives valid input, like input.distance > 10.
  9448. * @memberof AttrRecognizer
  9449. * @param {Object} input
  9450. * @returns {Boolean} recognized
  9451. */
  9452. attrTest: function(input) {
  9453. var optionPointers = this.options.pointers;
  9454. return optionPointers === 0 || input.pointers.length === optionPointers;
  9455. },
  9456. /**
  9457. * Process the input and return the state for the recognizer
  9458. * @memberof AttrRecognizer
  9459. * @param {Object} input
  9460. * @returns {*} State
  9461. */
  9462. process: function(input) {
  9463. var state = this.state;
  9464. var eventType = input.eventType;
  9465. var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
  9466. var isValid = this.attrTest(input);
  9467. // on cancel input and we've recognized before, return STATE_CANCELLED
  9468. if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
  9469. return state | STATE_CANCELLED;
  9470. } else if (isRecognized || isValid) {
  9471. if (eventType & INPUT_END) {
  9472. return state | STATE_ENDED;
  9473. } else if (!(state & STATE_BEGAN)) {
  9474. return STATE_BEGAN;
  9475. }
  9476. return state | STATE_CHANGED;
  9477. }
  9478. return STATE_FAILED;
  9479. }
  9480. });
  9481. /**
  9482. * Pan
  9483. * Recognized when the pointer is down and moved in the allowed direction.
  9484. * @constructor
  9485. * @extends AttrRecognizer
  9486. */
  9487. function PanRecognizer() {
  9488. AttrRecognizer.apply(this, arguments);
  9489. this.pX = null;
  9490. this.pY = null;
  9491. }
  9492. inherit(PanRecognizer, AttrRecognizer, {
  9493. /**
  9494. * @namespace
  9495. * @memberof PanRecognizer
  9496. */
  9497. defaults: {
  9498. event: 'pan',
  9499. threshold: 10,
  9500. pointers: 1,
  9501. direction: DIRECTION_ALL
  9502. },
  9503. getTouchAction: function() {
  9504. var direction = this.options.direction;
  9505. var actions = [];
  9506. if (direction & DIRECTION_HORIZONTAL) {
  9507. actions.push(TOUCH_ACTION_PAN_Y);
  9508. }
  9509. if (direction & DIRECTION_VERTICAL) {
  9510. actions.push(TOUCH_ACTION_PAN_X);
  9511. }
  9512. return actions;
  9513. },
  9514. directionTest: function(input) {
  9515. var options = this.options;
  9516. var hasMoved = true;
  9517. var distance = input.distance;
  9518. var direction = input.direction;
  9519. var x = input.deltaX;
  9520. var y = input.deltaY;
  9521. // lock to axis?
  9522. if (!(direction & options.direction)) {
  9523. if (options.direction & DIRECTION_HORIZONTAL) {
  9524. direction = (x === 0) ? DIRECTION_NONE : (x < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT;
  9525. hasMoved = x != this.pX;
  9526. distance = Math.abs(input.deltaX);
  9527. } else {
  9528. direction = (y === 0) ? DIRECTION_NONE : (y < 0) ? DIRECTION_UP : DIRECTION_DOWN;
  9529. hasMoved = y != this.pY;
  9530. distance = Math.abs(input.deltaY);
  9531. }
  9532. }
  9533. input.direction = direction;
  9534. return hasMoved && distance > options.threshold && direction & options.direction;
  9535. },
  9536. attrTest: function(input) {
  9537. return AttrRecognizer.prototype.attrTest.call(this, input) &&
  9538. (this.state & STATE_BEGAN || (!(this.state & STATE_BEGAN) && this.directionTest(input)));
  9539. },
  9540. emit: function(input) {
  9541. this.pX = input.deltaX;
  9542. this.pY = input.deltaY;
  9543. var direction = directionStr(input.direction);
  9544. if (direction) {
  9545. this.manager.emit(this.options.event + direction, input);
  9546. }
  9547. this._super.emit.call(this, input);
  9548. }
  9549. });
  9550. /**
  9551. * Pinch
  9552. * Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out).
  9553. * @constructor
  9554. * @extends AttrRecognizer
  9555. */
  9556. function PinchRecognizer() {
  9557. AttrRecognizer.apply(this, arguments);
  9558. }
  9559. inherit(PinchRecognizer, AttrRecognizer, {
  9560. /**
  9561. * @namespace
  9562. * @memberof PinchRecognizer
  9563. */
  9564. defaults: {
  9565. event: 'pinch',
  9566. threshold: 0,
  9567. pointers: 2
  9568. },
  9569. getTouchAction: function() {
  9570. return [TOUCH_ACTION_NONE];
  9571. },
  9572. attrTest: function(input) {
  9573. return this._super.attrTest.call(this, input) &&
  9574. (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
  9575. },
  9576. emit: function(input) {
  9577. this._super.emit.call(this, input);
  9578. if (input.scale !== 1) {
  9579. var inOut = input.scale < 1 ? 'in' : 'out';
  9580. this.manager.emit(this.options.event + inOut, input);
  9581. }
  9582. }
  9583. });
  9584. /**
  9585. * Press
  9586. * Recognized when the pointer is down for x ms without any movement.
  9587. * @constructor
  9588. * @extends Recognizer
  9589. */
  9590. function PressRecognizer() {
  9591. Recognizer.apply(this, arguments);
  9592. this._timer = null;
  9593. this._input = null;
  9594. }
  9595. inherit(PressRecognizer, Recognizer, {
  9596. /**
  9597. * @namespace
  9598. * @memberof PressRecognizer
  9599. */
  9600. defaults: {
  9601. event: 'press',
  9602. pointers: 1,
  9603. time: 500, // minimal time of the pointer to be pressed
  9604. threshold: 5 // a minimal movement is ok, but keep it low
  9605. },
  9606. getTouchAction: function() {
  9607. return [TOUCH_ACTION_AUTO];
  9608. },
  9609. process: function(input) {
  9610. var options = this.options;
  9611. var validPointers = input.pointers.length === options.pointers;
  9612. var validMovement = input.distance < options.threshold;
  9613. var validTime = input.deltaTime > options.time;
  9614. this._input = input;
  9615. // we only allow little movement
  9616. // and we've reached an end event, so a tap is possible
  9617. if (!validMovement || !validPointers || (input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime)) {
  9618. this.reset();
  9619. } else if (input.eventType & INPUT_START) {
  9620. this.reset();
  9621. this._timer = setTimeoutContext(function() {
  9622. this.state = STATE_RECOGNIZED;
  9623. this.tryEmit();
  9624. }, options.time, this);
  9625. } else if (input.eventType & INPUT_END) {
  9626. return STATE_RECOGNIZED;
  9627. }
  9628. return STATE_FAILED;
  9629. },
  9630. reset: function() {
  9631. clearTimeout(this._timer);
  9632. },
  9633. emit: function(input) {
  9634. if (this.state !== STATE_RECOGNIZED) {
  9635. return;
  9636. }
  9637. if (input && (input.eventType & INPUT_END)) {
  9638. this.manager.emit(this.options.event + 'up', input);
  9639. } else {
  9640. this._input.timeStamp = now();
  9641. this.manager.emit(this.options.event, this._input);
  9642. }
  9643. }
  9644. });
  9645. /**
  9646. * Rotate
  9647. * Recognized when two or more pointer are moving in a circular motion.
  9648. * @constructor
  9649. * @extends AttrRecognizer
  9650. */
  9651. function RotateRecognizer() {
  9652. AttrRecognizer.apply(this, arguments);
  9653. }
  9654. inherit(RotateRecognizer, AttrRecognizer, {
  9655. /**
  9656. * @namespace
  9657. * @memberof RotateRecognizer
  9658. */
  9659. defaults: {
  9660. event: 'rotate',
  9661. threshold: 0,
  9662. pointers: 2
  9663. },
  9664. getTouchAction: function() {
  9665. return [TOUCH_ACTION_NONE];
  9666. },
  9667. attrTest: function(input) {
  9668. return this._super.attrTest.call(this, input) &&
  9669. (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
  9670. }
  9671. });
  9672. /**
  9673. * Swipe
  9674. * Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction.
  9675. * @constructor
  9676. * @extends AttrRecognizer
  9677. */
  9678. function SwipeRecognizer() {
  9679. AttrRecognizer.apply(this, arguments);
  9680. }
  9681. inherit(SwipeRecognizer, AttrRecognizer, {
  9682. /**
  9683. * @namespace
  9684. * @memberof SwipeRecognizer
  9685. */
  9686. defaults: {
  9687. event: 'swipe',
  9688. threshold: 10,
  9689. velocity: 0.65,
  9690. direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
  9691. pointers: 1
  9692. },
  9693. getTouchAction: function() {
  9694. return PanRecognizer.prototype.getTouchAction.call(this);
  9695. },
  9696. attrTest: function(input) {
  9697. var direction = this.options.direction;
  9698. var velocity;
  9699. if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
  9700. velocity = input.velocity;
  9701. } else if (direction & DIRECTION_HORIZONTAL) {
  9702. velocity = input.velocityX;
  9703. } else if (direction & DIRECTION_VERTICAL) {
  9704. velocity = input.velocityY;
  9705. }
  9706. return this._super.attrTest.call(this, input) &&
  9707. direction & input.direction &&
  9708. input.distance > this.options.threshold &&
  9709. abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
  9710. },
  9711. emit: function(input) {
  9712. var direction = directionStr(input.direction);
  9713. if (direction) {
  9714. this.manager.emit(this.options.event + direction, input);
  9715. }
  9716. this.manager.emit(this.options.event, input);
  9717. }
  9718. });
  9719. /**
  9720. * A tap is ecognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur
  9721. * between the given interval and position. The delay option can be used to recognize multi-taps without firing
  9722. * a single tap.
  9723. *
  9724. * The eventData from the emitted event contains the property `tapCount`, which contains the amount of
  9725. * multi-taps being recognized.
  9726. * @constructor
  9727. * @extends Recognizer
  9728. */
  9729. function TapRecognizer() {
  9730. Recognizer.apply(this, arguments);
  9731. // previous time and center,
  9732. // used for tap counting
  9733. this.pTime = false;
  9734. this.pCenter = false;
  9735. this._timer = null;
  9736. this._input = null;
  9737. this.count = 0;
  9738. }
  9739. inherit(TapRecognizer, Recognizer, {
  9740. /**
  9741. * @namespace
  9742. * @memberof PinchRecognizer
  9743. */
  9744. defaults: {
  9745. event: 'tap',
  9746. pointers: 1,
  9747. taps: 1,
  9748. interval: 300, // max time between the multi-tap taps
  9749. time: 250, // max time of the pointer to be down (like finger on the screen)
  9750. threshold: 2, // a minimal movement is ok, but keep it low
  9751. posThreshold: 10 // a multi-tap can be a bit off the initial position
  9752. },
  9753. getTouchAction: function() {
  9754. return [TOUCH_ACTION_MANIPULATION];
  9755. },
  9756. process: function(input) {
  9757. var options = this.options;
  9758. var validPointers = input.pointers.length === options.pointers;
  9759. var validMovement = input.distance < options.threshold;
  9760. var validTouchTime = input.deltaTime < options.time;
  9761. this.reset();
  9762. if ((input.eventType & INPUT_START) && (this.count === 0)) {
  9763. return this.failTimeout();
  9764. }
  9765. // we only allow little movement
  9766. // and we've reached an end event, so a tap is possible
  9767. if (validMovement && validTouchTime && validPointers) {
  9768. if (input.eventType != INPUT_END) {
  9769. return this.failTimeout();
  9770. }
  9771. var validInterval = this.pTime ? (input.timeStamp - this.pTime < options.interval) : true;
  9772. var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
  9773. this.pTime = input.timeStamp;
  9774. this.pCenter = input.center;
  9775. if (!validMultiTap || !validInterval) {
  9776. this.count = 1;
  9777. } else {
  9778. this.count += 1;
  9779. }
  9780. this._input = input;
  9781. // if tap count matches we have recognized it,
  9782. // else it has began recognizing...
  9783. var tapCount = this.count % options.taps;
  9784. if (tapCount === 0) {
  9785. // no failing requirements, immediately trigger the tap event
  9786. // or wait as long as the multitap interval to trigger
  9787. if (!this.hasRequireFailures()) {
  9788. return STATE_RECOGNIZED;
  9789. } else {
  9790. this._timer = setTimeoutContext(function() {
  9791. this.state = STATE_RECOGNIZED;
  9792. this.tryEmit();
  9793. }, options.interval, this);
  9794. return STATE_BEGAN;
  9795. }
  9796. }
  9797. }
  9798. return STATE_FAILED;
  9799. },
  9800. failTimeout: function() {
  9801. this._timer = setTimeoutContext(function() {
  9802. this.state = STATE_FAILED;
  9803. }, this.options.interval, this);
  9804. return STATE_FAILED;
  9805. },
  9806. reset: function() {
  9807. clearTimeout(this._timer);
  9808. },
  9809. emit: function() {
  9810. if (this.state == STATE_RECOGNIZED) {
  9811. this._input.tapCount = this.count;
  9812. this.manager.emit(this.options.event, this._input);
  9813. }
  9814. }
  9815. });
  9816. /**
  9817. * Simple way to create an manager with a default set of recognizers.
  9818. * @param {HTMLElement} element
  9819. * @param {Object} [options]
  9820. * @constructor
  9821. */
  9822. function Hammer(element, options) {
  9823. options = options || {};
  9824. options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
  9825. return new Manager(element, options);
  9826. }
  9827. /**
  9828. * @const {string}
  9829. */
  9830. Hammer.VERSION = '2.0.4';
  9831. /**
  9832. * default settings
  9833. * @namespace
  9834. */
  9835. Hammer.defaults = {
  9836. /**
  9837. * set if DOM events are being triggered.
  9838. * But this is slower and unused by simple implementations, so disabled by default.
  9839. * @type {Boolean}
  9840. * @default false
  9841. */
  9842. domEvents: false,
  9843. /**
  9844. * The value for the touchAction property/fallback.
  9845. * When set to `compute` it will magically set the correct value based on the added recognizers.
  9846. * @type {String}
  9847. * @default compute
  9848. */
  9849. touchAction: TOUCH_ACTION_COMPUTE,
  9850. /**
  9851. * @type {Boolean}
  9852. * @default true
  9853. */
  9854. enable: true,
  9855. /**
  9856. * EXPERIMENTAL FEATURE -- can be removed/changed
  9857. * Change the parent input target element.
  9858. * If Null, then it is being set the to main element.
  9859. * @type {Null|EventTarget}
  9860. * @default null
  9861. */
  9862. inputTarget: null,
  9863. /**
  9864. * force an input class
  9865. * @type {Null|Function}
  9866. * @default null
  9867. */
  9868. inputClass: null,
  9869. /**
  9870. * Default recognizer setup when calling `Hammer()`
  9871. * When creating a new Manager these will be skipped.
  9872. * @type {Array}
  9873. */
  9874. preset: [
  9875. // RecognizerClass, options, [recognizeWith, ...], [requireFailure, ...]
  9876. [RotateRecognizer, {enable: false}],
  9877. [PinchRecognizer, {enable: false}, ['rotate']],
  9878. [SwipeRecognizer, {direction: DIRECTION_HORIZONTAL}],
  9879. [PanRecognizer, {direction: DIRECTION_HORIZONTAL}, ['swipe']],
  9880. [TapRecognizer],
  9881. [TapRecognizer, {event: 'doubletap', taps: 2}, ['tap']],
  9882. [PressRecognizer]
  9883. ],
  9884. /**
  9885. * Some CSS properties can be used to improve the working of Hammer.
  9886. * Add them to this method and they will be set when creating a new Manager.
  9887. * @namespace
  9888. */
  9889. cssProps: {
  9890. /**
  9891. * Disables text selection to improve the dragging gesture. Mainly for desktop browsers.
  9892. * @type {String}
  9893. * @default 'none'
  9894. */
  9895. userSelect: 'none',
  9896. /**
  9897. * Disable the Windows Phone grippers when pressing an element.
  9898. * @type {String}
  9899. * @default 'none'
  9900. */
  9901. touchSelect: 'none',
  9902. /**
  9903. * Disables the default callout shown when you touch and hold a touch target.
  9904. * On iOS, when you touch and hold a touch target such as a link, Safari displays
  9905. * a callout containing information about the link. This property allows you to disable that callout.
  9906. * @type {String}
  9907. * @default 'none'
  9908. */
  9909. touchCallout: 'none',
  9910. /**
  9911. * Specifies whether zooming is enabled. Used by IE10>
  9912. * @type {String}
  9913. * @default 'none'
  9914. */
  9915. contentZooming: 'none',
  9916. /**
  9917. * Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers.
  9918. * @type {String}
  9919. * @default 'none'
  9920. */
  9921. userDrag: 'none',
  9922. /**
  9923. * Overrides the highlight color shown when the user taps a link or a JavaScript
  9924. * clickable element in iOS. This property obeys the alpha value, if specified.
  9925. * @type {String}
  9926. * @default 'rgba(0,0,0,0)'
  9927. */
  9928. tapHighlightColor: 'rgba(0,0,0,0)'
  9929. }
  9930. };
  9931. var STOP = 1;
  9932. var FORCED_STOP = 2;
  9933. /**
  9934. * Manager
  9935. * @param {HTMLElement} element
  9936. * @param {Object} [options]
  9937. * @constructor
  9938. */
  9939. function Manager(element, options) {
  9940. options = options || {};
  9941. this.options = merge(options, Hammer.defaults);
  9942. this.options.inputTarget = this.options.inputTarget || element;
  9943. this.handlers = {};
  9944. this.session = {};
  9945. this.recognizers = [];
  9946. this.element = element;
  9947. this.input = createInputInstance(this);
  9948. this.touchAction = new TouchAction(this, this.options.touchAction);
  9949. toggleCssProps(this, true);
  9950. each(options.recognizers, function(item) {
  9951. var recognizer = this.add(new (item[0])(item[1]));
  9952. item[2] && recognizer.recognizeWith(item[2]);
  9953. item[3] && recognizer.requireFailure(item[3]);
  9954. }, this);
  9955. }
  9956. Manager.prototype = {
  9957. /**
  9958. * set options
  9959. * @param {Object} options
  9960. * @returns {Manager}
  9961. */
  9962. set: function(options) {
  9963. extend(this.options, options);
  9964. // Options that need a little more setup
  9965. if (options.touchAction) {
  9966. this.touchAction.update();
  9967. }
  9968. if (options.inputTarget) {
  9969. // Clean up existing event listeners and reinitialize
  9970. this.input.destroy();
  9971. this.input.target = options.inputTarget;
  9972. this.input.init();
  9973. }
  9974. return this;
  9975. },
  9976. /**
  9977. * stop recognizing for this session.
  9978. * This session will be discarded, when a new [input]start event is fired.
  9979. * When forced, the recognizer cycle is stopped immediately.
  9980. * @param {Boolean} [force]
  9981. */
  9982. stop: function(force) {
  9983. this.session.stopped = force ? FORCED_STOP : STOP;
  9984. },
  9985. /**
  9986. * run the recognizers!
  9987. * called by the inputHandler function on every movement of the pointers (touches)
  9988. * it walks through all the recognizers and tries to detect the gesture that is being made
  9989. * @param {Object} inputData
  9990. */
  9991. recognize: function(inputData) {
  9992. var session = this.session;
  9993. if (session.stopped) {
  9994. return;
  9995. }
  9996. // run the touch-action polyfill
  9997. this.touchAction.preventDefaults(inputData);
  9998. var recognizer;
  9999. var recognizers = this.recognizers;
  10000. // this holds the recognizer that is being recognized.
  10001. // so the recognizer's state needs to be BEGAN, CHANGED, ENDED or RECOGNIZED
  10002. // if no recognizer is detecting a thing, it is set to `null`
  10003. var curRecognizer = session.curRecognizer;
  10004. // reset when the last recognizer is recognized
  10005. // or when we're in a new session
  10006. if (!curRecognizer || (curRecognizer && curRecognizer.state & STATE_RECOGNIZED)) {
  10007. curRecognizer = session.curRecognizer = null;
  10008. }
  10009. var i = 0;
  10010. while (i < recognizers.length) {
  10011. recognizer = recognizers[i];
  10012. // find out if we are allowed try to recognize the input for this one.
  10013. // 1. allow if the session is NOT forced stopped (see the .stop() method)
  10014. // 2. allow if we still haven't recognized a gesture in this session, or the this recognizer is the one
  10015. // that is being recognized.
  10016. // 3. allow if the recognizer is allowed to run simultaneous with the current recognized recognizer.
  10017. // this can be setup with the `recognizeWith()` method on the recognizer.
  10018. if (session.stopped !== FORCED_STOP && ( // 1
  10019. !curRecognizer || recognizer == curRecognizer || // 2
  10020. recognizer.canRecognizeWith(curRecognizer))) { // 3
  10021. recognizer.recognize(inputData);
  10022. } else {
  10023. recognizer.reset();
  10024. }
  10025. // if the recognizer has been recognizing the input as a valid gesture, we want to store this one as the
  10026. // current active recognizer. but only if we don't already have an active recognizer
  10027. if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
  10028. curRecognizer = session.curRecognizer = recognizer;
  10029. }
  10030. i++;
  10031. }
  10032. },
  10033. /**
  10034. * get a recognizer by its event name.
  10035. * @param {Recognizer|String} recognizer
  10036. * @returns {Recognizer|Null}
  10037. */
  10038. get: function(recognizer) {
  10039. if (recognizer instanceof Recognizer) {
  10040. return recognizer;
  10041. }
  10042. var recognizers = this.recognizers;
  10043. for (var i = 0; i < recognizers.length; i++) {
  10044. if (recognizers[i].options.event == recognizer) {
  10045. return recognizers[i];
  10046. }
  10047. }
  10048. return null;
  10049. },
  10050. /**
  10051. * add a recognizer to the manager
  10052. * existing recognizers with the same event name will be removed
  10053. * @param {Recognizer} recognizer
  10054. * @returns {Recognizer|Manager}
  10055. */
  10056. add: function(recognizer) {
  10057. if (invokeArrayArg(recognizer, 'add', this)) {
  10058. return this;
  10059. }
  10060. // remove existing
  10061. var existing = this.get(recognizer.options.event);
  10062. if (existing) {
  10063. this.remove(existing);
  10064. }
  10065. this.recognizers.push(recognizer);
  10066. recognizer.manager = this;
  10067. this.touchAction.update();
  10068. return recognizer;
  10069. },
  10070. /**
  10071. * remove a recognizer by name or instance
  10072. * @param {Recognizer|String} recognizer
  10073. * @returns {Manager}
  10074. */
  10075. remove: function(recognizer) {
  10076. if (invokeArrayArg(recognizer, 'remove', this)) {
  10077. return this;
  10078. }
  10079. var recognizers = this.recognizers;
  10080. recognizer = this.get(recognizer);
  10081. recognizers.splice(inArray(recognizers, recognizer), 1);
  10082. this.touchAction.update();
  10083. return this;
  10084. },
  10085. /**
  10086. * bind event
  10087. * @param {String} events
  10088. * @param {Function} handler
  10089. * @returns {EventEmitter} this
  10090. */
  10091. on: function(events, handler) {
  10092. var handlers = this.handlers;
  10093. each(splitStr(events), function(event) {
  10094. handlers[event] = handlers[event] || [];
  10095. handlers[event].push(handler);
  10096. });
  10097. return this;
  10098. },
  10099. /**
  10100. * unbind event, leave emit blank to remove all handlers
  10101. * @param {String} events
  10102. * @param {Function} [handler]
  10103. * @returns {EventEmitter} this
  10104. */
  10105. off: function(events, handler) {
  10106. var handlers = this.handlers;
  10107. each(splitStr(events), function(event) {
  10108. if (!handler) {
  10109. delete handlers[event];
  10110. } else {
  10111. handlers[event].splice(inArray(handlers[event], handler), 1);
  10112. }
  10113. });
  10114. return this;
  10115. },
  10116. /**
  10117. * emit event to the listeners
  10118. * @param {String} event
  10119. * @param {Object} data
  10120. */
  10121. emit: function(event, data) {
  10122. // we also want to trigger dom events
  10123. if (this.options.domEvents) {
  10124. triggerDomEvent(event, data);
  10125. }
  10126. // no handlers, so skip it all
  10127. var handlers = this.handlers[event] && this.handlers[event].slice();
  10128. if (!handlers || !handlers.length) {
  10129. return;
  10130. }
  10131. data.type = event;
  10132. data.preventDefault = function() {
  10133. data.srcEvent.preventDefault();
  10134. };
  10135. var i = 0;
  10136. while (i < handlers.length) {
  10137. handlers[i](data);
  10138. i++;
  10139. }
  10140. },
  10141. /**
  10142. * destroy the manager and unbinds all events
  10143. * it doesn't unbind dom events, that is the user own responsibility
  10144. */
  10145. destroy: function() {
  10146. this.element && toggleCssProps(this, false);
  10147. this.handlers = {};
  10148. this.session = {};
  10149. this.input.destroy();
  10150. this.element = null;
  10151. }
  10152. };
  10153. /**
  10154. * add/remove the css properties as defined in manager.options.cssProps
  10155. * @param {Manager} manager
  10156. * @param {Boolean} add
  10157. */
  10158. function toggleCssProps(manager, add) {
  10159. var element = manager.element;
  10160. each(manager.options.cssProps, function(value, name) {
  10161. element.style[prefixed(element.style, name)] = add ? value : '';
  10162. });
  10163. }
  10164. /**
  10165. * trigger dom event
  10166. * @param {String} event
  10167. * @param {Object} data
  10168. */
  10169. function triggerDomEvent(event, data) {
  10170. var gestureEvent = document.createEvent('Event');
  10171. gestureEvent.initEvent(event, true, true);
  10172. gestureEvent.gesture = data;
  10173. data.target.dispatchEvent(gestureEvent);
  10174. }
  10175. extend(Hammer, {
  10176. INPUT_START: INPUT_START,
  10177. INPUT_MOVE: INPUT_MOVE,
  10178. INPUT_END: INPUT_END,
  10179. INPUT_CANCEL: INPUT_CANCEL,
  10180. STATE_POSSIBLE: STATE_POSSIBLE,
  10181. STATE_BEGAN: STATE_BEGAN,
  10182. STATE_CHANGED: STATE_CHANGED,
  10183. STATE_ENDED: STATE_ENDED,
  10184. STATE_RECOGNIZED: STATE_RECOGNIZED,
  10185. STATE_CANCELLED: STATE_CANCELLED,
  10186. STATE_FAILED: STATE_FAILED,
  10187. DIRECTION_NONE: DIRECTION_NONE,
  10188. DIRECTION_LEFT: DIRECTION_LEFT,
  10189. DIRECTION_RIGHT: DIRECTION_RIGHT,
  10190. DIRECTION_UP: DIRECTION_UP,
  10191. DIRECTION_DOWN: DIRECTION_DOWN,
  10192. DIRECTION_HORIZONTAL: DIRECTION_HORIZONTAL,
  10193. DIRECTION_VERTICAL: DIRECTION_VERTICAL,
  10194. DIRECTION_ALL: DIRECTION_ALL,
  10195. Manager: Manager,
  10196. Input: Input,
  10197. TouchAction: TouchAction,
  10198. TouchInput: TouchInput,
  10199. MouseInput: MouseInput,
  10200. PointerEventInput: PointerEventInput,
  10201. TouchMouseInput: TouchMouseInput,
  10202. SingleTouchInput: SingleTouchInput,
  10203. Recognizer: Recognizer,
  10204. AttrRecognizer: AttrRecognizer,
  10205. Tap: TapRecognizer,
  10206. Pan: PanRecognizer,
  10207. Swipe: SwipeRecognizer,
  10208. Pinch: PinchRecognizer,
  10209. Rotate: RotateRecognizer,
  10210. Press: PressRecognizer,
  10211. on: addEventListeners,
  10212. off: removeEventListeners,
  10213. each: each,
  10214. merge: merge,
  10215. extend: extend,
  10216. inherit: inherit,
  10217. bindFn: bindFn,
  10218. prefixed: prefixed
  10219. });
  10220. // jquery.hammer.js
  10221. // This jQuery plugin is just a small wrapper around the Hammer() class.
  10222. // It also extends the Manager.emit method by triggering jQuery events.
  10223. // $(element).hammer(options).bind("pan", myPanHandler);
  10224. // The Hammer instance is stored at $element.data("hammer").
  10225. // https://github.com/hammerjs/jquery.hammer.js
  10226. (function($, Hammer) {
  10227. function hammerify(el, options) {
  10228. var $el = $(el);
  10229. if (!$el.data('hammer')) {
  10230. $el.data('hammer', new Hammer($el[0], options));
  10231. }
  10232. }
  10233. $.fn.hammer = function(options) {
  10234. return this.each(function() {
  10235. hammerify(this, options);
  10236. });
  10237. };
  10238. // extend the emit method to also trigger jQuery events
  10239. Hammer.Manager.prototype.emit = (function(originalEmit) {
  10240. return function(type, data) {
  10241. originalEmit.call(this, type, data);
  10242. $(this.element).trigger({
  10243. type: type,
  10244. gesture: data
  10245. });
  10246. };
  10247. })(Hammer.Manager.prototype.emit);
  10248. })($, Hammer);
  10249. $.AMUI.Hammer = Hammer;
  10250. module.exports = Hammer;
  10251. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  10252. },{"2":2}],31:[function(_dereq_,module,exports){
  10253. (function (global){
  10254. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  10255. _dereq_(2);
  10256. /**
  10257. * @ver 1.1.0
  10258. * @via https://github.com/aralejs/qrcode/blob/master/src/qrcode.js
  10259. * @license http://aralejs.org/
  10260. */
  10261. var qrcodeAlgObjCache = [];
  10262. /**
  10263. * 二维码构造函数,主要用于绘制
  10264. * @param {参数列表} opt 传递参数
  10265. * @return {}
  10266. */
  10267. var qrcode = function(opt) {
  10268. if (typeof opt === 'string') { // 只编码ASCII字符串
  10269. opt = {
  10270. text: opt
  10271. };
  10272. }
  10273. //设置默认参数
  10274. this.options = $.extend({}, {
  10275. text: "",
  10276. render: "",
  10277. width: 256,
  10278. height: 256,
  10279. correctLevel: 3,
  10280. background: "#ffffff",
  10281. foreground: "#000000"
  10282. }, opt);
  10283. //使用QRCodeAlg创建二维码结构
  10284. var qrCodeAlg = null;
  10285. for (var i = 0, l = qrcodeAlgObjCache.length; i < l; i++) {
  10286. if (qrcodeAlgObjCache[i].text == this.options.text && qrcodeAlgObjCache[i].text.correctLevel == this.options.correctLevel) {
  10287. qrCodeAlg = qrcodeAlgObjCache[i].obj;
  10288. break;
  10289. }
  10290. }
  10291. if (i == l) {
  10292. qrCodeAlg = new QRCodeAlg(this.options.text, this.options.correctLevel);
  10293. qrcodeAlgObjCache.push({
  10294. text: this.options.text,
  10295. correctLevel: this.options.correctLevel,
  10296. obj: qrCodeAlg
  10297. });
  10298. }
  10299. if (this.options.render) {
  10300. switch (this.options.render) {
  10301. case "canvas":
  10302. return this.createCanvas(qrCodeAlg);
  10303. case "table":
  10304. return this.createTable(qrCodeAlg);
  10305. case "svg":
  10306. return this.createSVG(qrCodeAlg);
  10307. default:
  10308. return this.createDefault(qrCodeAlg);
  10309. }
  10310. }
  10311. return this.createDefault(qrCodeAlg);
  10312. };
  10313. /**
  10314. * 使用Canvas来画二维码
  10315. * @return {}
  10316. */
  10317. qrcode.prototype.createDefault = function(qrCodeAlg) {
  10318. var canvas = document.createElement('canvas');
  10319. if (canvas.getContext)
  10320. return this.createCanvas(qrCodeAlg);
  10321. if (!!document.createElementNS && !!document.createElementNS(SVG_NS, 'svg').createSVGRect)
  10322. return this.createSVG(qrCodeAlg);
  10323. return this.createTable(qrCodeAlg);
  10324. };
  10325. qrcode.prototype.createCanvas = function(qrCodeAlg) {
  10326. //创建canvas节点
  10327. var canvas = document.createElement('canvas');
  10328. canvas.width = this.options.width;
  10329. canvas.height = this.options.height;
  10330. var ctx = canvas.getContext('2d');
  10331. //计算每个点的长宽
  10332. var tileW = (this.options.width / qrCodeAlg.getModuleCount()).toPrecision(4);
  10333. var tileH = this.options.height / qrCodeAlg.getModuleCount().toPrecision(4);
  10334. //绘制
  10335. for (var row = 0; row < qrCodeAlg.getModuleCount(); row++) {
  10336. for (var col = 0; col < qrCodeAlg.getModuleCount(); col++) {
  10337. ctx.fillStyle = qrCodeAlg.modules[row][col] ? this.options.foreground : this.options.background;
  10338. var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW));
  10339. var h = (Math.ceil((row + 1) * tileW) - Math.floor(row * tileW));
  10340. ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h);
  10341. }
  10342. }
  10343. //返回绘制的节点
  10344. return canvas;
  10345. };
  10346. /**
  10347. * 使用table来绘制二维码
  10348. * @return {}
  10349. */
  10350. qrcode.prototype.createTable = function(qrCodeAlg) {
  10351. //创建table节点
  10352. var s = [];
  10353. s.push('<table style="border:0px; margin:0px; padding:0px; border-collapse:collapse; background-color: ' +
  10354. this.options.background +
  10355. ';">');
  10356. // 计算每个节点的长宽;取整,防止点之间出现分离
  10357. var tileW = -1, tileH = -1, caculateW = -1, caculateH = -1;
  10358. tileW = caculateW = Math.floor(this.options.width / qrCodeAlg.getModuleCount());
  10359. tileH = caculateH = Math.floor(this.options.height / qrCodeAlg.getModuleCount());
  10360. if (caculateW <= 0) {
  10361. if (qrCodeAlg.getModuleCount() < 80) {
  10362. tileW = 2;
  10363. } else {
  10364. tileW = 1;
  10365. }
  10366. }
  10367. if (caculateH <= 0) {
  10368. if (qrCodeAlg.getModuleCount() < 80) {
  10369. tileH = 2;
  10370. } else {
  10371. tileH = 1;
  10372. }
  10373. }
  10374. // 绘制二维码
  10375. foreTd = '<td style="border:0px; margin:0px; padding:0px; width:' + tileW + 'px; background-color: ' + this.options.foreground + '"></td>',
  10376. backTd = '<td style="border:0px; margin:0px; padding:0px; width:' + tileW + 'px; background-color: ' + this.options.background + '"></td>',
  10377. l = qrCodeAlg.getModuleCount();
  10378. for (var row = 0; row < l; row++) {
  10379. s.push('<tr style="border:0px; margin:0px; padding:0px; height: ' + tileH + 'px">');
  10380. for (var col = 0; col < l; col++) {
  10381. s.push(qrCodeAlg.modules[row][col] ? foreTd : backTd);
  10382. }
  10383. s.push('</tr>');
  10384. }
  10385. s.push('</table>');
  10386. var span = document.createElement("span");
  10387. span.innerHTML = s.join('');
  10388. return span.firstChild;
  10389. };
  10390. /**
  10391. * 使用SVG开绘制二维码
  10392. * @return {}
  10393. */
  10394. qrcode.prototype.createSVG = function(qrCodeAlg) {
  10395. var x, dx, y, dy,
  10396. moduleCount = qrCodeAlg.getModuleCount(),
  10397. scale = this.options.height / this.options.width,
  10398. svg = '<svg xmlns="http://www.w3.org/2000/svg" '
  10399. + 'width="' + this.options.width + 'px" height="' + this.options.height + 'px" '
  10400. + 'viewbox="0 0 ' + moduleCount * 10 + ' ' + moduleCount * 10 * scale + '">',
  10401. rectHead = '<path ',
  10402. foreRect = ' style="stroke-width:0.5;stroke:' + this.options.foreground
  10403. + ';fill:' + this.options.foreground + ';"></path>',
  10404. backRect = ' style="stroke-width:0.5;stroke:' + this.options.background
  10405. + ';fill:' + this.options.background + ';"></path>';
  10406. // draw in the svg
  10407. for (var row = 0; row < moduleCount; row++) {
  10408. for (var col = 0; col < moduleCount; col++) {
  10409. x = col * 10;
  10410. y = row * 10 * scale;
  10411. dx = (col + 1) * 10;
  10412. dy = (row + 1) * 10 * scale;
  10413. svg += rectHead + 'd="M ' + x + ',' + y
  10414. + ' L ' + dx + ',' + y
  10415. + ' L ' + dx + ',' + dy
  10416. + ' L ' + x + ',' + dy
  10417. + ' Z"';
  10418. svg += qrCodeAlg.modules[row][col] ? foreRect : backRect;
  10419. }
  10420. }
  10421. svg += '</svg>';
  10422. // return just built svg
  10423. return $(svg)[0];
  10424. };
  10425. /**
  10426. * 获取单个字符的utf8编码
  10427. * unicode BMP平面约65535个字符
  10428. * @param {num} code
  10429. * return {array}
  10430. */
  10431. function unicodeFormat8(code) {
  10432. // 1 byte
  10433. if (code < 128) {
  10434. return [code];
  10435. // 2 bytes
  10436. } else if (code < 2048) {
  10437. c0 = 192 + (code >> 6);
  10438. c1 = 128 + (code & 63);
  10439. return [c0, c1];
  10440. // 3 bytes
  10441. } else {
  10442. c0 = 224 + (code >> 12);
  10443. c1 = 128 + (code >> 6 & 63);
  10444. c2 = 128 + (code & 63);
  10445. return [c0, c1, c2];
  10446. }
  10447. }
  10448. /**
  10449. * 获取字符串的utf8编码字节串
  10450. * @param {string} string
  10451. * @return {array}
  10452. */
  10453. function getUTF8Bytes(string) {
  10454. var utf8codes = [];
  10455. for (var i = 0; i < string.length; i++) {
  10456. var code = string.charCodeAt(i);
  10457. var utf8 = unicodeFormat8(code);
  10458. for (var j = 0; j < utf8.length; j++) {
  10459. utf8codes.push(utf8[j]);
  10460. }
  10461. }
  10462. return utf8codes;
  10463. }
  10464. /**
  10465. * 二维码算法实现
  10466. * @param {string} data 要编码的信息字符串
  10467. * @param {num} errorCorrectLevel 纠错等级
  10468. */
  10469. function QRCodeAlg(data, errorCorrectLevel) {
  10470. this.typeNumber = -1; //版本
  10471. this.errorCorrectLevel = errorCorrectLevel;
  10472. this.modules = null; //二维矩阵,存放最终结果
  10473. this.moduleCount = 0; //矩阵大小
  10474. this.dataCache = null; //数据缓存
  10475. this.rsBlocks = null; //版本数据信息
  10476. this.totalDataCount = -1; //可使用的数据量
  10477. this.data = data;
  10478. this.utf8bytes = getUTF8Bytes(data);
  10479. this.make();
  10480. }
  10481. QRCodeAlg.prototype = {
  10482. constructor: QRCodeAlg,
  10483. /**
  10484. * 获取二维码矩阵大小
  10485. * @return {num} 矩阵大小
  10486. */
  10487. getModuleCount: function() {
  10488. return this.moduleCount;
  10489. },
  10490. /**
  10491. * 编码
  10492. */
  10493. make: function() {
  10494. this.getRightType();
  10495. this.dataCache = this.createData();
  10496. this.createQrcode();
  10497. },
  10498. /**
  10499. * 设置二位矩阵功能图形
  10500. * @param {bool} test 表示是否在寻找最好掩膜阶段
  10501. * @param {num} maskPattern 掩膜的版本
  10502. */
  10503. makeImpl: function(maskPattern) {
  10504. this.moduleCount = this.typeNumber * 4 + 17;
  10505. this.modules = new Array(this.moduleCount);
  10506. for (var row = 0; row < this.moduleCount; row++) {
  10507. this.modules[row] = new Array(this.moduleCount);
  10508. }
  10509. this.setupPositionProbePattern(0, 0);
  10510. this.setupPositionProbePattern(this.moduleCount - 7, 0);
  10511. this.setupPositionProbePattern(0, this.moduleCount - 7);
  10512. this.setupPositionAdjustPattern();
  10513. this.setupTimingPattern();
  10514. this.setupTypeInfo(true, maskPattern);
  10515. if (this.typeNumber >= 7) {
  10516. this.setupTypeNumber(true);
  10517. }
  10518. this.mapData(this.dataCache, maskPattern);
  10519. },
  10520. /**
  10521. * 设置二维码的位置探测图形
  10522. * @param {num} row 探测图形的中心横坐标
  10523. * @param {num} col 探测图形的中心纵坐标
  10524. */
  10525. setupPositionProbePattern: function(row, col) {
  10526. for (var r = -1; r <= 7; r++) {
  10527. if (row + r <= -1 || this.moduleCount <= row + r) continue;
  10528. for (var c = -1; c <= 7; c++) {
  10529. if (col + c <= -1 || this.moduleCount <= col + c) continue;
  10530. if ((0 <= r && r <= 6 && (c == 0 || c == 6)) || (0 <= c && c <= 6 && (r == 0 || r == 6)) || (2 <= r && r <= 4 && 2 <= c && c <= 4)) {
  10531. this.modules[row + r][col + c] = true;
  10532. } else {
  10533. this.modules[row + r][col + c] = false;
  10534. }
  10535. }
  10536. }
  10537. },
  10538. /**
  10539. * 创建二维码
  10540. * @return {[type]} [description]
  10541. */
  10542. createQrcode: function() {
  10543. var minLostPoint = 0;
  10544. var pattern = 0;
  10545. var bestModules = null;
  10546. for (var i = 0; i < 8; i++) {
  10547. this.makeImpl(i);
  10548. var lostPoint = QRUtil.getLostPoint(this);
  10549. if (i == 0 || minLostPoint > lostPoint) {
  10550. minLostPoint = lostPoint;
  10551. pattern = i;
  10552. bestModules = this.modules;
  10553. }
  10554. }
  10555. this.modules = bestModules;
  10556. this.setupTypeInfo(false, pattern);
  10557. if (this.typeNumber >= 7) {
  10558. this.setupTypeNumber(false);
  10559. }
  10560. },
  10561. /**
  10562. * 设置定位图形
  10563. * @return {[type]} [description]
  10564. */
  10565. setupTimingPattern: function() {
  10566. for (var r = 8; r < this.moduleCount - 8; r++) {
  10567. if (this.modules[r][6] != null) {
  10568. continue;
  10569. }
  10570. this.modules[r][6] = (r % 2 == 0);
  10571. if (this.modules[6][r] != null) {
  10572. continue;
  10573. }
  10574. this.modules[6][r] = (r % 2 == 0);
  10575. }
  10576. },
  10577. /**
  10578. * 设置矫正图形
  10579. * @return {[type]} [description]
  10580. */
  10581. setupPositionAdjustPattern: function() {
  10582. var pos = QRUtil.getPatternPosition(this.typeNumber);
  10583. for (var i = 0; i < pos.length; i++) {
  10584. for (var j = 0; j < pos.length; j++) {
  10585. var row = pos[i];
  10586. var col = pos[j];
  10587. if (this.modules[row][col] != null) {
  10588. continue;
  10589. }
  10590. for (var r = -2; r <= 2; r++) {
  10591. for (var c = -2; c <= 2; c++) {
  10592. if (r == -2 || r == 2 || c == -2 || c == 2 || (r == 0 && c == 0)) {
  10593. this.modules[row + r][col + c] = true;
  10594. } else {
  10595. this.modules[row + r][col + c] = false;
  10596. }
  10597. }
  10598. }
  10599. }
  10600. }
  10601. },
  10602. /**
  10603. * 设置版本信息(7以上版本才有)
  10604. * @param {bool} test 是否处于判断最佳掩膜阶段
  10605. * @return {[type]} [description]
  10606. */
  10607. setupTypeNumber: function(test) {
  10608. var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
  10609. for (var i = 0; i < 18; i++) {
  10610. var mod = (!test && ((bits >> i) & 1) == 1);
  10611. this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
  10612. this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
  10613. }
  10614. },
  10615. /**
  10616. * 设置格式信息(纠错等级和掩膜版本)
  10617. * @param {bool} test
  10618. * @param {num} maskPattern 掩膜版本
  10619. * @return {}
  10620. */
  10621. setupTypeInfo: function(test, maskPattern) {
  10622. var data = (QRErrorCorrectLevel[this.errorCorrectLevel] << 3) | maskPattern;
  10623. var bits = QRUtil.getBCHTypeInfo(data);
  10624. // vertical
  10625. for (var i = 0; i < 15; i++) {
  10626. var mod = (!test && ((bits >> i) & 1) == 1);
  10627. if (i < 6) {
  10628. this.modules[i][8] = mod;
  10629. } else if (i < 8) {
  10630. this.modules[i + 1][8] = mod;
  10631. } else {
  10632. this.modules[this.moduleCount - 15 + i][8] = mod;
  10633. }
  10634. // horizontal
  10635. var mod = (!test && ((bits >> i) & 1) == 1);
  10636. if (i < 8) {
  10637. this.modules[8][this.moduleCount - i - 1] = mod;
  10638. } else if (i < 9) {
  10639. this.modules[8][15 - i - 1 + 1] = mod;
  10640. } else {
  10641. this.modules[8][15 - i - 1] = mod;
  10642. }
  10643. }
  10644. // fixed module
  10645. this.modules[this.moduleCount - 8][8] = (!test);
  10646. },
  10647. /**
  10648. * 数据编码
  10649. * @return {[type]} [description]
  10650. */
  10651. createData: function() {
  10652. var buffer = new QRBitBuffer();
  10653. var lengthBits = this.typeNumber > 9 ? 16 : 8;
  10654. buffer.put(4, 4); //添加模式
  10655. buffer.put(this.utf8bytes.length, lengthBits);
  10656. for (var i = 0, l = this.utf8bytes.length; i < l; i++) {
  10657. buffer.put(this.utf8bytes[i], 8);
  10658. }
  10659. if (buffer.length + 4 <= this.totalDataCount * 8) {
  10660. buffer.put(0, 4);
  10661. }
  10662. // padding
  10663. while (buffer.length % 8 != 0) {
  10664. buffer.putBit(false);
  10665. }
  10666. // padding
  10667. while (true) {
  10668. if (buffer.length >= this.totalDataCount * 8) {
  10669. break;
  10670. }
  10671. buffer.put(QRCodeAlg.PAD0, 8);
  10672. if (buffer.length >= this.totalDataCount * 8) {
  10673. break;
  10674. }
  10675. buffer.put(QRCodeAlg.PAD1, 8);
  10676. }
  10677. return this.createBytes(buffer);
  10678. },
  10679. /**
  10680. * 纠错码编码
  10681. * @param {buffer} buffer 数据编码
  10682. * @return {[type]}
  10683. */
  10684. createBytes: function(buffer) {
  10685. var offset = 0;
  10686. var maxDcCount = 0;
  10687. var maxEcCount = 0;
  10688. var length = this.rsBlock.length / 3;
  10689. var rsBlocks = new Array();
  10690. for (var i = 0; i < length; i++) {
  10691. var count = this.rsBlock[i * 3 + 0];
  10692. var totalCount = this.rsBlock[i * 3 + 1];
  10693. var dataCount = this.rsBlock[i * 3 + 2];
  10694. for (var j = 0; j < count; j++) {
  10695. rsBlocks.push([dataCount, totalCount]);
  10696. }
  10697. }
  10698. var dcdata = new Array(rsBlocks.length);
  10699. var ecdata = new Array(rsBlocks.length);
  10700. for (var r = 0; r < rsBlocks.length; r++) {
  10701. var dcCount = rsBlocks[r][0];
  10702. var ecCount = rsBlocks[r][1] - dcCount;
  10703. maxDcCount = Math.max(maxDcCount, dcCount);
  10704. maxEcCount = Math.max(maxEcCount, ecCount);
  10705. dcdata[r] = new Array(dcCount);
  10706. for (var i = 0; i < dcdata[r].length; i++) {
  10707. dcdata[r][i] = 0xff & buffer.buffer[i + offset];
  10708. }
  10709. offset += dcCount;
  10710. var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
  10711. var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
  10712. var modPoly = rawPoly.mod(rsPoly);
  10713. ecdata[r] = new Array(rsPoly.getLength() - 1);
  10714. for (var i = 0; i < ecdata[r].length; i++) {
  10715. var modIndex = i + modPoly.getLength() - ecdata[r].length;
  10716. ecdata[r][i] = (modIndex >= 0) ? modPoly.get(modIndex) : 0;
  10717. }
  10718. }
  10719. var data = new Array(this.totalDataCount);
  10720. var index = 0;
  10721. for (var i = 0; i < maxDcCount; i++) {
  10722. for (var r = 0; r < rsBlocks.length; r++) {
  10723. if (i < dcdata[r].length) {
  10724. data[index++] = dcdata[r][i];
  10725. }
  10726. }
  10727. }
  10728. for (var i = 0; i < maxEcCount; i++) {
  10729. for (var r = 0; r < rsBlocks.length; r++) {
  10730. if (i < ecdata[r].length) {
  10731. data[index++] = ecdata[r][i];
  10732. }
  10733. }
  10734. }
  10735. return data;
  10736. },
  10737. /**
  10738. * 布置模块,构建最终信息
  10739. * @param {} data
  10740. * @param {} maskPattern
  10741. * @return {}
  10742. */
  10743. mapData: function(data, maskPattern) {
  10744. var inc = -1;
  10745. var row = this.moduleCount - 1;
  10746. var bitIndex = 7;
  10747. var byteIndex = 0;
  10748. for (var col = this.moduleCount - 1; col > 0; col -= 2) {
  10749. if (col == 6) col--;
  10750. while (true) {
  10751. for (var c = 0; c < 2; c++) {
  10752. if (this.modules[row][col - c] == null) {
  10753. var dark = false;
  10754. if (byteIndex < data.length) {
  10755. dark = (((data[byteIndex] >>> bitIndex) & 1) == 1);
  10756. }
  10757. var mask = QRUtil.getMask(maskPattern, row, col - c);
  10758. if (mask) {
  10759. dark = !dark;
  10760. }
  10761. this.modules[row][col - c] = dark;
  10762. bitIndex--;
  10763. if (bitIndex == -1) {
  10764. byteIndex++;
  10765. bitIndex = 7;
  10766. }
  10767. }
  10768. }
  10769. row += inc;
  10770. if (row < 0 || this.moduleCount <= row) {
  10771. row -= inc;
  10772. inc = -inc;
  10773. break;
  10774. }
  10775. }
  10776. }
  10777. }
  10778. };
  10779. /**
  10780. * 填充字段
  10781. */
  10782. QRCodeAlg.PAD0 = 0xEC;
  10783. QRCodeAlg.PAD1 = 0x11;
  10784. //---------------------------------------------------------------------
  10785. // 纠错等级对应的编码
  10786. //---------------------------------------------------------------------
  10787. var QRErrorCorrectLevel = [1, 0, 3, 2];
  10788. //---------------------------------------------------------------------
  10789. // 掩膜版本
  10790. //---------------------------------------------------------------------
  10791. var QRMaskPattern = {
  10792. PATTERN000: 0,
  10793. PATTERN001: 1,
  10794. PATTERN010: 2,
  10795. PATTERN011: 3,
  10796. PATTERN100: 4,
  10797. PATTERN101: 5,
  10798. PATTERN110: 6,
  10799. PATTERN111: 7
  10800. };
  10801. //---------------------------------------------------------------------
  10802. // 工具类
  10803. //---------------------------------------------------------------------
  10804. var QRUtil = {
  10805. /*
  10806. 每个版本矫正图形的位置
  10807. */
  10808. PATTERN_POSITION_TABLE: [
  10809. [],
  10810. [6, 18],
  10811. [6, 22],
  10812. [6, 26],
  10813. [6, 30],
  10814. [6, 34],
  10815. [6, 22, 38],
  10816. [6, 24, 42],
  10817. [6, 26, 46],
  10818. [6, 28, 50],
  10819. [6, 30, 54],
  10820. [6, 32, 58],
  10821. [6, 34, 62],
  10822. [6, 26, 46, 66],
  10823. [6, 26, 48, 70],
  10824. [6, 26, 50, 74],
  10825. [6, 30, 54, 78],
  10826. [6, 30, 56, 82],
  10827. [6, 30, 58, 86],
  10828. [6, 34, 62, 90],
  10829. [6, 28, 50, 72, 94],
  10830. [6, 26, 50, 74, 98],
  10831. [6, 30, 54, 78, 102],
  10832. [6, 28, 54, 80, 106],
  10833. [6, 32, 58, 84, 110],
  10834. [6, 30, 58, 86, 114],
  10835. [6, 34, 62, 90, 118],
  10836. [6, 26, 50, 74, 98, 122],
  10837. [6, 30, 54, 78, 102, 126],
  10838. [6, 26, 52, 78, 104, 130],
  10839. [6, 30, 56, 82, 108, 134],
  10840. [6, 34, 60, 86, 112, 138],
  10841. [6, 30, 58, 86, 114, 142],
  10842. [6, 34, 62, 90, 118, 146],
  10843. [6, 30, 54, 78, 102, 126, 150],
  10844. [6, 24, 50, 76, 102, 128, 154],
  10845. [6, 28, 54, 80, 106, 132, 158],
  10846. [6, 32, 58, 84, 110, 136, 162],
  10847. [6, 26, 54, 82, 110, 138, 166],
  10848. [6, 30, 58, 86, 114, 142, 170]
  10849. ],
  10850. G15: (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0),
  10851. G18: (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0),
  10852. G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
  10853. /*
  10854. BCH编码格式信息
  10855. */
  10856. getBCHTypeInfo: function(data) {
  10857. var d = data << 10;
  10858. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
  10859. d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15)));
  10860. }
  10861. return ((data << 10) | d) ^ QRUtil.G15_MASK;
  10862. },
  10863. /*
  10864. BCH编码版本信息
  10865. */
  10866. getBCHTypeNumber: function(data) {
  10867. var d = data << 12;
  10868. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
  10869. d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18)));
  10870. }
  10871. return (data << 12) | d;
  10872. },
  10873. /*
  10874. 获取BCH位信息
  10875. */
  10876. getBCHDigit: function(data) {
  10877. var digit = 0;
  10878. while (data != 0) {
  10879. digit++;
  10880. data >>>= 1;
  10881. }
  10882. return digit;
  10883. },
  10884. /*
  10885. 获取版本对应的矫正图形位置
  10886. */
  10887. getPatternPosition: function(typeNumber) {
  10888. return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
  10889. },
  10890. /*
  10891. 掩膜算法
  10892. */
  10893. getMask: function(maskPattern, i, j) {
  10894. switch (maskPattern) {
  10895. case QRMaskPattern.PATTERN000:
  10896. return (i + j) % 2 == 0;
  10897. case QRMaskPattern.PATTERN001:
  10898. return i % 2 == 0;
  10899. case QRMaskPattern.PATTERN010:
  10900. return j % 3 == 0;
  10901. case QRMaskPattern.PATTERN011:
  10902. return (i + j) % 3 == 0;
  10903. case QRMaskPattern.PATTERN100:
  10904. return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
  10905. case QRMaskPattern.PATTERN101:
  10906. return (i * j) % 2 + (i * j) % 3 == 0;
  10907. case QRMaskPattern.PATTERN110:
  10908. return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
  10909. case QRMaskPattern.PATTERN111:
  10910. return ((i * j) % 3 + (i + j) % 2) % 2 == 0;
  10911. default:
  10912. throw new Error("bad maskPattern:" + maskPattern);
  10913. }
  10914. },
  10915. /*
  10916. 获取RS的纠错多项式
  10917. */
  10918. getErrorCorrectPolynomial: function(errorCorrectLength) {
  10919. var a = new QRPolynomial([1], 0);
  10920. for (var i = 0; i < errorCorrectLength; i++) {
  10921. a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
  10922. }
  10923. return a;
  10924. },
  10925. /*
  10926. 获取评价
  10927. */
  10928. getLostPoint: function(qrCode) {
  10929. var moduleCount = qrCode.getModuleCount(),
  10930. lostPoint = 0,
  10931. darkCount = 0;
  10932. for (var row = 0; row < moduleCount; row++) {
  10933. var sameCount = 0;
  10934. var head = qrCode.modules[row][0];
  10935. for (var col = 0; col < moduleCount; col++) {
  10936. var current = qrCode.modules[row][col];
  10937. //level 3 评价
  10938. if (col < moduleCount - 6) {
  10939. if (current && !qrCode.modules[row][col + 1] && qrCode.modules[row][col + 2] && qrCode.modules[row][col + 3] && qrCode.modules[row][col + 4] && !qrCode.modules[row][col + 5] && qrCode.modules[row][col + 6]) {
  10940. if (col < moduleCount - 10) {
  10941. if (qrCode.modules[row][col + 7] && qrCode.modules[row][col + 8] && qrCode.modules[row][col + 9] && qrCode.modules[row][col + 10]) {
  10942. lostPoint += 40;
  10943. }
  10944. } else if (col > 3) {
  10945. if (qrCode.modules[row][col - 1] && qrCode.modules[row][col - 2] && qrCode.modules[row][col - 3] && qrCode.modules[row][col - 4]) {
  10946. lostPoint += 40;
  10947. }
  10948. }
  10949. }
  10950. }
  10951. //level 2 评价
  10952. if ((row < moduleCount - 1) && (col < moduleCount - 1)) {
  10953. var count = 0;
  10954. if (current) count++;
  10955. if (qrCode.modules[row + 1][col]) count++;
  10956. if (qrCode.modules[row][col + 1]) count++;
  10957. if (qrCode.modules[row + 1][col + 1]) count++;
  10958. if (count == 0 || count == 4) {
  10959. lostPoint += 3;
  10960. }
  10961. }
  10962. //level 1 评价
  10963. if (head ^ current) {
  10964. sameCount++;
  10965. } else {
  10966. head = current;
  10967. if (sameCount >= 5) {
  10968. lostPoint += (3 + sameCount - 5);
  10969. }
  10970. sameCount = 1;
  10971. }
  10972. //level 4 评价
  10973. if (current) {
  10974. darkCount++;
  10975. }
  10976. }
  10977. }
  10978. for (var col = 0; col < moduleCount; col++) {
  10979. var sameCount = 0;
  10980. var head = qrCode.modules[0][col];
  10981. for (var row = 0; row < moduleCount; row++) {
  10982. var current = qrCode.modules[row][col];
  10983. //level 3 评价
  10984. if (row < moduleCount - 6) {
  10985. if (current && !qrCode.modules[row + 1][col] && qrCode.modules[row + 2][col] && qrCode.modules[row + 3][col] && qrCode.modules[row + 4][col] && !qrCode.modules[row + 5][col] && qrCode.modules[row + 6][col]) {
  10986. if (row < moduleCount - 10) {
  10987. if (qrCode.modules[row + 7][col] && qrCode.modules[row + 8][col] && qrCode.modules[row + 9][col] && qrCode.modules[row + 10][col]) {
  10988. lostPoint += 40;
  10989. }
  10990. } else if (row > 3) {
  10991. if (qrCode.modules[row - 1][col] && qrCode.modules[row - 2][col] && qrCode.modules[row - 3][col] && qrCode.modules[row - 4][col]) {
  10992. lostPoint += 40;
  10993. }
  10994. }
  10995. }
  10996. }
  10997. //level 1 评价
  10998. if (head ^ current) {
  10999. sameCount++;
  11000. } else {
  11001. head = current;
  11002. if (sameCount >= 5) {
  11003. lostPoint += (3 + sameCount - 5);
  11004. }
  11005. sameCount = 1;
  11006. }
  11007. }
  11008. }
  11009. // LEVEL4
  11010. var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
  11011. lostPoint += ratio * 10;
  11012. return lostPoint;
  11013. }
  11014. };
  11015. //---------------------------------------------------------------------
  11016. // QRMath使用的数学工具
  11017. //---------------------------------------------------------------------
  11018. var QRMath = {
  11019. /*
  11020. 将n转化为a^m
  11021. */
  11022. glog: function(n) {
  11023. if (n < 1) {
  11024. throw new Error("glog(" + n + ")");
  11025. }
  11026. return QRMath.LOG_TABLE[n];
  11027. },
  11028. /*
  11029. 将a^m转化为n
  11030. */
  11031. gexp: function(n) {
  11032. while (n < 0) {
  11033. n += 255;
  11034. }
  11035. while (n >= 256) {
  11036. n -= 255;
  11037. }
  11038. return QRMath.EXP_TABLE[n];
  11039. },
  11040. EXP_TABLE: new Array(256),
  11041. LOG_TABLE: new Array(256)
  11042. };
  11043. for (var i = 0; i < 8; i++) {
  11044. QRMath.EXP_TABLE[i] = 1 << i;
  11045. }
  11046. for (var i = 8; i < 256; i++) {
  11047. QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
  11048. }
  11049. for (var i = 0; i < 255; i++) {
  11050. QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
  11051. }
  11052. //---------------------------------------------------------------------
  11053. // QRPolynomial 多项式
  11054. //---------------------------------------------------------------------
  11055. /**
  11056. * 多项式类
  11057. * @param {Array} num 系数
  11058. * @param {num} shift a^shift
  11059. */
  11060. function QRPolynomial(num, shift) {
  11061. if (num.length == undefined) {
  11062. throw new Error(num.length + "/" + shift);
  11063. }
  11064. var offset = 0;
  11065. while (offset < num.length && num[offset] == 0) {
  11066. offset++;
  11067. }
  11068. this.num = new Array(num.length - offset + shift);
  11069. for (var i = 0; i < num.length - offset; i++) {
  11070. this.num[i] = num[i + offset];
  11071. }
  11072. }
  11073. QRPolynomial.prototype = {
  11074. get: function(index) {
  11075. return this.num[index];
  11076. },
  11077. getLength: function() {
  11078. return this.num.length;
  11079. },
  11080. /**
  11081. * 多项式乘法
  11082. * @param {QRPolynomial} e 被乘多项式
  11083. * @return {[type]} [description]
  11084. */
  11085. multiply: function(e) {
  11086. var num = new Array(this.getLength() + e.getLength() - 1);
  11087. for (var i = 0; i < this.getLength(); i++) {
  11088. for (var j = 0; j < e.getLength(); j++) {
  11089. num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
  11090. }
  11091. }
  11092. return new QRPolynomial(num, 0);
  11093. },
  11094. /**
  11095. * 多项式模运算
  11096. * @param {QRPolynomial} e 模多项式
  11097. * @return {}
  11098. */
  11099. mod: function(e) {
  11100. var tl = this.getLength(),
  11101. el = e.getLength();
  11102. if (tl - el < 0) {
  11103. return this;
  11104. }
  11105. var num = new Array(tl);
  11106. for (var i = 0; i < tl; i++) {
  11107. num[i] = this.get(i);
  11108. }
  11109. while (num.length >= el) {
  11110. var ratio = QRMath.glog(num[0]) - QRMath.glog(e.get(0));
  11111. for (var i = 0; i < e.getLength(); i++) {
  11112. num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio);
  11113. }
  11114. while (num[0] == 0) {
  11115. num.shift();
  11116. }
  11117. }
  11118. return new QRPolynomial(num, 0);
  11119. }
  11120. };
  11121. //---------------------------------------------------------------------
  11122. // RS_BLOCK_TABLE
  11123. //---------------------------------------------------------------------
  11124. /*
  11125. 二维码各个版本信息[块数, 每块中的数据块数, 每块中的信息块数]
  11126. */
  11127. var RS_BLOCK_TABLE = [
  11128. // L
  11129. // M
  11130. // Q
  11131. // H
  11132. // 1
  11133. [1, 26, 19],
  11134. [1, 26, 16],
  11135. [1, 26, 13],
  11136. [1, 26, 9],
  11137. // 2
  11138. [1, 44, 34],
  11139. [1, 44, 28],
  11140. [1, 44, 22],
  11141. [1, 44, 16],
  11142. // 3
  11143. [1, 70, 55],
  11144. [1, 70, 44],
  11145. [2, 35, 17],
  11146. [2, 35, 13],
  11147. // 4
  11148. [1, 100, 80],
  11149. [2, 50, 32],
  11150. [2, 50, 24],
  11151. [4, 25, 9],
  11152. // 5
  11153. [1, 134, 108],
  11154. [2, 67, 43],
  11155. [2, 33, 15, 2, 34, 16],
  11156. [2, 33, 11, 2, 34, 12],
  11157. // 6
  11158. [2, 86, 68],
  11159. [4, 43, 27],
  11160. [4, 43, 19],
  11161. [4, 43, 15],
  11162. // 7
  11163. [2, 98, 78],
  11164. [4, 49, 31],
  11165. [2, 32, 14, 4, 33, 15],
  11166. [4, 39, 13, 1, 40, 14],
  11167. // 8
  11168. [2, 121, 97],
  11169. [2, 60, 38, 2, 61, 39],
  11170. [4, 40, 18, 2, 41, 19],
  11171. [4, 40, 14, 2, 41, 15],
  11172. // 9
  11173. [2, 146, 116],
  11174. [3, 58, 36, 2, 59, 37],
  11175. [4, 36, 16, 4, 37, 17],
  11176. [4, 36, 12, 4, 37, 13],
  11177. // 10
  11178. [2, 86, 68, 2, 87, 69],
  11179. [4, 69, 43, 1, 70, 44],
  11180. [6, 43, 19, 2, 44, 20],
  11181. [6, 43, 15, 2, 44, 16],
  11182. // 11
  11183. [4, 101, 81],
  11184. [1, 80, 50, 4, 81, 51],
  11185. [4, 50, 22, 4, 51, 23],
  11186. [3, 36, 12, 8, 37, 13],
  11187. // 12
  11188. [2, 116, 92, 2, 117, 93],
  11189. [6, 58, 36, 2, 59, 37],
  11190. [4, 46, 20, 6, 47, 21],
  11191. [7, 42, 14, 4, 43, 15],
  11192. // 13
  11193. [4, 133, 107],
  11194. [8, 59, 37, 1, 60, 38],
  11195. [8, 44, 20, 4, 45, 21],
  11196. [12, 33, 11, 4, 34, 12],
  11197. // 14
  11198. [3, 145, 115, 1, 146, 116],
  11199. [4, 64, 40, 5, 65, 41],
  11200. [11, 36, 16, 5, 37, 17],
  11201. [11, 36, 12, 5, 37, 13],
  11202. // 15
  11203. [5, 109, 87, 1, 110, 88],
  11204. [5, 65, 41, 5, 66, 42],
  11205. [5, 54, 24, 7, 55, 25],
  11206. [11, 36, 12],
  11207. // 16
  11208. [5, 122, 98, 1, 123, 99],
  11209. [7, 73, 45, 3, 74, 46],
  11210. [15, 43, 19, 2, 44, 20],
  11211. [3, 45, 15, 13, 46, 16],
  11212. // 17
  11213. [1, 135, 107, 5, 136, 108],
  11214. [10, 74, 46, 1, 75, 47],
  11215. [1, 50, 22, 15, 51, 23],
  11216. [2, 42, 14, 17, 43, 15],
  11217. // 18
  11218. [5, 150, 120, 1, 151, 121],
  11219. [9, 69, 43, 4, 70, 44],
  11220. [17, 50, 22, 1, 51, 23],
  11221. [2, 42, 14, 19, 43, 15],
  11222. // 19
  11223. [3, 141, 113, 4, 142, 114],
  11224. [3, 70, 44, 11, 71, 45],
  11225. [17, 47, 21, 4, 48, 22],
  11226. [9, 39, 13, 16, 40, 14],
  11227. // 20
  11228. [3, 135, 107, 5, 136, 108],
  11229. [3, 67, 41, 13, 68, 42],
  11230. [15, 54, 24, 5, 55, 25],
  11231. [15, 43, 15, 10, 44, 16],
  11232. // 21
  11233. [4, 144, 116, 4, 145, 117],
  11234. [17, 68, 42],
  11235. [17, 50, 22, 6, 51, 23],
  11236. [19, 46, 16, 6, 47, 17],
  11237. // 22
  11238. [2, 139, 111, 7, 140, 112],
  11239. [17, 74, 46],
  11240. [7, 54, 24, 16, 55, 25],
  11241. [34, 37, 13],
  11242. // 23
  11243. [4, 151, 121, 5, 152, 122],
  11244. [4, 75, 47, 14, 76, 48],
  11245. [11, 54, 24, 14, 55, 25],
  11246. [16, 45, 15, 14, 46, 16],
  11247. // 24
  11248. [6, 147, 117, 4, 148, 118],
  11249. [6, 73, 45, 14, 74, 46],
  11250. [11, 54, 24, 16, 55, 25],
  11251. [30, 46, 16, 2, 47, 17],
  11252. // 25
  11253. [8, 132, 106, 4, 133, 107],
  11254. [8, 75, 47, 13, 76, 48],
  11255. [7, 54, 24, 22, 55, 25],
  11256. [22, 45, 15, 13, 46, 16],
  11257. // 26
  11258. [10, 142, 114, 2, 143, 115],
  11259. [19, 74, 46, 4, 75, 47],
  11260. [28, 50, 22, 6, 51, 23],
  11261. [33, 46, 16, 4, 47, 17],
  11262. // 27
  11263. [8, 152, 122, 4, 153, 123],
  11264. [22, 73, 45, 3, 74, 46],
  11265. [8, 53, 23, 26, 54, 24],
  11266. [12, 45, 15, 28, 46, 16],
  11267. // 28
  11268. [3, 147, 117, 10, 148, 118],
  11269. [3, 73, 45, 23, 74, 46],
  11270. [4, 54, 24, 31, 55, 25],
  11271. [11, 45, 15, 31, 46, 16],
  11272. // 29
  11273. [7, 146, 116, 7, 147, 117],
  11274. [21, 73, 45, 7, 74, 46],
  11275. [1, 53, 23, 37, 54, 24],
  11276. [19, 45, 15, 26, 46, 16],
  11277. // 30
  11278. [5, 145, 115, 10, 146, 116],
  11279. [19, 75, 47, 10, 76, 48],
  11280. [15, 54, 24, 25, 55, 25],
  11281. [23, 45, 15, 25, 46, 16],
  11282. // 31
  11283. [13, 145, 115, 3, 146, 116],
  11284. [2, 74, 46, 29, 75, 47],
  11285. [42, 54, 24, 1, 55, 25],
  11286. [23, 45, 15, 28, 46, 16],
  11287. // 32
  11288. [17, 145, 115],
  11289. [10, 74, 46, 23, 75, 47],
  11290. [10, 54, 24, 35, 55, 25],
  11291. [19, 45, 15, 35, 46, 16],
  11292. // 33
  11293. [17, 145, 115, 1, 146, 116],
  11294. [14, 74, 46, 21, 75, 47],
  11295. [29, 54, 24, 19, 55, 25],
  11296. [11, 45, 15, 46, 46, 16],
  11297. // 34
  11298. [13, 145, 115, 6, 146, 116],
  11299. [14, 74, 46, 23, 75, 47],
  11300. [44, 54, 24, 7, 55, 25],
  11301. [59, 46, 16, 1, 47, 17],
  11302. // 35
  11303. [12, 151, 121, 7, 152, 122],
  11304. [12, 75, 47, 26, 76, 48],
  11305. [39, 54, 24, 14, 55, 25],
  11306. [22, 45, 15, 41, 46, 16],
  11307. // 36
  11308. [6, 151, 121, 14, 152, 122],
  11309. [6, 75, 47, 34, 76, 48],
  11310. [46, 54, 24, 10, 55, 25],
  11311. [2, 45, 15, 64, 46, 16],
  11312. // 37
  11313. [17, 152, 122, 4, 153, 123],
  11314. [29, 74, 46, 14, 75, 47],
  11315. [49, 54, 24, 10, 55, 25],
  11316. [24, 45, 15, 46, 46, 16],
  11317. // 38
  11318. [4, 152, 122, 18, 153, 123],
  11319. [13, 74, 46, 32, 75, 47],
  11320. [48, 54, 24, 14, 55, 25],
  11321. [42, 45, 15, 32, 46, 16],
  11322. // 39
  11323. [20, 147, 117, 4, 148, 118],
  11324. [40, 75, 47, 7, 76, 48],
  11325. [43, 54, 24, 22, 55, 25],
  11326. [10, 45, 15, 67, 46, 16],
  11327. // 40
  11328. [19, 148, 118, 6, 149, 119],
  11329. [18, 75, 47, 31, 76, 48],
  11330. [34, 54, 24, 34, 55, 25],
  11331. [20, 45, 15, 61, 46, 16]
  11332. ];
  11333. /**
  11334. * 根据数据获取对应版本
  11335. * @return {[type]} [description]
  11336. */
  11337. QRCodeAlg.prototype.getRightType = function() {
  11338. for (var typeNumber = 1; typeNumber < 41; typeNumber++) {
  11339. var rsBlock = RS_BLOCK_TABLE[(typeNumber - 1) * 4 + this.errorCorrectLevel];
  11340. if (rsBlock == undefined) {
  11341. throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + this.errorCorrectLevel);
  11342. }
  11343. var length = rsBlock.length / 3;
  11344. var totalDataCount = 0;
  11345. for (var i = 0; i < length; i++) {
  11346. var count = rsBlock[i * 3 + 0];
  11347. var dataCount = rsBlock[i * 3 + 2];
  11348. totalDataCount += dataCount * count;
  11349. }
  11350. var lengthBytes = typeNumber > 9 ? 2 : 1;
  11351. if (this.utf8bytes.length + lengthBytes < totalDataCount || typeNumber == 40) {
  11352. this.typeNumber = typeNumber;
  11353. this.rsBlock = rsBlock;
  11354. this.totalDataCount = totalDataCount;
  11355. break;
  11356. }
  11357. }
  11358. };
  11359. //---------------------------------------------------------------------
  11360. // QRBitBuffer
  11361. //---------------------------------------------------------------------
  11362. function QRBitBuffer() {
  11363. this.buffer = new Array();
  11364. this.length = 0;
  11365. }
  11366. QRBitBuffer.prototype = {
  11367. get: function(index) {
  11368. var bufIndex = Math.floor(index / 8);
  11369. return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1);
  11370. },
  11371. put: function(num, length) {
  11372. for (var i = 0; i < length; i++) {
  11373. this.putBit(((num >>> (length - i - 1)) & 1));
  11374. }
  11375. },
  11376. putBit: function(bit) {
  11377. var bufIndex = Math.floor(this.length / 8);
  11378. if (this.buffer.length <= bufIndex) {
  11379. this.buffer.push(0);
  11380. }
  11381. if (bit) {
  11382. this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
  11383. }
  11384. this.length++;
  11385. }
  11386. };
  11387. /**
  11388. * 获取单个字符的utf8编码
  11389. * unicode BMP平面约65535个字符
  11390. * @param {num} code
  11391. * return {array}
  11392. */
  11393. function unicodeFormat8(code) {
  11394. // 1 byte
  11395. if (code < 128) {
  11396. return [code];
  11397. // 2 bytes
  11398. } else if (code < 2048) {
  11399. c0 = 192 + (code >> 6);
  11400. c1 = 128 + (code & 63);
  11401. return [c0, c1];
  11402. // 3 bytes
  11403. } else {
  11404. c0 = 224 + (code >> 12);
  11405. c1 = 128 + (code >> 6 & 63);
  11406. c2 = 128 + (code & 63);
  11407. return [c0, c1, c2];
  11408. }
  11409. }
  11410. /**
  11411. * 获取字符串的utf8编码字节串
  11412. * @param {string} string
  11413. * @return {array}
  11414. */
  11415. function getUTF8Bytes(string) {
  11416. var utf8codes = [];
  11417. for (var i = 0; i < string.length; i++) {
  11418. var code = string.charCodeAt(i);
  11419. var utf8 = unicodeFormat8(code);
  11420. for (var j = 0; j < utf8.length; j++) {
  11421. utf8codes.push(utf8[j]);
  11422. }
  11423. }
  11424. return utf8codes;
  11425. }
  11426. /**
  11427. * 二维码算法实现
  11428. * @param {string} data 要编码的信息字符串
  11429. * @param {num} errorCorrectLevel 纠错等级
  11430. */
  11431. function QRCodeAlg(data, errorCorrectLevel) {
  11432. this.typeNumber = -1; //版本
  11433. this.errorCorrectLevel = errorCorrectLevel;
  11434. this.modules = null; //二维矩阵,存放最终结果
  11435. this.moduleCount = 0; //矩阵大小
  11436. this.dataCache = null; //数据缓存
  11437. this.rsBlocks = null; //版本数据信息
  11438. this.totalDataCount = -1; //可使用的数据量
  11439. this.data = data;
  11440. this.utf8bytes = getUTF8Bytes(data);
  11441. this.make();
  11442. }
  11443. QRCodeAlg.prototype = {
  11444. constructor: QRCodeAlg,
  11445. /**
  11446. * 获取二维码矩阵大小
  11447. * @return {num} 矩阵大小
  11448. */
  11449. getModuleCount: function() {
  11450. return this.moduleCount;
  11451. },
  11452. /**
  11453. * 编码
  11454. */
  11455. make: function() {
  11456. this.getRightType();
  11457. this.dataCache = this.createData();
  11458. this.createQrcode();
  11459. },
  11460. /**
  11461. * 设置二位矩阵功能图形
  11462. * @param {bool} test 表示是否在寻找最好掩膜阶段
  11463. * @param {num} maskPattern 掩膜的版本
  11464. */
  11465. makeImpl: function(maskPattern) {
  11466. this.moduleCount = this.typeNumber * 4 + 17;
  11467. this.modules = new Array(this.moduleCount);
  11468. for (var row = 0; row < this.moduleCount; row++) {
  11469. this.modules[row] = new Array(this.moduleCount);
  11470. }
  11471. this.setupPositionProbePattern(0, 0);
  11472. this.setupPositionProbePattern(this.moduleCount - 7, 0);
  11473. this.setupPositionProbePattern(0, this.moduleCount - 7);
  11474. this.setupPositionAdjustPattern();
  11475. this.setupTimingPattern();
  11476. this.setupTypeInfo(true, maskPattern);
  11477. if (this.typeNumber >= 7) {
  11478. this.setupTypeNumber(true);
  11479. }
  11480. this.mapData(this.dataCache, maskPattern);
  11481. },
  11482. /**
  11483. * 设置二维码的位置探测图形
  11484. * @param {num} row 探测图形的中心横坐标
  11485. * @param {num} col 探测图形的中心纵坐标
  11486. */
  11487. setupPositionProbePattern: function(row, col) {
  11488. for (var r = -1; r <= 7; r++) {
  11489. if (row + r <= -1 || this.moduleCount <= row + r) continue;
  11490. for (var c = -1; c <= 7; c++) {
  11491. if (col + c <= -1 || this.moduleCount <= col + c) continue;
  11492. if ((0 <= r && r <= 6 && (c == 0 || c == 6)) || (0 <= c && c <= 6 && (r == 0 || r == 6)) || (2 <= r && r <= 4 && 2 <= c && c <= 4)) {
  11493. this.modules[row + r][col + c] = true;
  11494. } else {
  11495. this.modules[row + r][col + c] = false;
  11496. }
  11497. }
  11498. }
  11499. },
  11500. /**
  11501. * 创建二维码
  11502. * @return {[type]} [description]
  11503. */
  11504. createQrcode: function() {
  11505. var minLostPoint = 0;
  11506. var pattern = 0;
  11507. var bestModules = null;
  11508. for (var i = 0; i < 8; i++) {
  11509. this.makeImpl(i);
  11510. var lostPoint = QRUtil.getLostPoint(this);
  11511. if (i == 0 || minLostPoint > lostPoint) {
  11512. minLostPoint = lostPoint;
  11513. pattern = i;
  11514. bestModules = this.modules;
  11515. }
  11516. }
  11517. this.modules = bestModules;
  11518. this.setupTypeInfo(false, pattern);
  11519. if (this.typeNumber >= 7) {
  11520. this.setupTypeNumber(false);
  11521. }
  11522. },
  11523. /**
  11524. * 设置定位图形
  11525. * @return {[type]} [description]
  11526. */
  11527. setupTimingPattern: function() {
  11528. for (var r = 8; r < this.moduleCount - 8; r++) {
  11529. if (this.modules[r][6] != null) {
  11530. continue;
  11531. }
  11532. this.modules[r][6] = (r % 2 == 0);
  11533. if (this.modules[6][r] != null) {
  11534. continue;
  11535. }
  11536. this.modules[6][r] = (r % 2 == 0);
  11537. }
  11538. },
  11539. /**
  11540. * 设置矫正图形
  11541. * @return {[type]} [description]
  11542. */
  11543. setupPositionAdjustPattern: function() {
  11544. var pos = QRUtil.getPatternPosition(this.typeNumber);
  11545. for (var i = 0; i < pos.length; i++) {
  11546. for (var j = 0; j < pos.length; j++) {
  11547. var row = pos[i];
  11548. var col = pos[j];
  11549. if (this.modules[row][col] != null) {
  11550. continue;
  11551. }
  11552. for (var r = -2; r <= 2; r++) {
  11553. for (var c = -2; c <= 2; c++) {
  11554. if (r == -2 || r == 2 || c == -2 || c == 2 || (r == 0 && c == 0)) {
  11555. this.modules[row + r][col + c] = true;
  11556. } else {
  11557. this.modules[row + r][col + c] = false;
  11558. }
  11559. }
  11560. }
  11561. }
  11562. }
  11563. },
  11564. /**
  11565. * 设置版本信息(7以上版本才有)
  11566. * @param {bool} test 是否处于判断最佳掩膜阶段
  11567. * @return {[type]} [description]
  11568. */
  11569. setupTypeNumber: function(test) {
  11570. var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
  11571. for (var i = 0; i < 18; i++) {
  11572. var mod = (!test && ((bits >> i) & 1) == 1);
  11573. this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
  11574. this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
  11575. }
  11576. },
  11577. /**
  11578. * 设置格式信息(纠错等级和掩膜版本)
  11579. * @param {bool} test
  11580. * @param {num} maskPattern 掩膜版本
  11581. * @return {}
  11582. */
  11583. setupTypeInfo: function(test, maskPattern) {
  11584. var data = (QRErrorCorrectLevel[this.errorCorrectLevel] << 3) | maskPattern;
  11585. var bits = QRUtil.getBCHTypeInfo(data);
  11586. // vertical
  11587. for (var i = 0; i < 15; i++) {
  11588. var mod = (!test && ((bits >> i) & 1) == 1);
  11589. if (i < 6) {
  11590. this.modules[i][8] = mod;
  11591. } else if (i < 8) {
  11592. this.modules[i + 1][8] = mod;
  11593. } else {
  11594. this.modules[this.moduleCount - 15 + i][8] = mod;
  11595. }
  11596. // horizontal
  11597. var mod = (!test && ((bits >> i) & 1) == 1);
  11598. if (i < 8) {
  11599. this.modules[8][this.moduleCount - i - 1] = mod;
  11600. } else if (i < 9) {
  11601. this.modules[8][15 - i - 1 + 1] = mod;
  11602. } else {
  11603. this.modules[8][15 - i - 1] = mod;
  11604. }
  11605. }
  11606. // fixed module
  11607. this.modules[this.moduleCount - 8][8] = (!test);
  11608. },
  11609. /**
  11610. * 数据编码
  11611. * @return {[type]} [description]
  11612. */
  11613. createData: function() {
  11614. var buffer = new QRBitBuffer();
  11615. var lengthBits = this.typeNumber > 9 ? 16 : 8;
  11616. buffer.put(4, 4); //添加模式
  11617. buffer.put(this.utf8bytes.length, lengthBits);
  11618. for (var i = 0, l = this.utf8bytes.length; i < l; i++) {
  11619. buffer.put(this.utf8bytes[i], 8);
  11620. }
  11621. if (buffer.length + 4 <= this.totalDataCount * 8) {
  11622. buffer.put(0, 4);
  11623. }
  11624. // padding
  11625. while (buffer.length % 8 != 0) {
  11626. buffer.putBit(false);
  11627. }
  11628. // padding
  11629. while (true) {
  11630. if (buffer.length >= this.totalDataCount * 8) {
  11631. break;
  11632. }
  11633. buffer.put(QRCodeAlg.PAD0, 8);
  11634. if (buffer.length >= this.totalDataCount * 8) {
  11635. break;
  11636. }
  11637. buffer.put(QRCodeAlg.PAD1, 8);
  11638. }
  11639. return this.createBytes(buffer);
  11640. },
  11641. /**
  11642. * 纠错码编码
  11643. * @param {buffer} buffer 数据编码
  11644. * @return {[type]}
  11645. */
  11646. createBytes: function(buffer) {
  11647. var offset = 0;
  11648. var maxDcCount = 0;
  11649. var maxEcCount = 0;
  11650. var length = this.rsBlock.length / 3;
  11651. var rsBlocks = new Array();
  11652. for (var i = 0; i < length; i++) {
  11653. var count = this.rsBlock[i * 3 + 0];
  11654. var totalCount = this.rsBlock[i * 3 + 1];
  11655. var dataCount = this.rsBlock[i * 3 + 2];
  11656. for (var j = 0; j < count; j++) {
  11657. rsBlocks.push([dataCount, totalCount]);
  11658. }
  11659. }
  11660. var dcdata = new Array(rsBlocks.length);
  11661. var ecdata = new Array(rsBlocks.length);
  11662. for (var r = 0; r < rsBlocks.length; r++) {
  11663. var dcCount = rsBlocks[r][0];
  11664. var ecCount = rsBlocks[r][1] - dcCount;
  11665. maxDcCount = Math.max(maxDcCount, dcCount);
  11666. maxEcCount = Math.max(maxEcCount, ecCount);
  11667. dcdata[r] = new Array(dcCount);
  11668. for (var i = 0; i < dcdata[r].length; i++) {
  11669. dcdata[r][i] = 0xff & buffer.buffer[i + offset];
  11670. }
  11671. offset += dcCount;
  11672. var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
  11673. var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
  11674. var modPoly = rawPoly.mod(rsPoly);
  11675. ecdata[r] = new Array(rsPoly.getLength() - 1);
  11676. for (var i = 0; i < ecdata[r].length; i++) {
  11677. var modIndex = i + modPoly.getLength() - ecdata[r].length;
  11678. ecdata[r][i] = (modIndex >= 0) ? modPoly.get(modIndex) : 0;
  11679. }
  11680. }
  11681. var data = new Array(this.totalDataCount);
  11682. var index = 0;
  11683. for (var i = 0; i < maxDcCount; i++) {
  11684. for (var r = 0; r < rsBlocks.length; r++) {
  11685. if (i < dcdata[r].length) {
  11686. data[index++] = dcdata[r][i];
  11687. }
  11688. }
  11689. }
  11690. for (var i = 0; i < maxEcCount; i++) {
  11691. for (var r = 0; r < rsBlocks.length; r++) {
  11692. if (i < ecdata[r].length) {
  11693. data[index++] = ecdata[r][i];
  11694. }
  11695. }
  11696. }
  11697. return data;
  11698. },
  11699. /**
  11700. * 布置模块,构建最终信息
  11701. * @param {} data
  11702. * @param {} maskPattern
  11703. * @return {}
  11704. */
  11705. mapData: function(data, maskPattern) {
  11706. var inc = -1;
  11707. var row = this.moduleCount - 1;
  11708. var bitIndex = 7;
  11709. var byteIndex = 0;
  11710. for (var col = this.moduleCount - 1; col > 0; col -= 2) {
  11711. if (col == 6) col--;
  11712. while (true) {
  11713. for (var c = 0; c < 2; c++) {
  11714. if (this.modules[row][col - c] == null) {
  11715. var dark = false;
  11716. if (byteIndex < data.length) {
  11717. dark = (((data[byteIndex] >>> bitIndex) & 1) == 1);
  11718. }
  11719. var mask = QRUtil.getMask(maskPattern, row, col - c);
  11720. if (mask) {
  11721. dark = !dark;
  11722. }
  11723. this.modules[row][col - c] = dark;
  11724. bitIndex--;
  11725. if (bitIndex == -1) {
  11726. byteIndex++;
  11727. bitIndex = 7;
  11728. }
  11729. }
  11730. }
  11731. row += inc;
  11732. if (row < 0 || this.moduleCount <= row) {
  11733. row -= inc;
  11734. inc = -inc;
  11735. break;
  11736. }
  11737. }
  11738. }
  11739. }
  11740. };
  11741. /**
  11742. * 填充字段
  11743. */
  11744. QRCodeAlg.PAD0 = 0xEC;
  11745. QRCodeAlg.PAD1 = 0x11;
  11746. //---------------------------------------------------------------------
  11747. // 纠错等级对应的编码
  11748. //---------------------------------------------------------------------
  11749. var QRErrorCorrectLevel = [1, 0, 3, 2];
  11750. //---------------------------------------------------------------------
  11751. // 掩膜版本
  11752. //---------------------------------------------------------------------
  11753. var QRMaskPattern = {
  11754. PATTERN000: 0,
  11755. PATTERN001: 1,
  11756. PATTERN010: 2,
  11757. PATTERN011: 3,
  11758. PATTERN100: 4,
  11759. PATTERN101: 5,
  11760. PATTERN110: 6,
  11761. PATTERN111: 7
  11762. };
  11763. //---------------------------------------------------------------------
  11764. // 工具类
  11765. //---------------------------------------------------------------------
  11766. var QRUtil = {
  11767. /*
  11768. 每个版本矫正图形的位置
  11769. */
  11770. PATTERN_POSITION_TABLE: [
  11771. [],
  11772. [6, 18],
  11773. [6, 22],
  11774. [6, 26],
  11775. [6, 30],
  11776. [6, 34],
  11777. [6, 22, 38],
  11778. [6, 24, 42],
  11779. [6, 26, 46],
  11780. [6, 28, 50],
  11781. [6, 30, 54],
  11782. [6, 32, 58],
  11783. [6, 34, 62],
  11784. [6, 26, 46, 66],
  11785. [6, 26, 48, 70],
  11786. [6, 26, 50, 74],
  11787. [6, 30, 54, 78],
  11788. [6, 30, 56, 82],
  11789. [6, 30, 58, 86],
  11790. [6, 34, 62, 90],
  11791. [6, 28, 50, 72, 94],
  11792. [6, 26, 50, 74, 98],
  11793. [6, 30, 54, 78, 102],
  11794. [6, 28, 54, 80, 106],
  11795. [6, 32, 58, 84, 110],
  11796. [6, 30, 58, 86, 114],
  11797. [6, 34, 62, 90, 118],
  11798. [6, 26, 50, 74, 98, 122],
  11799. [6, 30, 54, 78, 102, 126],
  11800. [6, 26, 52, 78, 104, 130],
  11801. [6, 30, 56, 82, 108, 134],
  11802. [6, 34, 60, 86, 112, 138],
  11803. [6, 30, 58, 86, 114, 142],
  11804. [6, 34, 62, 90, 118, 146],
  11805. [6, 30, 54, 78, 102, 126, 150],
  11806. [6, 24, 50, 76, 102, 128, 154],
  11807. [6, 28, 54, 80, 106, 132, 158],
  11808. [6, 32, 58, 84, 110, 136, 162],
  11809. [6, 26, 54, 82, 110, 138, 166],
  11810. [6, 30, 58, 86, 114, 142, 170]
  11811. ],
  11812. G15: (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0),
  11813. G18: (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0),
  11814. G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
  11815. /*
  11816. BCH编码格式信息
  11817. */
  11818. getBCHTypeInfo: function(data) {
  11819. var d = data << 10;
  11820. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
  11821. d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15)));
  11822. }
  11823. return ((data << 10) | d) ^ QRUtil.G15_MASK;
  11824. },
  11825. /*
  11826. BCH编码版本信息
  11827. */
  11828. getBCHTypeNumber: function(data) {
  11829. var d = data << 12;
  11830. while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
  11831. d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18)));
  11832. }
  11833. return (data << 12) | d;
  11834. },
  11835. /*
  11836. 获取BCH位信息
  11837. */
  11838. getBCHDigit: function(data) {
  11839. var digit = 0;
  11840. while (data != 0) {
  11841. digit++;
  11842. data >>>= 1;
  11843. }
  11844. return digit;
  11845. },
  11846. /*
  11847. 获取版本对应的矫正图形位置
  11848. */
  11849. getPatternPosition: function(typeNumber) {
  11850. return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
  11851. },
  11852. /*
  11853. 掩膜算法
  11854. */
  11855. getMask: function(maskPattern, i, j) {
  11856. switch (maskPattern) {
  11857. case QRMaskPattern.PATTERN000:
  11858. return (i + j) % 2 == 0;
  11859. case QRMaskPattern.PATTERN001:
  11860. return i % 2 == 0;
  11861. case QRMaskPattern.PATTERN010:
  11862. return j % 3 == 0;
  11863. case QRMaskPattern.PATTERN011:
  11864. return (i + j) % 3 == 0;
  11865. case QRMaskPattern.PATTERN100:
  11866. return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
  11867. case QRMaskPattern.PATTERN101:
  11868. return (i * j) % 2 + (i * j) % 3 == 0;
  11869. case QRMaskPattern.PATTERN110:
  11870. return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
  11871. case QRMaskPattern.PATTERN111:
  11872. return ((i * j) % 3 + (i + j) % 2) % 2 == 0;
  11873. default:
  11874. throw new Error("bad maskPattern:" + maskPattern);
  11875. }
  11876. },
  11877. /*
  11878. 获取RS的纠错多项式
  11879. */
  11880. getErrorCorrectPolynomial: function(errorCorrectLength) {
  11881. var a = new QRPolynomial([1], 0);
  11882. for (var i = 0; i < errorCorrectLength; i++) {
  11883. a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
  11884. }
  11885. return a;
  11886. },
  11887. /*
  11888. 获取评价
  11889. */
  11890. getLostPoint: function(qrCode) {
  11891. var moduleCount = qrCode.getModuleCount(),
  11892. lostPoint = 0,
  11893. darkCount = 0;
  11894. for (var row = 0; row < moduleCount; row++) {
  11895. var sameCount = 0;
  11896. var head = qrCode.modules[row][0];
  11897. for (var col = 0; col < moduleCount; col++) {
  11898. var current = qrCode.modules[row][col];
  11899. //level 3 评价
  11900. if (col < moduleCount - 6) {
  11901. if (current && !qrCode.modules[row][col + 1] && qrCode.modules[row][col + 2] && qrCode.modules[row][col + 3] && qrCode.modules[row][col + 4] && !qrCode.modules[row][col + 5] && qrCode.modules[row][col + 6]) {
  11902. if (col < moduleCount - 10) {
  11903. if (qrCode.modules[row][col + 7] && qrCode.modules[row][col + 8] && qrCode.modules[row][col + 9] && qrCode.modules[row][col + 10]) {
  11904. lostPoint += 40;
  11905. }
  11906. } else if (col > 3) {
  11907. if (qrCode.modules[row][col - 1] && qrCode.modules[row][col - 2] && qrCode.modules[row][col - 3] && qrCode.modules[row][col - 4]) {
  11908. lostPoint += 40;
  11909. }
  11910. }
  11911. }
  11912. }
  11913. //level 2 评价
  11914. if ((row < moduleCount - 1) && (col < moduleCount - 1)) {
  11915. var count = 0;
  11916. if (current) count++;
  11917. if (qrCode.modules[row + 1][col]) count++;
  11918. if (qrCode.modules[row][col + 1]) count++;
  11919. if (qrCode.modules[row + 1][col + 1]) count++;
  11920. if (count == 0 || count == 4) {
  11921. lostPoint += 3;
  11922. }
  11923. }
  11924. //level 1 评价
  11925. if (head ^ current) {
  11926. sameCount++;
  11927. } else {
  11928. head = current;
  11929. if (sameCount >= 5) {
  11930. lostPoint += (3 + sameCount - 5);
  11931. }
  11932. sameCount = 1;
  11933. }
  11934. //level 4 评价
  11935. if (current) {
  11936. darkCount++;
  11937. }
  11938. }
  11939. }
  11940. for (var col = 0; col < moduleCount; col++) {
  11941. var sameCount = 0;
  11942. var head = qrCode.modules[0][col];
  11943. for (var row = 0; row < moduleCount; row++) {
  11944. var current = qrCode.modules[row][col];
  11945. //level 3 评价
  11946. if (row < moduleCount - 6) {
  11947. if (current && !qrCode.modules[row + 1][col] && qrCode.modules[row + 2][col] && qrCode.modules[row + 3][col] && qrCode.modules[row + 4][col] && !qrCode.modules[row + 5][col] && qrCode.modules[row + 6][col]) {
  11948. if (row < moduleCount - 10) {
  11949. if (qrCode.modules[row + 7][col] && qrCode.modules[row + 8][col] && qrCode.modules[row + 9][col] && qrCode.modules[row + 10][col]) {
  11950. lostPoint += 40;
  11951. }
  11952. } else if (row > 3) {
  11953. if (qrCode.modules[row - 1][col] && qrCode.modules[row - 2][col] && qrCode.modules[row - 3][col] && qrCode.modules[row - 4][col]) {
  11954. lostPoint += 40;
  11955. }
  11956. }
  11957. }
  11958. }
  11959. //level 1 评价
  11960. if (head ^ current) {
  11961. sameCount++;
  11962. } else {
  11963. head = current;
  11964. if (sameCount >= 5) {
  11965. lostPoint += (3 + sameCount - 5);
  11966. }
  11967. sameCount = 1;
  11968. }
  11969. }
  11970. }
  11971. // LEVEL4
  11972. var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
  11973. lostPoint += ratio * 10;
  11974. return lostPoint;
  11975. }
  11976. };
  11977. //---------------------------------------------------------------------
  11978. // QRMath使用的数学工具
  11979. //---------------------------------------------------------------------
  11980. var QRMath = {
  11981. /*
  11982. 将n转化为a^m
  11983. */
  11984. glog: function(n) {
  11985. if (n < 1) {
  11986. throw new Error("glog(" + n + ")");
  11987. }
  11988. return QRMath.LOG_TABLE[n];
  11989. },
  11990. /*
  11991. 将a^m转化为n
  11992. */
  11993. gexp: function(n) {
  11994. while (n < 0) {
  11995. n += 255;
  11996. }
  11997. while (n >= 256) {
  11998. n -= 255;
  11999. }
  12000. return QRMath.EXP_TABLE[n];
  12001. },
  12002. EXP_TABLE: new Array(256),
  12003. LOG_TABLE: new Array(256)
  12004. };
  12005. for (var i = 0; i < 8; i++) {
  12006. QRMath.EXP_TABLE[i] = 1 << i;
  12007. }
  12008. for (var i = 8; i < 256; i++) {
  12009. QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
  12010. }
  12011. for (var i = 0; i < 255; i++) {
  12012. QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
  12013. }
  12014. //---------------------------------------------------------------------
  12015. // QRPolynomial 多项式
  12016. //---------------------------------------------------------------------
  12017. /**
  12018. * 多项式类
  12019. * @param {Array} num 系数
  12020. * @param {num} shift a^shift
  12021. */
  12022. function QRPolynomial(num, shift) {
  12023. if (num.length == undefined) {
  12024. throw new Error(num.length + "/" + shift);
  12025. }
  12026. var offset = 0;
  12027. while (offset < num.length && num[offset] == 0) {
  12028. offset++;
  12029. }
  12030. this.num = new Array(num.length - offset + shift);
  12031. for (var i = 0; i < num.length - offset; i++) {
  12032. this.num[i] = num[i + offset];
  12033. }
  12034. }
  12035. QRPolynomial.prototype = {
  12036. get: function(index) {
  12037. return this.num[index];
  12038. },
  12039. getLength: function() {
  12040. return this.num.length;
  12041. },
  12042. /**
  12043. * 多项式乘法
  12044. * @param {QRPolynomial} e 被乘多项式
  12045. * @return {[type]} [description]
  12046. */
  12047. multiply: function(e) {
  12048. var num = new Array(this.getLength() + e.getLength() - 1);
  12049. for (var i = 0; i < this.getLength(); i++) {
  12050. for (var j = 0; j < e.getLength(); j++) {
  12051. num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
  12052. }
  12053. }
  12054. return new QRPolynomial(num, 0);
  12055. },
  12056. /**
  12057. * 多项式模运算
  12058. * @param {QRPolynomial} e 模多项式
  12059. * @return {}
  12060. */
  12061. mod: function(e) {
  12062. var tl = this.getLength(),
  12063. el = e.getLength();
  12064. if (tl - el < 0) {
  12065. return this;
  12066. }
  12067. var num = new Array(tl);
  12068. for (var i = 0; i < tl; i++) {
  12069. num[i] = this.get(i);
  12070. }
  12071. while (num.length >= el) {
  12072. var ratio = QRMath.glog(num[0]) - QRMath.glog(e.get(0));
  12073. for (var i = 0; i < e.getLength(); i++) {
  12074. num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio);
  12075. }
  12076. while (num[0] == 0) {
  12077. num.shift();
  12078. }
  12079. }
  12080. return new QRPolynomial(num, 0);
  12081. }
  12082. };
  12083. //---------------------------------------------------------------------
  12084. // RS_BLOCK_TABLE
  12085. //---------------------------------------------------------------------
  12086. /*
  12087. 二维码各个版本信息[块数, 每块中的数据块数, 每块中的信息块数]
  12088. */
  12089. RS_BLOCK_TABLE = [
  12090. // L
  12091. // M
  12092. // Q
  12093. // H
  12094. // 1
  12095. [1, 26, 19],
  12096. [1, 26, 16],
  12097. [1, 26, 13],
  12098. [1, 26, 9],
  12099. // 2
  12100. [1, 44, 34],
  12101. [1, 44, 28],
  12102. [1, 44, 22],
  12103. [1, 44, 16],
  12104. // 3
  12105. [1, 70, 55],
  12106. [1, 70, 44],
  12107. [2, 35, 17],
  12108. [2, 35, 13],
  12109. // 4
  12110. [1, 100, 80],
  12111. [2, 50, 32],
  12112. [2, 50, 24],
  12113. [4, 25, 9],
  12114. // 5
  12115. [1, 134, 108],
  12116. [2, 67, 43],
  12117. [2, 33, 15, 2, 34, 16],
  12118. [2, 33, 11, 2, 34, 12],
  12119. // 6
  12120. [2, 86, 68],
  12121. [4, 43, 27],
  12122. [4, 43, 19],
  12123. [4, 43, 15],
  12124. // 7
  12125. [2, 98, 78],
  12126. [4, 49, 31],
  12127. [2, 32, 14, 4, 33, 15],
  12128. [4, 39, 13, 1, 40, 14],
  12129. // 8
  12130. [2, 121, 97],
  12131. [2, 60, 38, 2, 61, 39],
  12132. [4, 40, 18, 2, 41, 19],
  12133. [4, 40, 14, 2, 41, 15],
  12134. // 9
  12135. [2, 146, 116],
  12136. [3, 58, 36, 2, 59, 37],
  12137. [4, 36, 16, 4, 37, 17],
  12138. [4, 36, 12, 4, 37, 13],
  12139. // 10
  12140. [2, 86, 68, 2, 87, 69],
  12141. [4, 69, 43, 1, 70, 44],
  12142. [6, 43, 19, 2, 44, 20],
  12143. [6, 43, 15, 2, 44, 16],
  12144. // 11
  12145. [4, 101, 81],
  12146. [1, 80, 50, 4, 81, 51],
  12147. [4, 50, 22, 4, 51, 23],
  12148. [3, 36, 12, 8, 37, 13],
  12149. // 12
  12150. [2, 116, 92, 2, 117, 93],
  12151. [6, 58, 36, 2, 59, 37],
  12152. [4, 46, 20, 6, 47, 21],
  12153. [7, 42, 14, 4, 43, 15],
  12154. // 13
  12155. [4, 133, 107],
  12156. [8, 59, 37, 1, 60, 38],
  12157. [8, 44, 20, 4, 45, 21],
  12158. [12, 33, 11, 4, 34, 12],
  12159. // 14
  12160. [3, 145, 115, 1, 146, 116],
  12161. [4, 64, 40, 5, 65, 41],
  12162. [11, 36, 16, 5, 37, 17],
  12163. [11, 36, 12, 5, 37, 13],
  12164. // 15
  12165. [5, 109, 87, 1, 110, 88],
  12166. [5, 65, 41, 5, 66, 42],
  12167. [5, 54, 24, 7, 55, 25],
  12168. [11, 36, 12],
  12169. // 16
  12170. [5, 122, 98, 1, 123, 99],
  12171. [7, 73, 45, 3, 74, 46],
  12172. [15, 43, 19, 2, 44, 20],
  12173. [3, 45, 15, 13, 46, 16],
  12174. // 17
  12175. [1, 135, 107, 5, 136, 108],
  12176. [10, 74, 46, 1, 75, 47],
  12177. [1, 50, 22, 15, 51, 23],
  12178. [2, 42, 14, 17, 43, 15],
  12179. // 18
  12180. [5, 150, 120, 1, 151, 121],
  12181. [9, 69, 43, 4, 70, 44],
  12182. [17, 50, 22, 1, 51, 23],
  12183. [2, 42, 14, 19, 43, 15],
  12184. // 19
  12185. [3, 141, 113, 4, 142, 114],
  12186. [3, 70, 44, 11, 71, 45],
  12187. [17, 47, 21, 4, 48, 22],
  12188. [9, 39, 13, 16, 40, 14],
  12189. // 20
  12190. [3, 135, 107, 5, 136, 108],
  12191. [3, 67, 41, 13, 68, 42],
  12192. [15, 54, 24, 5, 55, 25],
  12193. [15, 43, 15, 10, 44, 16],
  12194. // 21
  12195. [4, 144, 116, 4, 145, 117],
  12196. [17, 68, 42],
  12197. [17, 50, 22, 6, 51, 23],
  12198. [19, 46, 16, 6, 47, 17],
  12199. // 22
  12200. [2, 139, 111, 7, 140, 112],
  12201. [17, 74, 46],
  12202. [7, 54, 24, 16, 55, 25],
  12203. [34, 37, 13],
  12204. // 23
  12205. [4, 151, 121, 5, 152, 122],
  12206. [4, 75, 47, 14, 76, 48],
  12207. [11, 54, 24, 14, 55, 25],
  12208. [16, 45, 15, 14, 46, 16],
  12209. // 24
  12210. [6, 147, 117, 4, 148, 118],
  12211. [6, 73, 45, 14, 74, 46],
  12212. [11, 54, 24, 16, 55, 25],
  12213. [30, 46, 16, 2, 47, 17],
  12214. // 25
  12215. [8, 132, 106, 4, 133, 107],
  12216. [8, 75, 47, 13, 76, 48],
  12217. [7, 54, 24, 22, 55, 25],
  12218. [22, 45, 15, 13, 46, 16],
  12219. // 26
  12220. [10, 142, 114, 2, 143, 115],
  12221. [19, 74, 46, 4, 75, 47],
  12222. [28, 50, 22, 6, 51, 23],
  12223. [33, 46, 16, 4, 47, 17],
  12224. // 27
  12225. [8, 152, 122, 4, 153, 123],
  12226. [22, 73, 45, 3, 74, 46],
  12227. [8, 53, 23, 26, 54, 24],
  12228. [12, 45, 15, 28, 46, 16],
  12229. // 28
  12230. [3, 147, 117, 10, 148, 118],
  12231. [3, 73, 45, 23, 74, 46],
  12232. [4, 54, 24, 31, 55, 25],
  12233. [11, 45, 15, 31, 46, 16],
  12234. // 29
  12235. [7, 146, 116, 7, 147, 117],
  12236. [21, 73, 45, 7, 74, 46],
  12237. [1, 53, 23, 37, 54, 24],
  12238. [19, 45, 15, 26, 46, 16],
  12239. // 30
  12240. [5, 145, 115, 10, 146, 116],
  12241. [19, 75, 47, 10, 76, 48],
  12242. [15, 54, 24, 25, 55, 25],
  12243. [23, 45, 15, 25, 46, 16],
  12244. // 31
  12245. [13, 145, 115, 3, 146, 116],
  12246. [2, 74, 46, 29, 75, 47],
  12247. [42, 54, 24, 1, 55, 25],
  12248. [23, 45, 15, 28, 46, 16],
  12249. // 32
  12250. [17, 145, 115],
  12251. [10, 74, 46, 23, 75, 47],
  12252. [10, 54, 24, 35, 55, 25],
  12253. [19, 45, 15, 35, 46, 16],
  12254. // 33
  12255. [17, 145, 115, 1, 146, 116],
  12256. [14, 74, 46, 21, 75, 47],
  12257. [29, 54, 24, 19, 55, 25],
  12258. [11, 45, 15, 46, 46, 16],
  12259. // 34
  12260. [13, 145, 115, 6, 146, 116],
  12261. [14, 74, 46, 23, 75, 47],
  12262. [44, 54, 24, 7, 55, 25],
  12263. [59, 46, 16, 1, 47, 17],
  12264. // 35
  12265. [12, 151, 121, 7, 152, 122],
  12266. [12, 75, 47, 26, 76, 48],
  12267. [39, 54, 24, 14, 55, 25],
  12268. [22, 45, 15, 41, 46, 16],
  12269. // 36
  12270. [6, 151, 121, 14, 152, 122],
  12271. [6, 75, 47, 34, 76, 48],
  12272. [46, 54, 24, 10, 55, 25],
  12273. [2, 45, 15, 64, 46, 16],
  12274. // 37
  12275. [17, 152, 122, 4, 153, 123],
  12276. [29, 74, 46, 14, 75, 47],
  12277. [49, 54, 24, 10, 55, 25],
  12278. [24, 45, 15, 46, 46, 16],
  12279. // 38
  12280. [4, 152, 122, 18, 153, 123],
  12281. [13, 74, 46, 32, 75, 47],
  12282. [48, 54, 24, 14, 55, 25],
  12283. [42, 45, 15, 32, 46, 16],
  12284. // 39
  12285. [20, 147, 117, 4, 148, 118],
  12286. [40, 75, 47, 7, 76, 48],
  12287. [43, 54, 24, 22, 55, 25],
  12288. [10, 45, 15, 67, 46, 16],
  12289. // 40
  12290. [19, 148, 118, 6, 149, 119],
  12291. [18, 75, 47, 31, 76, 48],
  12292. [34, 54, 24, 34, 55, 25],
  12293. [20, 45, 15, 61, 46, 16]
  12294. ];
  12295. /**
  12296. * 根据数据获取对应版本
  12297. * @return {[type]} [description]
  12298. */
  12299. QRCodeAlg.prototype.getRightType = function() {
  12300. for (var typeNumber = 1; typeNumber < 41; typeNumber++) {
  12301. var rsBlock = RS_BLOCK_TABLE[(typeNumber - 1) * 4 + this.errorCorrectLevel];
  12302. if (rsBlock == undefined) {
  12303. throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + this.errorCorrectLevel);
  12304. }
  12305. var length = rsBlock.length / 3;
  12306. var totalDataCount = 0;
  12307. for (var i = 0; i < length; i++) {
  12308. var count = rsBlock[i * 3 + 0];
  12309. var dataCount = rsBlock[i * 3 + 2];
  12310. totalDataCount += dataCount * count;
  12311. }
  12312. var lengthBytes = typeNumber > 9 ? 2 : 1;
  12313. if (this.utf8bytes.length + lengthBytes < totalDataCount || typeNumber == 40) {
  12314. this.typeNumber = typeNumber;
  12315. this.rsBlock = rsBlock;
  12316. this.totalDataCount = totalDataCount;
  12317. break;
  12318. }
  12319. }
  12320. };
  12321. //---------------------------------------------------------------------
  12322. // QRBitBuffer
  12323. //---------------------------------------------------------------------
  12324. function QRBitBuffer() {
  12325. this.buffer = new Array();
  12326. this.length = 0;
  12327. }
  12328. QRBitBuffer.prototype = {
  12329. get: function(index) {
  12330. var bufIndex = Math.floor(index / 8);
  12331. return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1);
  12332. },
  12333. put: function(num, length) {
  12334. for (var i = 0; i < length; i++) {
  12335. this.putBit(((num >>> (length - i - 1)) & 1));
  12336. }
  12337. },
  12338. putBit: function(bit) {
  12339. var bufIndex = Math.floor(this.length / 8);
  12340. if (this.buffer.length <= bufIndex) {
  12341. this.buffer.push(0);
  12342. }
  12343. if (bit) {
  12344. this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
  12345. }
  12346. this.length++;
  12347. }
  12348. };
  12349. $.AMUI.qrcode = qrcode;
  12350. module.exports = qrcode;
  12351. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12352. },{"2":2}],32:[function(_dereq_,module,exports){
  12353. (function (global){
  12354. 'use strict';
  12355. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12356. _dereq_(2);
  12357. /**
  12358. * store.js
  12359. * @via https://github.com/marcuswestin/store.js
  12360. * @license https://github.com/marcuswestin/store.js/blob/master/LICENSE
  12361. */
  12362. var store = {};
  12363. var win = window;
  12364. var localStorageName = 'localStorage';
  12365. var storage;
  12366. store.disabled = false;
  12367. store.version = '1.3.17';
  12368. store.set = function(key, value) {
  12369. };
  12370. store.get = function(key, defaultVal) {
  12371. };
  12372. store.has = function(key) {
  12373. return store.get(key) !== undefined;
  12374. };
  12375. store.remove = function(key) {
  12376. };
  12377. store.clear = function() {
  12378. };
  12379. store.transact = function(key, defaultVal, transactionFn) {
  12380. if (transactionFn == null) {
  12381. transactionFn = defaultVal;
  12382. defaultVal = null;
  12383. }
  12384. if (defaultVal == null) {
  12385. defaultVal = {};
  12386. }
  12387. var val = store.get(key, defaultVal);
  12388. transactionFn(val);
  12389. store.set(key, val);
  12390. };
  12391. store.getAll = function() {
  12392. };
  12393. store.forEach = function() {
  12394. };
  12395. store.serialize = function(value) {
  12396. return JSON.stringify(value);
  12397. };
  12398. store.deserialize = function(value) {
  12399. if (typeof value != 'string') {
  12400. return undefined;
  12401. }
  12402. try {
  12403. return JSON.parse(value);
  12404. } catch (e) {
  12405. return value || undefined;
  12406. }
  12407. };
  12408. // Functions to encapsulate questionable FireFox 3.6.13 behavior
  12409. // when about.config::dom.storage.enabled === false
  12410. // See https://github.com/marcuswestin/store.js/issues#issue/13
  12411. function isLocalStorageNameSupported() {
  12412. try {
  12413. return (localStorageName in win && win[localStorageName]);
  12414. }
  12415. catch (err) {
  12416. return false;
  12417. }
  12418. }
  12419. if (isLocalStorageNameSupported()) {
  12420. storage = win[localStorageName];
  12421. store.set = function(key, val) {
  12422. if (val === undefined) {
  12423. return store.remove(key);
  12424. }
  12425. storage.setItem(key, store.serialize(val));
  12426. return val;
  12427. };
  12428. store.get = function(key, defaultVal) {
  12429. var val = store.deserialize(storage.getItem(key));
  12430. return (val === undefined ? defaultVal : val);
  12431. };
  12432. store.remove = function(key) {
  12433. storage.removeItem(key);
  12434. };
  12435. store.clear = function() {
  12436. storage.clear();
  12437. };
  12438. store.getAll = function() {
  12439. var ret = {};
  12440. store.forEach(function(key, val) {
  12441. ret[key] = val;
  12442. });
  12443. return ret;
  12444. };
  12445. store.forEach = function(callback) {
  12446. for (var i = 0; i < storage.length; i++) {
  12447. var key = storage.key(i);
  12448. callback(key, store.get(key));
  12449. }
  12450. };
  12451. }
  12452. try {
  12453. var testKey = '__storeJs__';
  12454. store.set(testKey, testKey);
  12455. if (store.get(testKey) != testKey) {
  12456. store.disabled = true;
  12457. }
  12458. store.remove(testKey);
  12459. } catch (e) {
  12460. store.disabled = true;
  12461. }
  12462. store.enabled = !store.disabled;
  12463. $.AMUI = $.AMUI || {};
  12464. $.AMUI.store = store;
  12465. module.exports = store;
  12466. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12467. },{"2":2}],33:[function(_dereq_,module,exports){
  12468. (function (global){
  12469. 'use strict';
  12470. _dereq_(2);
  12471. _dereq_(6);
  12472. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12473. var UI = $.AMUI;
  12474. function accordionInit() {
  12475. var $accordion = $('[data-am-widget="accordion"]');
  12476. var selector = {
  12477. item: '.am-accordion-item',
  12478. title: '.am-accordion-title',
  12479. body: '.am-accordion-bd',
  12480. disabled: '.am-disabled'
  12481. };
  12482. $accordion.each(function(i, item) {
  12483. var options = UI.utils.parseOptions($(item).attr('data-am-accordion'));
  12484. var $title = $(item).find(selector.title);
  12485. $title.on('click.accordion.amui', function() {
  12486. var $collapse = $(this).next(selector.body);
  12487. var $parent = $(this).parent(selector.item);
  12488. var data = $collapse.data('amui.collapse');
  12489. if ($parent.is(selector.disabled)) {
  12490. return;
  12491. }
  12492. $parent.toggleClass('am-active');
  12493. if (!data) {
  12494. $collapse.collapse();
  12495. } else {
  12496. $collapse.collapse('toggle');
  12497. }
  12498. !options.multiple &&
  12499. $(item).children('.am-active').
  12500. not($parent).not(selector.disabled).removeClass('am-active').
  12501. find(selector.body + '.am-in').collapse('close');
  12502. });
  12503. });
  12504. }
  12505. // Init on DOM ready
  12506. $(accordionInit);
  12507. module.exports = $.AMUI.accordion = {
  12508. VERSION: '2.1.0',
  12509. init: accordionInit
  12510. };
  12511. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12512. },{"2":2,"6":6}],34:[function(_dereq_,module,exports){
  12513. 'use strict';
  12514. module.exports = {
  12515. VERSION: '2.0.1'
  12516. };
  12517. },{}],35:[function(_dereq_,module,exports){
  12518. (function (global){
  12519. 'use strict';
  12520. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12521. _dereq_(2);
  12522. function duoshuoInit() {
  12523. var $dsThread = $('.ds-thread');
  12524. var dsShortName = $dsThread.parent('[data-am-widget="duoshuo"]').
  12525. attr('data-ds-short-name');
  12526. var dsSrc = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
  12527. '//static.duoshuo.com/embed.js';
  12528. if (!$dsThread.length || !dsShortName) {
  12529. return;
  12530. }
  12531. window.duoshuoQuery = {
  12532. short_name: dsShortName
  12533. };
  12534. // 已经有多说脚本
  12535. if ($('script[src="' + dsSrc + '"]').length) {
  12536. return;
  12537. }
  12538. var $dsJS = $('<script>', {
  12539. async: true,
  12540. type: 'text/javascript',
  12541. src: dsSrc,
  12542. charset: 'utf-8'
  12543. });
  12544. $('body').append($dsJS);
  12545. }
  12546. $(window).on('load', duoshuoInit);
  12547. module.exports = $.AMUI.duoshuo = {
  12548. VERSION: '2.0.1',
  12549. init: duoshuoInit
  12550. };
  12551. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12552. },{"2":2}],36:[function(_dereq_,module,exports){
  12553. (function (global){
  12554. 'use strict';
  12555. _dereq_(2);
  12556. _dereq_(17);
  12557. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12558. var UI = $.AMUI;
  12559. /**
  12560. * Is Images zoomable
  12561. * @return {Boolean}
  12562. */
  12563. $.isImgZoomAble = function(element) {
  12564. var t = new Image();
  12565. t.src = element.src;
  12566. var zoomAble = ($(element).width() < t.width);
  12567. if (zoomAble) {
  12568. $(element).closest('.am-figure').addClass('am-figure-zoomable');
  12569. }
  12570. return zoomAble;
  12571. };
  12572. function figureInit() {
  12573. $('.am-figure').each(function(i, item) {
  12574. var options = UI.utils.parseOptions($(item).attr('data-am-figure'));
  12575. var $item = $(item);
  12576. var data;
  12577. if (options.pureview) {
  12578. if (options.pureview === 'auto') {
  12579. var zoomAble = $.isImgZoomAble($item.find('img')[0]);
  12580. zoomAble && $item.pureview();
  12581. } else {
  12582. $item.addClass('am-figure-zoomable').pureview();
  12583. }
  12584. }
  12585. data = $item.data('amui.pureview');
  12586. if (data) {
  12587. $item.on('click', ':not(img)', function() {
  12588. data.open(0);
  12589. });
  12590. }
  12591. });
  12592. }
  12593. $(window).on('load', figureInit);
  12594. module.exports = $.AMUI.figure = {
  12595. VERSION: '2.0.3',
  12596. init: figureInit
  12597. };
  12598. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12599. },{"17":17,"2":2}],37:[function(_dereq_,module,exports){
  12600. (function (global){
  12601. 'use strict';
  12602. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12603. var UI = _dereq_(2);
  12604. _dereq_(12);
  12605. var addToHS = _dereq_(3);
  12606. var cookie = _dereq_(27);
  12607. function footerInit() {
  12608. // modal mode
  12609. $('.am-footer-ysp').on('click', function() {
  12610. $('#am-footer-modal').modal();
  12611. });
  12612. var options = UI.utils.parseOptions($('.am-footer').data('amFooter'));
  12613. options.addToHS && addToHS();
  12614. // switch mode
  12615. // switch to desktop
  12616. $('[data-rel="desktop"]').on('click', function(e) {
  12617. e.preventDefault();
  12618. if (window.AMPlatform) { // front end
  12619. window.AMPlatform.util.goDesktop();
  12620. } else { // back end
  12621. cookie.set('allmobilize', 'desktop', '', '/');
  12622. window.location = window.location;
  12623. }
  12624. });
  12625. }
  12626. $(footerInit);
  12627. module.exports = $.AMUI.footer = {
  12628. VERSION: '3.1.2',
  12629. init: footerInit
  12630. };
  12631. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12632. },{"12":12,"2":2,"27":27,"3":3}],38:[function(_dereq_,module,exports){
  12633. (function (global){
  12634. 'use strict';
  12635. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12636. _dereq_(2);
  12637. _dereq_(17);
  12638. var UI = $.AMUI;
  12639. function galleryInit() {
  12640. var $gallery = $('[data-am-widget="gallery"]');
  12641. $gallery.each(function() {
  12642. var options = UI.utils.parseOptions($(this).attr('data-am-gallery'));
  12643. if (options.pureview) {
  12644. (typeof options.pureview === 'object') ?
  12645. $(this).pureview(options.pureview) : $(this).pureview();
  12646. }
  12647. });
  12648. }
  12649. $(galleryInit);
  12650. module.exports = $.AMUI.gallery = {
  12651. VERSION: '3.0.0',
  12652. init: galleryInit
  12653. };
  12654. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12655. },{"17":17,"2":2}],39:[function(_dereq_,module,exports){
  12656. (function (global){
  12657. 'use strict';
  12658. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12659. _dereq_(2);
  12660. _dereq_(22);
  12661. function goTopInit() {
  12662. var $goTop = $('[data-am-widget="gotop"]');
  12663. var $fixed = $goTop.filter('.am-gotop-fixed');
  12664. var $win = $(window);
  12665. if ($goTop.data('init')) {
  12666. return;
  12667. }
  12668. $goTop.find('a').on('click', function(e) {
  12669. e.preventDefault();
  12670. $win.smoothScroll();
  12671. });
  12672. function checkPosition() {
  12673. $fixed[($win.scrollTop() > 50 ? 'add' : 'remove') + 'Class']('am-active');
  12674. }
  12675. checkPosition();
  12676. $win.on('scroll.gotop.amui', $.AMUI.utils.debounce(checkPosition, 100));
  12677. $goTop.data('init', true);
  12678. }
  12679. $(goTopInit);
  12680. module.exports = $.AMUI.gotop = {
  12681. VERSION: '4.0.2',
  12682. init: goTopInit
  12683. };
  12684. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12685. },{"2":2,"22":22}],40:[function(_dereq_,module,exports){
  12686. (function (global){
  12687. 'use strict';
  12688. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12689. _dereq_(2);
  12690. function headerInit() {
  12691. $('[data-am-widget="header"]').each(function() {
  12692. if ($(this).hasClass('am-header-fixed')) {
  12693. $('body').addClass('am-with-fixed-header');
  12694. return false;
  12695. }
  12696. });
  12697. }
  12698. $(headerInit);
  12699. module.exports = $.AMUI.header = {
  12700. VERSION: '2.0.0',
  12701. init: headerInit
  12702. };
  12703. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12704. },{"2":2}],41:[function(_dereq_,module,exports){
  12705. (function (global){
  12706. 'use strict';
  12707. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12708. _dereq_(2);
  12709. module.exports = $.AMUI.intro = {
  12710. VERSION: '4.0.2',
  12711. init: function() {}
  12712. };
  12713. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12714. },{"2":2}],42:[function(_dereq_,module,exports){
  12715. (function (global){
  12716. 'use strict';
  12717. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12718. _dereq_(2);
  12719. module.exports = $.AMUI.listNews = {
  12720. VERSION: '4.0.0',
  12721. init: function() {}
  12722. };
  12723. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12724. },{"2":2}],43:[function(_dereq_,module,exports){
  12725. (function (global){
  12726. /* jshint strict: false, maxlen: 200 */
  12727. /* global BMap */
  12728. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12729. _dereq_(2);
  12730. function addMapApi(callback) {
  12731. var $mapApi0 = $('<script />', {
  12732. id: 'am-map-api-0'
  12733. });
  12734. $('body').append($mapApi0);
  12735. $mapApi0.on('load', function() {
  12736. console.log('load');
  12737. var $mapApi1 = $('<script/>', {
  12738. id: 'am-map-api-1'
  12739. });
  12740. $('body').append($mapApi1);
  12741. $mapApi1.on('load', function() {
  12742. var script = document.createElement('script');
  12743. script.textContent = '(' + callback.toString() + ')();';
  12744. $('body')[0].appendChild(script);
  12745. }).attr('src', 'http://api.map.baidu.com/getscript' +
  12746. '?type=quick&file=feature' +
  12747. '&ak=WVAXZ05oyNRXS5egLImmentg&t=20140109092002');
  12748. }).attr('src', 'http://api.map.baidu.com/getscript' +
  12749. '?type=quick&file=api&ak=WVAXZ05oyNRXS5egLImmentg&t=20140109092002');
  12750. // jQuery 中 `load` 事件触发有问题,动态设置 src 属性才会触发 `load` 事件
  12751. // $mapApi0 = $('<script />', {src: 'xxx'}); 这样的写法在 Zepto.js 中则没有问题
  12752. }
  12753. function addBdMap() {
  12754. // 如果使用 $ 选择符,minify 以后会报错: $ is undefined
  12755. // 即使传入 $ 也无效,改为使用原生方法
  12756. // 这个函数作为 callback 会插入到 body 以后才执行,应该是 $ 引用错误导致
  12757. var content = document.querySelector('.am-map');
  12758. var defaultLng = 116.331398; // 经度默认值
  12759. var defaultLat = 39.897445; // 纬度默认值
  12760. var name = content.getAttribute('data-name');
  12761. var address = content.getAttribute('data-address');
  12762. var lng = content.getAttribute('data-longitude') || defaultLng;
  12763. var lat = content.getAttribute('data-latitude') || defaultLat;
  12764. var setZoom = content.getAttribute('data-setZoom') || 17;
  12765. var icon = content.getAttribute('data-icon');
  12766. var map = new BMap.Map('bd-map');
  12767. // 实例化一个地理坐标点
  12768. var point = new BMap.Point(lng, lat);
  12769. // 设初始化地图, options: 3-18
  12770. map.centerAndZoom(point, setZoom);
  12771. // 添加地图缩放控件
  12772. if (content.getAttribute('data-zoomControl')) {
  12773. map.addControl(new BMap.ZoomControl());
  12774. }
  12775. // 添加比例尺控件
  12776. if (content.getAttribute('data-scaleControl')) {
  12777. map.addControl(new BMap.ScaleControl());
  12778. }
  12779. // 创建标准与自定义 icon
  12780. var marker = new BMap.Marker(point);
  12781. if (icon) {
  12782. marker.setIcon(new BMap.Icon(icon, new BMap.Size(40, 40)));
  12783. }
  12784. var opts = {
  12785. width: 200, // 信息窗口宽度
  12786. // height: 'auto', // 信息窗口高度
  12787. title: name // 信息窗口标题
  12788. };
  12789. // 创建信息窗口对象
  12790. var infoWindow = new BMap.InfoWindow('地址:' + address, opts);
  12791. // 创建地址解析器实例
  12792. var myGeo = new BMap.Geocoder();
  12793. // 判断有没有使用经纬度
  12794. if (lng == defaultLng && lat == defaultLat) {
  12795. // 使用地址反解析来设置地图
  12796. // 将地址解析结果显示在地图上,并调整地图视野
  12797. myGeo.getPoint(address, function(point) {
  12798. if (point) {
  12799. map.centerAndZoom(point, setZoom);
  12800. marker.setPosition(point);
  12801. map.addOverlay(marker);
  12802. map.openInfoWindow(infoWindow, point); // 开启信息窗口
  12803. }
  12804. }, '');
  12805. } else {
  12806. // 使用经纬度来设置地图
  12807. myGeo.getLocation(point, function(result) {
  12808. map.centerAndZoom(point, setZoom);
  12809. marker.setPosition(point);
  12810. map.addOverlay(marker);
  12811. if (address) {
  12812. map.openInfoWindow(infoWindow, point); // 开启信息窗口
  12813. } else {
  12814. map.openInfoWindow(new BMap.InfoWindow(address, opts), point); // 开启信息窗口
  12815. }
  12816. });
  12817. }
  12818. }
  12819. var mapInit = function() {
  12820. $('.am-map').length && addMapApi(addBdMap);
  12821. };
  12822. $(mapInit);
  12823. module.exports = $.AMUI.map = {
  12824. VERSION: '2.0.2',
  12825. init: mapInit
  12826. };
  12827. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12828. },{"2":2}],44:[function(_dereq_,module,exports){
  12829. (function (global){
  12830. 'use strict';
  12831. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12832. _dereq_(2);
  12833. function mechatInit() {
  12834. if (!$('#mechat').length) {
  12835. return;
  12836. }
  12837. var $mechat = $('[data-am-widget="mechat"]');
  12838. var unitid = $mechat.data('am-mechat-unitid');
  12839. var $mechatData = $('<script>', {
  12840. charset: 'utf-8',
  12841. src: 'http://mechatim.com/js/unit/button.js?id=' + unitid
  12842. });
  12843. $('body').append($mechatData);
  12844. }
  12845. // Lazy load
  12846. $(window).on('load', mechatInit);
  12847. module.exports = $.AMUI.mechat = {
  12848. VERSION: '2.0.1',
  12849. init: mechatInit
  12850. };
  12851. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12852. },{"2":2}],45:[function(_dereq_,module,exports){
  12853. (function (global){
  12854. 'use strict';
  12855. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12856. _dereq_(2);
  12857. _dereq_(13);
  12858. _dereq_(6);
  12859. var IScroll = _dereq_(11);
  12860. var menuInit = function() {
  12861. var $menus = $('[data-am-widget="menu"]');
  12862. $menus.find('.am-menu-nav .am-parent > a').on('click', function(e) {
  12863. e.preventDefault();
  12864. var $clicked = $(this);
  12865. var $parent = $clicked.parent();
  12866. var $subMenu = $clicked.next('.am-menu-sub');
  12867. $parent.toggleClass('am-open');
  12868. $subMenu.collapse('toggle');
  12869. $parent.siblings('.am-parent').removeClass('am-open')
  12870. .children('.am-menu-sub.am-in').collapse('close');
  12871. });
  12872. // Dropdown/slideDown menu
  12873. $menus.
  12874. filter('[data-am-menu-collapse]').
  12875. find('> .am-menu-toggle').
  12876. on('click', function(e) {
  12877. e.preventDefault();
  12878. var $this = $(this);
  12879. var $nav = $this.next('.am-menu-nav');
  12880. $this.toggleClass('am-active');
  12881. $nav.collapse('toggle');
  12882. });
  12883. // OffCanvas menu
  12884. $menus.
  12885. filter('[data-am-menu-offcanvas]').
  12886. find('> .am-menu-toggle').
  12887. on('click', function(e) {
  12888. e.preventDefault();
  12889. var $this = $(this);
  12890. var $nav = $this.next('.am-offcanvas');
  12891. $this.toggleClass('am-active');
  12892. $nav.offCanvas('open');
  12893. });
  12894. // Close offCanvas when link clicked
  12895. var autoCloseOffCanvas = '.am-offcanvas[data-dismiss-on="click"]';
  12896. var $autoCloseOffCanvas = $(autoCloseOffCanvas);
  12897. $autoCloseOffCanvas.find('a').not('.am-parent>a').on('click', function(e) {
  12898. $(this).parents(autoCloseOffCanvas).offCanvas('close');
  12899. });
  12900. // one theme
  12901. $menus.filter('.am-menu-one').each(function(index) {
  12902. var $this = $(this);
  12903. var $wrap = $('<div class="am-menu-nav-sub-wrap"></div>');
  12904. var allWidth = 0;
  12905. var $nav = $this.find('.am-menu-nav');
  12906. var $navTopItem = $nav.children('li');
  12907. var prevIndex;
  12908. $navTopItem.filter('.am-parent').each(function(index) {
  12909. $(this).attr('data-rel', '#am-menu-sub-' + index);
  12910. $(this).
  12911. find('.am-menu-sub').
  12912. attr('id', 'am-menu-sub-' + index).
  12913. appendTo($wrap);
  12914. });
  12915. $this.append($wrap);
  12916. $nav.wrap('<div class="am-menu-nav-wrap" id="am-menu-' + index + '">');
  12917. // $navTopItem.eq(0).addClass('am-active');
  12918. // 计算出所有 li 宽度
  12919. $navTopItem.each(function(i) {
  12920. allWidth += parseFloat($(this).css('width'));
  12921. });
  12922. $nav.width(allWidth);
  12923. var menuScroll = new IScroll('#am-menu-' + index, {
  12924. eventPassthrough: true,
  12925. scrollX: true,
  12926. scrollY: false,
  12927. preventDefault: false
  12928. });
  12929. $navTopItem.on('click', function() {
  12930. var $clicked = $(this);
  12931. $clicked.addClass('am-active').siblings().removeClass('am-active');
  12932. $wrap.find('.am-menu-sub.am-in').collapse('close');
  12933. if ($clicked.is('.am-parent')) {
  12934. !$clicked.hasClass('.am-open') &&
  12935. $wrap.find($clicked.attr('data-rel')).collapse('open');
  12936. } else {
  12937. $clicked.siblings().removeClass('am-open');
  12938. }
  12939. // 第一次调用,没有prevIndex
  12940. if (prevIndex === undefined) {
  12941. prevIndex = $(this).index() ? 0 : 1;
  12942. }
  12943. // 判断方向
  12944. var dir = $(this).index() > prevIndex;
  12945. var target = $(this)[dir ? 'next' : 'prev']();
  12946. // 点击的按钮,显示一半
  12947. var offset = target.offset() || $(this).offset();
  12948. var within = $this.offset();
  12949. // 父类左边距
  12950. var listOffset;
  12951. var parentLeft = parseInt($this.css('padding-left'));
  12952. if (dir ? offset.left + offset.width > within.left + within.width :
  12953. offset.left < within.left) {
  12954. listOffset = $nav.offset();
  12955. menuScroll.scrollTo(dir ?
  12956. within.width - offset.left + listOffset.left -
  12957. offset.width - parentLeft :
  12958. listOffset.left - offset.left, 0, 400);
  12959. }
  12960. prevIndex = $(this).index();
  12961. });
  12962. $this.on('touchmove', function(event) {
  12963. event.preventDefault();
  12964. });
  12965. });
  12966. };
  12967. $(menuInit);
  12968. module.exports = $.AMUI.menu = {
  12969. VERSION: '4.0.3',
  12970. init: menuInit
  12971. };
  12972. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  12973. },{"11":11,"13":13,"2":2,"6":6}],46:[function(_dereq_,module,exports){
  12974. (function (global){
  12975. 'use strict';
  12976. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  12977. _dereq_(2);
  12978. _dereq_(12);
  12979. var share = _dereq_(21);
  12980. var QRCode = _dereq_(31);
  12981. var UI = $.AMUI;
  12982. function navbarInit() {
  12983. var $navBar = $('[data-am-widget="navbar"]');
  12984. if (!$navBar.length) {
  12985. return;
  12986. }
  12987. var $win = $(window);
  12988. var $body = $('body');
  12989. var $navBarNav = $navBar.find('.am-navbar-nav');
  12990. var $navItems = $navBar.find('li');
  12991. var navItemsCounter = $navItems.length;
  12992. var configItems = $navBarNav.attr('class') &&
  12993. parseInt($navBarNav.attr('class').
  12994. match(/am-avg-sm-(\d+)/)[1]) || 3;
  12995. var navMinWidth = 60; // 每个 li 最小宽度
  12996. var offsetWidth = 16;
  12997. var $share = $navItems.filter('[data-am-navbar-share]');
  12998. var $qrcode = $navItems.filter('[data-am-navbar-qrcode]');
  12999. var activeStatus = 'am-active';
  13000. var $moreActions = $('<ul class="am-navbar-actions"></ul>', {
  13001. id: UI.utils.generateGUID('am-navbar-actions')
  13002. });
  13003. var $moreLink = $('<li class="am-navbar-labels am-navbar-more">' +
  13004. '<a href="javascript: void(0);">' +
  13005. '<span class="am-icon-angle-up"></span>' +
  13006. '<span class="am-navbar-label">更多</span></a></li>');
  13007. // 如果有 Fix 的工具栏则设置 body 的 padding-bottom
  13008. if ($navBar.css('position') == 'fixed') {
  13009. $body.addClass('am-with-fixed-navbar');
  13010. }
  13011. if ($qrcode.length) {
  13012. var qrId = 'am-navbar-qrcode';
  13013. $qrModal = $('#' + qrId);
  13014. if (!$qrModal.length) {
  13015. var qrImg = $qrcode.attr('data-am-navbar-qrcode');
  13016. var $qrModal = $('<div class="am-modal am-modal-no-btn" id="">' +
  13017. '<div class="am-modal-dialog">' +
  13018. '<div class="am-modal-bd"></div></div>' +
  13019. '</div>', {
  13020. id: qrId
  13021. });
  13022. var $qrContainer = $qrModal.find('.am-modal-bd');
  13023. // 判断上传自定义的二维码没有,否则生成二维码
  13024. if (qrImg) {
  13025. $qrContainer.html('<img src="' + qrImg + '"/>');
  13026. } else {
  13027. var qrnode = new QRCode({
  13028. render: 'canvas',
  13029. correctLevel: 0,
  13030. text: window.location.href,
  13031. width: 200,
  13032. height: 200,
  13033. background: '#fff',
  13034. foreground: '#000'
  13035. });
  13036. $qrContainer.html(qrnode);
  13037. }
  13038. $body.append($qrModal);
  13039. }
  13040. $qrcode.on('click', function(e) {
  13041. e.preventDefault();
  13042. $qrModal.modal();
  13043. });
  13044. }
  13045. if (navItemsCounter > configItems && navItemsCounter > calcSuiteItems()) {
  13046. initActions();
  13047. }
  13048. // console.log('NavItems: %d, config: %d, best: %d',
  13049. // navItemsCounter, configItems, calcSuiteItems());
  13050. function initActions() {
  13051. $navBarNav.append($moreLink);
  13052. $navBarNav.
  13053. find('li').
  13054. not('.am-navbar-more').
  13055. slice(calcSuiteItems() - 1).
  13056. appendTo($moreActions);
  13057. // Append more actions
  13058. $navBar.append($moreActions);
  13059. }
  13060. function checkNavBarItems() {
  13061. if (calcSuiteItems() >= navItemsCounter) {
  13062. // 显示所有链接,隐藏 more
  13063. $moreLink.hide();
  13064. $moreActions.find('li').insertBefore($moreLink);
  13065. return;
  13066. }
  13067. !$navBar.find('.am-navbar-actions').length && initActions();
  13068. $moreLink.show();
  13069. if ($navBarNav.find('li').length < calcSuiteItems()) {
  13070. $moreActions.find('li').
  13071. slice(0, calcSuiteItems() - $navBarNav.find('li').length).
  13072. insertBefore($moreLink);
  13073. } else if ($navBarNav.find('li').length > calcSuiteItems()) {
  13074. if ($moreActions.find('li').length) {
  13075. $navBarNav.find('li').not($moreLink).slice(calcSuiteItems() - 1).
  13076. insertBefore($moreActions.find('li').first());
  13077. } else {
  13078. $navBarNav.find('li').not($moreLink).slice(calcSuiteItems() - 1).
  13079. appendTo($moreActions);
  13080. }
  13081. }
  13082. }
  13083. /**
  13084. * 计算最适合显示的条目个数
  13085. * @returns {number}
  13086. */
  13087. function calcSuiteItems() {
  13088. return Math.floor(($win.width() - offsetWidth) / navMinWidth);
  13089. }
  13090. $navBar.on('click.navbar.amui', '.am-navbar-more', function(e) {
  13091. e.preventDefault();
  13092. $moreLink[$moreActions.hasClass(activeStatus) ?
  13093. 'removeClass' : 'addClass'](activeStatus);
  13094. $moreActions.toggleClass(activeStatus);
  13095. });
  13096. if ($share.length) {
  13097. $share.on('click.navbar.amui', function(e) {
  13098. e.preventDefault();
  13099. share.toggle();
  13100. });
  13101. }
  13102. $win.on('resize.navbar.amui orientationchange.navbar.amui',
  13103. UI.utils.debounce(checkNavBarItems, 150));
  13104. }
  13105. // DOMContent ready
  13106. $(navbarInit);
  13107. module.exports = $.AMUI.navbar = {
  13108. VERSION: '2.0.2',
  13109. init: navbarInit
  13110. };
  13111. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13112. },{"12":12,"2":2,"21":21,"31":31}],47:[function(_dereq_,module,exports){
  13113. (function (global){
  13114. 'use strict';
  13115. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  13116. _dereq_(2);
  13117. module.exports = $.AMUI.pagination = {
  13118. VERSION: '3.0.1'
  13119. };
  13120. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13121. },{"2":2}],48:[function(_dereq_,module,exports){
  13122. (function (global){
  13123. 'use strict';
  13124. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  13125. _dereq_(2);
  13126. _dereq_(17);
  13127. var IScroll = _dereq_(11);
  13128. var UI = $.AMUI;
  13129. /**
  13130. * 表格滚动
  13131. * @param {number} index ID 标识,多个 paragraph 里面多个 table
  13132. */
  13133. $.fn.scrollTable = function(index) {
  13134. var $this = $(this);
  13135. var $parent;
  13136. $this.wrap('<div class="am-paragraph-table-container" ' +
  13137. 'id="am-paragraph-table-' + index + '">' +
  13138. '<div class="am-paragraph-table-scroller"></div></div>');
  13139. $parent = $this.parent();
  13140. $parent.width($this.width());
  13141. $parent.height($this.height());
  13142. new IScroll('#am-paragraph-table-' + index, {
  13143. eventPassthrough: true,
  13144. scrollX: true,
  13145. scrollY: false,
  13146. preventDefault: false
  13147. });
  13148. };
  13149. function paragraphInit() {
  13150. var $paragraph = $('[data-am-widget="paragraph"]');
  13151. $paragraph.each(function(index) {
  13152. var $this = $(this);
  13153. var options = UI.utils.parseOptions($this.attr('data-am-paragraph'));
  13154. var $index = index;
  13155. if (options.pureview) {
  13156. $this.pureview();
  13157. }
  13158. if (options.tableScrollable) {
  13159. $this.find('table').each(function(index) {
  13160. if ($(this).width() > $(window).width()) {
  13161. $(this).scrollTable($index + '-' + index);
  13162. }
  13163. });
  13164. }
  13165. });
  13166. }
  13167. $(window).on('load', paragraphInit);
  13168. module.exports = $.AMUI.paragraph = {
  13169. VERSION: '2.0.1',
  13170. init: paragraphInit
  13171. };
  13172. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13173. },{"11":11,"17":17,"2":2}],49:[function(_dereq_,module,exports){
  13174. (function (global){
  13175. 'use strict';
  13176. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  13177. _dereq_(2);
  13178. _dereq_(10);
  13179. var UI = $.AMUI;
  13180. function sliderInit() {
  13181. var $sliders = $('[data-am-widget="slider"]');
  13182. $sliders.not('.am-slider-manual').each(function(i, item) {
  13183. var options = UI.utils.parseOptions($(item).attr('data-am-slider'));
  13184. $(item).flexslider(options);
  13185. });
  13186. }
  13187. $(sliderInit);
  13188. module.exports = $.AMUI.slider = {
  13189. VERSION: '3.0.1',
  13190. init: sliderInit
  13191. };
  13192. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13193. },{"10":10,"2":2}],50:[function(_dereq_,module,exports){
  13194. (function (global){
  13195. 'use strict';
  13196. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  13197. _dereq_(2);
  13198. _dereq_(24);
  13199. function tabsInit() {
  13200. $('[data-am-widget="tabs"]').each(function() {
  13201. var options = $(this).data('amTabsNoswipe') ? {noSwipe: 1} : {};
  13202. $(this).tabs(options);
  13203. });
  13204. }
  13205. $(tabsInit);
  13206. module.exports = $.AMUI.tab = {
  13207. VERSION: '4.0.1',
  13208. init: tabsInit
  13209. };
  13210. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13211. },{"2":2,"24":24}],51:[function(_dereq_,module,exports){
  13212. (function (global){
  13213. 'use strict';
  13214. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  13215. _dereq_(2);
  13216. module.exports = $.AMUI.titlebar = {
  13217. VERSION: '4.0.1'
  13218. };
  13219. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13220. },{"2":2}],52:[function(_dereq_,module,exports){
  13221. (function (global){
  13222. 'use strict';
  13223. var $ = (typeof window !== "undefined" ? window.jQuery : typeof global !== "undefined" ? global.jQuery : null);
  13224. var UI = _dereq_(2);
  13225. var isWeChat = window.navigator.userAgent.indexOf('MicroMessenger') > -1;
  13226. function appendWeChatSDK(callback) {
  13227. var $weChatSDK = $('<script/>', {
  13228. id: 'wechat-sdk'
  13229. });
  13230. $('body').append($weChatSDK);
  13231. $weChatSDK.on('load', function() {
  13232. callback && callback();
  13233. }).attr('src', 'http://res.wx.qq.com/open/js/jweixin-1.0.0.js');
  13234. }
  13235. function payHandler() {
  13236. var $paymentBtn = $('[data-am-widget="wechatpay"]');
  13237. if (!isWeChat) {
  13238. $paymentBtn.hide();
  13239. return false;
  13240. }
  13241. $paymentBtn.on('click', '.am-wechatpay-btn', function(e) {
  13242. e.preventDefault();
  13243. var options = UI.utils.parseOptions($(this).parent().data('wechatPay'));
  13244. // console.log(options);
  13245. // alert('pay button clicked');
  13246. if (!window.wx) {
  13247. alert('没有微信 JS SDK');
  13248. return;
  13249. }
  13250. wx.checkJsApi({
  13251. jsApiList: ['chooseWXPay'],
  13252. success: function(res) {
  13253. if (res.checkResult.chooseWXPay) {
  13254. wx.chooseWXPay(options);
  13255. } else {
  13256. alert('微信版本不支持支付接口或没有开启!');
  13257. }
  13258. },
  13259. fail: function() {
  13260. alert('调用 checkJsApi 接口时发生错误!');
  13261. }
  13262. });
  13263. });
  13264. }
  13265. var payInit = payHandler;
  13266. // Init on DOM ready
  13267. $(payInit);
  13268. module.exports = $.AMUI.pay = {
  13269. VERSION: '1.0.0',
  13270. init: payInit
  13271. };
  13272. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  13273. },{"2":2}]},{},[1])(1)
  13274. });