ionic.js 460 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356
  1. /*!
  2. * Copyright 2015 Drifty Co.
  3. * http://drifty.com/
  4. *
  5. * Ionic, v1.3.1
  6. * A powerful HTML5 mobile app framework.
  7. * http://ionicframework.com/
  8. *
  9. * By @maxlynch, @benjsperry, @adamdbradley <3
  10. *
  11. * Licensed under the MIT license. Please see LICENSE for more information.
  12. *
  13. */
  14. (function() {
  15. // Create global ionic obj and its namespaces
  16. // build processes may have already created an ionic obj
  17. window.ionic = window.ionic || {};
  18. window.ionic.views = {};
  19. window.ionic.version = '1.3.1';
  20. (function (ionic) {
  21. ionic.DelegateService = function(methodNames) {
  22. if (methodNames.indexOf('$getByHandle') > -1) {
  23. throw new Error("Method '$getByHandle' is implicitly added to each delegate service. Do not list it as a method.");
  24. }
  25. function trueFn() { return true; }
  26. return ['$log', function($log) {
  27. /*
  28. * Creates a new object that will have all the methodNames given,
  29. * and call them on the given the controller instance matching given
  30. * handle.
  31. * The reason we don't just let $getByHandle return the controller instance
  32. * itself is that the controller instance might not exist yet.
  33. *
  34. * We want people to be able to do
  35. * `var instance = $ionicScrollDelegate.$getByHandle('foo')` on controller
  36. * instantiation, but on controller instantiation a child directive
  37. * may not have been compiled yet!
  38. *
  39. * So this is our way of solving this problem: we create an object
  40. * that will only try to fetch the controller with given handle
  41. * once the methods are actually called.
  42. */
  43. function DelegateInstance(instances, handle) {
  44. this._instances = instances;
  45. this.handle = handle;
  46. }
  47. methodNames.forEach(function(methodName) {
  48. DelegateInstance.prototype[methodName] = instanceMethodCaller(methodName);
  49. });
  50. /**
  51. * The delegate service (eg $ionicNavBarDelegate) is just an instance
  52. * with a non-defined handle, a couple extra methods for registering
  53. * and narrowing down to a specific handle.
  54. */
  55. function DelegateService() {
  56. this._instances = [];
  57. }
  58. DelegateService.prototype = DelegateInstance.prototype;
  59. DelegateService.prototype._registerInstance = function(instance, handle, filterFn) {
  60. var instances = this._instances;
  61. instance.$$delegateHandle = handle;
  62. instance.$$filterFn = filterFn || trueFn;
  63. instances.push(instance);
  64. return function deregister() {
  65. var index = instances.indexOf(instance);
  66. if (index !== -1) {
  67. instances.splice(index, 1);
  68. }
  69. };
  70. };
  71. DelegateService.prototype.$getByHandle = function(handle) {
  72. return new DelegateInstance(this._instances, handle);
  73. };
  74. return new DelegateService();
  75. function instanceMethodCaller(methodName) {
  76. return function caller() {
  77. var handle = this.handle;
  78. var args = arguments;
  79. var foundInstancesCount = 0;
  80. var returnValue;
  81. this._instances.forEach(function(instance) {
  82. if ((!handle || handle == instance.$$delegateHandle) && instance.$$filterFn(instance)) {
  83. foundInstancesCount++;
  84. var ret = instance[methodName].apply(instance, args);
  85. //Only return the value from the first call
  86. if (foundInstancesCount === 1) {
  87. returnValue = ret;
  88. }
  89. }
  90. });
  91. if (!foundInstancesCount && handle) {
  92. return $log.warn(
  93. 'Delegate for handle "' + handle + '" could not find a ' +
  94. 'corresponding element with delegate-handle="' + handle + '"! ' +
  95. methodName + '() was not called!\n' +
  96. 'Possible cause: If you are calling ' + methodName + '() immediately, and ' +
  97. 'your element with delegate-handle="' + handle + '" is a child of your ' +
  98. 'controller, then your element may not be compiled yet. Put a $timeout ' +
  99. 'around your call to ' + methodName + '() and try again.'
  100. );
  101. }
  102. return returnValue;
  103. };
  104. }
  105. }];
  106. };
  107. })(window.ionic);
  108. (function(window, document, ionic) {
  109. var readyCallbacks = [];
  110. var isDomReady = document.readyState === 'complete' || document.readyState === 'interactive';
  111. function domReady() {
  112. isDomReady = true;
  113. for (var x = 0; x < readyCallbacks.length; x++) {
  114. ionic.requestAnimationFrame(readyCallbacks[x]);
  115. }
  116. readyCallbacks = [];
  117. document.removeEventListener('DOMContentLoaded', domReady);
  118. }
  119. if (!isDomReady) {
  120. document.addEventListener('DOMContentLoaded', domReady);
  121. }
  122. // From the man himself, Mr. Paul Irish.
  123. // The requestAnimationFrame polyfill
  124. // Put it on window just to preserve its context
  125. // without having to use .call
  126. window._rAF = (function() {
  127. return window.requestAnimationFrame ||
  128. window.webkitRequestAnimationFrame ||
  129. window.mozRequestAnimationFrame ||
  130. function(callback) {
  131. window.setTimeout(callback, 16);
  132. };
  133. })();
  134. var cancelAnimationFrame = window.cancelAnimationFrame ||
  135. window.webkitCancelAnimationFrame ||
  136. window.mozCancelAnimationFrame ||
  137. window.webkitCancelRequestAnimationFrame;
  138. /**
  139. * @ngdoc utility
  140. * @name ionic.DomUtil
  141. * @module ionic
  142. */
  143. ionic.DomUtil = {
  144. //Call with proper context
  145. /**
  146. * @ngdoc method
  147. * @name ionic.DomUtil#requestAnimationFrame
  148. * @alias ionic.requestAnimationFrame
  149. * @description Calls [requestAnimationFrame](https://developer.mozilla.org/en-US/docs/Web/API/window.requestAnimationFrame), or a polyfill if not available.
  150. * @param {function} callback The function to call when the next frame
  151. * happens.
  152. */
  153. requestAnimationFrame: function(cb) {
  154. return window._rAF(cb);
  155. },
  156. cancelAnimationFrame: function(requestId) {
  157. cancelAnimationFrame(requestId);
  158. },
  159. /**
  160. * @ngdoc method
  161. * @name ionic.DomUtil#animationFrameThrottle
  162. * @alias ionic.animationFrameThrottle
  163. * @description
  164. * When given a callback, if that callback is called 100 times between
  165. * animation frames, adding Throttle will make it only run the last of
  166. * the 100 calls.
  167. *
  168. * @param {function} callback a function which will be throttled to
  169. * requestAnimationFrame
  170. * @returns {function} A function which will then call the passed in callback.
  171. * The passed in callback will receive the context the returned function is
  172. * called with.
  173. */
  174. animationFrameThrottle: function(cb) {
  175. var args, isQueued, context;
  176. return function() {
  177. args = arguments;
  178. context = this;
  179. if (!isQueued) {
  180. isQueued = true;
  181. ionic.requestAnimationFrame(function() {
  182. cb.apply(context, args);
  183. isQueued = false;
  184. });
  185. }
  186. };
  187. },
  188. contains: function(parentNode, otherNode) {
  189. var current = otherNode;
  190. while (current) {
  191. if (current === parentNode) return true;
  192. current = current.parentNode;
  193. }
  194. },
  195. /**
  196. * @ngdoc method
  197. * @name ionic.DomUtil#getPositionInParent
  198. * @description
  199. * Find an element's scroll offset within its container.
  200. * @param {DOMElement} element The element to find the offset of.
  201. * @returns {object} A position object with the following properties:
  202. * - `{number}` `left` The left offset of the element.
  203. * - `{number}` `top` The top offset of the element.
  204. */
  205. getPositionInParent: function(el) {
  206. return {
  207. left: el.offsetLeft,
  208. top: el.offsetTop
  209. };
  210. },
  211. getOffsetTop: function(el) {
  212. var curtop = 0;
  213. if (el.offsetParent) {
  214. do {
  215. curtop += el.offsetTop;
  216. el = el.offsetParent;
  217. } while (el)
  218. return curtop;
  219. }
  220. },
  221. /**
  222. * @ngdoc method
  223. * @name ionic.DomUtil#ready
  224. * @description
  225. * Call a function when the DOM is ready, or if it is already ready
  226. * call the function immediately.
  227. * @param {function} callback The function to be called.
  228. */
  229. ready: function(cb) {
  230. if (isDomReady) {
  231. ionic.requestAnimationFrame(cb);
  232. } else {
  233. readyCallbacks.push(cb);
  234. }
  235. },
  236. /**
  237. * @ngdoc method
  238. * @name ionic.DomUtil#getTextBounds
  239. * @description
  240. * Get a rect representing the bounds of the given textNode.
  241. * @param {DOMElement} textNode The textNode to find the bounds of.
  242. * @returns {object} An object representing the bounds of the node. Properties:
  243. * - `{number}` `left` The left position of the textNode.
  244. * - `{number}` `right` The right position of the textNode.
  245. * - `{number}` `top` The top position of the textNode.
  246. * - `{number}` `bottom` The bottom position of the textNode.
  247. * - `{number}` `width` The width of the textNode.
  248. * - `{number}` `height` The height of the textNode.
  249. */
  250. getTextBounds: function(textNode) {
  251. if (document.createRange) {
  252. var range = document.createRange();
  253. range.selectNodeContents(textNode);
  254. if (range.getBoundingClientRect) {
  255. var rect = range.getBoundingClientRect();
  256. if (rect) {
  257. var sx = window.scrollX;
  258. var sy = window.scrollY;
  259. return {
  260. top: rect.top + sy,
  261. left: rect.left + sx,
  262. right: rect.left + sx + rect.width,
  263. bottom: rect.top + sy + rect.height,
  264. width: rect.width,
  265. height: rect.height
  266. };
  267. }
  268. }
  269. }
  270. return null;
  271. },
  272. /**
  273. * @ngdoc method
  274. * @name ionic.DomUtil#getChildIndex
  275. * @description
  276. * Get the first index of a child node within the given element of the
  277. * specified type.
  278. * @param {DOMElement} element The element to find the index of.
  279. * @param {string} type The nodeName to match children of element against.
  280. * @returns {number} The index, or -1, of a child with nodeName matching type.
  281. */
  282. getChildIndex: function(element, type) {
  283. if (type) {
  284. var ch = element.parentNode.children;
  285. var c;
  286. for (var i = 0, k = 0, j = ch.length; i < j; i++) {
  287. c = ch[i];
  288. if (c.nodeName && c.nodeName.toLowerCase() == type) {
  289. if (c == element) {
  290. return k;
  291. }
  292. k++;
  293. }
  294. }
  295. }
  296. return Array.prototype.slice.call(element.parentNode.children).indexOf(element);
  297. },
  298. /**
  299. * @private
  300. */
  301. swapNodes: function(src, dest) {
  302. dest.parentNode.insertBefore(src, dest);
  303. },
  304. elementIsDescendant: function(el, parent, stopAt) {
  305. var current = el;
  306. do {
  307. if (current === parent) return true;
  308. current = current.parentNode;
  309. } while (current && current !== stopAt);
  310. return false;
  311. },
  312. /**
  313. * @ngdoc method
  314. * @name ionic.DomUtil#getParentWithClass
  315. * @param {DOMElement} element
  316. * @param {string} className
  317. * @returns {DOMElement} The closest parent of element matching the
  318. * className, or null.
  319. */
  320. getParentWithClass: function(e, className, depth) {
  321. depth = depth || 10;
  322. while (e.parentNode && depth--) {
  323. if (e.parentNode.classList && e.parentNode.classList.contains(className)) {
  324. return e.parentNode;
  325. }
  326. e = e.parentNode;
  327. }
  328. return null;
  329. },
  330. /**
  331. * @ngdoc method
  332. * @name ionic.DomUtil#getParentOrSelfWithClass
  333. * @param {DOMElement} element
  334. * @param {string} className
  335. * @returns {DOMElement} The closest parent or self matching the
  336. * className, or null.
  337. */
  338. getParentOrSelfWithClass: function(e, className, depth) {
  339. depth = depth || 10;
  340. while (e && depth--) {
  341. if (e.classList && e.classList.contains(className)) {
  342. return e;
  343. }
  344. e = e.parentNode;
  345. }
  346. return null;
  347. },
  348. /**
  349. * @ngdoc method
  350. * @name ionic.DomUtil#rectContains
  351. * @param {number} x
  352. * @param {number} y
  353. * @param {number} x1
  354. * @param {number} y1
  355. * @param {number} x2
  356. * @param {number} y2
  357. * @returns {boolean} Whether {x,y} fits within the rectangle defined by
  358. * {x1,y1,x2,y2}.
  359. */
  360. rectContains: function(x, y, x1, y1, x2, y2) {
  361. if (x < x1 || x > x2) return false;
  362. if (y < y1 || y > y2) return false;
  363. return true;
  364. },
  365. /**
  366. * @ngdoc method
  367. * @name ionic.DomUtil#blurAll
  368. * @description
  369. * Blurs any currently focused input element
  370. * @returns {DOMElement} The element blurred or null
  371. */
  372. blurAll: function() {
  373. if (document.activeElement && document.activeElement != document.body) {
  374. document.activeElement.blur();
  375. return document.activeElement;
  376. }
  377. return null;
  378. },
  379. cachedAttr: function(ele, key, value) {
  380. ele = ele && ele.length && ele[0] || ele;
  381. if (ele && ele.setAttribute) {
  382. var dataKey = '$attr-' + key;
  383. if (arguments.length > 2) {
  384. if (ele[dataKey] !== value) {
  385. ele.setAttribute(key, value);
  386. ele[dataKey] = value;
  387. }
  388. } else if (typeof ele[dataKey] == 'undefined') {
  389. ele[dataKey] = ele.getAttribute(key);
  390. }
  391. return ele[dataKey];
  392. }
  393. },
  394. cachedStyles: function(ele, styles) {
  395. ele = ele && ele.length && ele[0] || ele;
  396. if (ele && ele.style) {
  397. for (var prop in styles) {
  398. if (ele['$style-' + prop] !== styles[prop]) {
  399. ele.style[prop] = ele['$style-' + prop] = styles[prop];
  400. }
  401. }
  402. }
  403. }
  404. };
  405. //Shortcuts
  406. ionic.requestAnimationFrame = ionic.DomUtil.requestAnimationFrame;
  407. ionic.cancelAnimationFrame = ionic.DomUtil.cancelAnimationFrame;
  408. ionic.animationFrameThrottle = ionic.DomUtil.animationFrameThrottle;
  409. })(window, document, ionic);
  410. /**
  411. * ion-events.js
  412. *
  413. * Author: Max Lynch <max@drifty.com>
  414. *
  415. * Framework events handles various mobile browser events, and
  416. * detects special events like tap/swipe/etc. and emits them
  417. * as custom events that can be used in an app.
  418. *
  419. * Portions lovingly adapted from github.com/maker/ratchet and github.com/alexgibson/tap.js - thanks guys!
  420. */
  421. (function(ionic) {
  422. // Custom event polyfill
  423. ionic.CustomEvent = (function() {
  424. if( typeof window.CustomEvent === 'function' ) return CustomEvent;
  425. var customEvent = function(event, params) {
  426. var evt;
  427. params = params || {
  428. bubbles: false,
  429. cancelable: false,
  430. detail: undefined
  431. };
  432. try {
  433. evt = document.createEvent("CustomEvent");
  434. evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
  435. } catch (error) {
  436. // fallback for browsers that don't support createEvent('CustomEvent')
  437. evt = document.createEvent("Event");
  438. for (var param in params) {
  439. evt[param] = params[param];
  440. }
  441. evt.initEvent(event, params.bubbles, params.cancelable);
  442. }
  443. return evt;
  444. };
  445. customEvent.prototype = window.Event.prototype;
  446. return customEvent;
  447. })();
  448. /**
  449. * @ngdoc utility
  450. * @name ionic.EventController
  451. * @module ionic
  452. */
  453. ionic.EventController = {
  454. VIRTUALIZED_EVENTS: ['tap', 'swipe', 'swiperight', 'swipeleft', 'drag', 'hold', 'release'],
  455. /**
  456. * @ngdoc method
  457. * @name ionic.EventController#trigger
  458. * @alias ionic.trigger
  459. * @param {string} eventType The event to trigger.
  460. * @param {object} data The data for the event. Hint: pass in
  461. * `{target: targetElement}`
  462. * @param {boolean=} bubbles Whether the event should bubble up the DOM.
  463. * @param {boolean=} cancelable Whether the event should be cancelable.
  464. */
  465. // Trigger a new event
  466. trigger: function(eventType, data, bubbles, cancelable) {
  467. var event = new ionic.CustomEvent(eventType, {
  468. detail: data,
  469. bubbles: !!bubbles,
  470. cancelable: !!cancelable
  471. });
  472. // Make sure to trigger the event on the given target, or dispatch it from
  473. // the window if we don't have an event target
  474. data && data.target && data.target.dispatchEvent && data.target.dispatchEvent(event) || window.dispatchEvent(event);
  475. },
  476. /**
  477. * @ngdoc method
  478. * @name ionic.EventController#on
  479. * @alias ionic.on
  480. * @description Listen to an event on an element.
  481. * @param {string} type The event to listen for.
  482. * @param {function} callback The listener to be called.
  483. * @param {DOMElement} element The element to listen for the event on.
  484. */
  485. on: function(type, callback, element) {
  486. var e = element || window;
  487. // Bind a gesture if it's a virtual event
  488. for(var i = 0, j = this.VIRTUALIZED_EVENTS.length; i < j; i++) {
  489. if(type == this.VIRTUALIZED_EVENTS[i]) {
  490. var gesture = new ionic.Gesture(element);
  491. gesture.on(type, callback);
  492. return gesture;
  493. }
  494. }
  495. // Otherwise bind a normal event
  496. e.addEventListener(type, callback);
  497. },
  498. /**
  499. * @ngdoc method
  500. * @name ionic.EventController#off
  501. * @alias ionic.off
  502. * @description Remove an event listener.
  503. * @param {string} type
  504. * @param {function} callback
  505. * @param {DOMElement} element
  506. */
  507. off: function(type, callback, element) {
  508. element.removeEventListener(type, callback);
  509. },
  510. /**
  511. * @ngdoc method
  512. * @name ionic.EventController#onGesture
  513. * @alias ionic.onGesture
  514. * @description Add an event listener for a gesture on an element.
  515. *
  516. * Available eventTypes (from [hammer.js](http://eightmedia.github.io/hammer.js/)):
  517. *
  518. * `hold`, `tap`, `doubletap`, `drag`, `dragstart`, `dragend`, `dragup`, `dragdown`, <br/>
  519. * `dragleft`, `dragright`, `swipe`, `swipeup`, `swipedown`, `swipeleft`, `swiperight`, <br/>
  520. * `transform`, `transformstart`, `transformend`, `rotate`, `pinch`, `pinchin`, `pinchout`, <br/>
  521. * `touch`, `release`
  522. *
  523. * @param {string} eventType The gesture event to listen for.
  524. * @param {function(e)} callback The function to call when the gesture
  525. * happens.
  526. * @param {DOMElement} element The angular element to listen for the event on.
  527. * @param {object} options object.
  528. * @returns {ionic.Gesture} The gesture object (use this to remove the gesture later on).
  529. */
  530. onGesture: function(type, callback, element, options) {
  531. var gesture = new ionic.Gesture(element, options);
  532. gesture.on(type, callback);
  533. return gesture;
  534. },
  535. /**
  536. * @ngdoc method
  537. * @name ionic.EventController#offGesture
  538. * @alias ionic.offGesture
  539. * @description Remove an event listener for a gesture created on an element.
  540. * @param {ionic.Gesture} gesture The gesture that should be removed.
  541. * @param {string} eventType The gesture event to remove the listener for.
  542. * @param {function(e)} callback The listener to remove.
  543. */
  544. offGesture: function(gesture, type, callback) {
  545. gesture && gesture.off(type, callback);
  546. },
  547. handlePopState: function() {}
  548. };
  549. // Map some convenient top-level functions for event handling
  550. ionic.on = function() { ionic.EventController.on.apply(ionic.EventController, arguments); };
  551. ionic.off = function() { ionic.EventController.off.apply(ionic.EventController, arguments); };
  552. ionic.trigger = ionic.EventController.trigger;//function() { ionic.EventController.trigger.apply(ionic.EventController.trigger, arguments); };
  553. ionic.onGesture = function() { return ionic.EventController.onGesture.apply(ionic.EventController.onGesture, arguments); };
  554. ionic.offGesture = function() { return ionic.EventController.offGesture.apply(ionic.EventController.offGesture, arguments); };
  555. })(window.ionic);
  556. /* eslint camelcase:0 */
  557. /**
  558. * Simple gesture controllers with some common gestures that emit
  559. * gesture events.
  560. *
  561. * Ported from github.com/EightMedia/hammer.js Gestures - thanks!
  562. */
  563. (function(ionic) {
  564. /**
  565. * ionic.Gestures
  566. * use this to create instances
  567. * @param {HTMLElement} element
  568. * @param {Object} options
  569. * @returns {ionic.Gestures.Instance}
  570. * @constructor
  571. */
  572. ionic.Gesture = function(element, options) {
  573. return new ionic.Gestures.Instance(element, options || {});
  574. };
  575. ionic.Gestures = {};
  576. // default settings
  577. ionic.Gestures.defaults = {
  578. // add css to the element to prevent the browser from doing
  579. // its native behavior. this doesnt prevent the scrolling,
  580. // but cancels the contextmenu, tap highlighting etc
  581. // set to false to disable this
  582. stop_browser_behavior: 'disable-user-behavior'
  583. };
  584. // detect touchevents
  585. ionic.Gestures.HAS_POINTEREVENTS = window.navigator.pointerEnabled || window.navigator.msPointerEnabled;
  586. ionic.Gestures.HAS_TOUCHEVENTS = ('ontouchstart' in window);
  587. // dont use mouseevents on mobile devices
  588. ionic.Gestures.MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android|silk/i;
  589. ionic.Gestures.NO_MOUSEEVENTS = ionic.Gestures.HAS_TOUCHEVENTS && window.navigator.userAgent.match(ionic.Gestures.MOBILE_REGEX);
  590. // eventtypes per touchevent (start, move, end)
  591. // are filled by ionic.Gestures.event.determineEventTypes on setup
  592. ionic.Gestures.EVENT_TYPES = {};
  593. // direction defines
  594. ionic.Gestures.DIRECTION_DOWN = 'down';
  595. ionic.Gestures.DIRECTION_LEFT = 'left';
  596. ionic.Gestures.DIRECTION_UP = 'up';
  597. ionic.Gestures.DIRECTION_RIGHT = 'right';
  598. // pointer type
  599. ionic.Gestures.POINTER_MOUSE = 'mouse';
  600. ionic.Gestures.POINTER_TOUCH = 'touch';
  601. ionic.Gestures.POINTER_PEN = 'pen';
  602. // touch event defines
  603. ionic.Gestures.EVENT_START = 'start';
  604. ionic.Gestures.EVENT_MOVE = 'move';
  605. ionic.Gestures.EVENT_END = 'end';
  606. // hammer document where the base events are added at
  607. ionic.Gestures.DOCUMENT = window.document;
  608. // plugins namespace
  609. ionic.Gestures.plugins = {};
  610. // if the window events are set...
  611. ionic.Gestures.READY = false;
  612. /**
  613. * setup events to detect gestures on the document
  614. */
  615. function setup() {
  616. if(ionic.Gestures.READY) {
  617. return;
  618. }
  619. // find what eventtypes we add listeners to
  620. ionic.Gestures.event.determineEventTypes();
  621. // Register all gestures inside ionic.Gestures.gestures
  622. for(var name in ionic.Gestures.gestures) {
  623. if(ionic.Gestures.gestures.hasOwnProperty(name)) {
  624. ionic.Gestures.detection.register(ionic.Gestures.gestures[name]);
  625. }
  626. }
  627. // Add touch events on the document
  628. ionic.Gestures.event.onTouch(ionic.Gestures.DOCUMENT, ionic.Gestures.EVENT_MOVE, ionic.Gestures.detection.detect);
  629. ionic.Gestures.event.onTouch(ionic.Gestures.DOCUMENT, ionic.Gestures.EVENT_END, ionic.Gestures.detection.detect);
  630. // ionic.Gestures is ready...!
  631. ionic.Gestures.READY = true;
  632. }
  633. /**
  634. * create new hammer instance
  635. * all methods should return the instance itself, so it is chainable.
  636. * @param {HTMLElement} element
  637. * @param {Object} [options={}]
  638. * @returns {ionic.Gestures.Instance}
  639. * @name Gesture.Instance
  640. * @constructor
  641. */
  642. ionic.Gestures.Instance = function(element, options) {
  643. var self = this;
  644. // A null element was passed into the instance, which means
  645. // whatever lookup was done to find this element failed to find it
  646. // so we can't listen for events on it.
  647. if(element === null) {
  648. void 0;
  649. return this;
  650. }
  651. // setup ionic.GesturesJS window events and register all gestures
  652. // this also sets up the default options
  653. setup();
  654. this.element = element;
  655. // start/stop detection option
  656. this.enabled = true;
  657. // merge options
  658. this.options = ionic.Gestures.utils.extend(
  659. ionic.Gestures.utils.extend({}, ionic.Gestures.defaults),
  660. options || {});
  661. // add some css to the element to prevent the browser from doing its native behavoir
  662. if(this.options.stop_browser_behavior) {
  663. ionic.Gestures.utils.stopDefaultBrowserBehavior(this.element, this.options.stop_browser_behavior);
  664. }
  665. // start detection on touchstart
  666. ionic.Gestures.event.onTouch(element, ionic.Gestures.EVENT_START, function(ev) {
  667. if(self.enabled) {
  668. ionic.Gestures.detection.startDetect(self, ev);
  669. }
  670. });
  671. // return instance
  672. return this;
  673. };
  674. ionic.Gestures.Instance.prototype = {
  675. /**
  676. * bind events to the instance
  677. * @param {String} gesture
  678. * @param {Function} handler
  679. * @returns {ionic.Gestures.Instance}
  680. */
  681. on: function onEvent(gesture, handler){
  682. var gestures = gesture.split(' ');
  683. for(var t = 0; t < gestures.length; t++) {
  684. this.element.addEventListener(gestures[t], handler, false);
  685. }
  686. return this;
  687. },
  688. /**
  689. * unbind events to the instance
  690. * @param {String} gesture
  691. * @param {Function} handler
  692. * @returns {ionic.Gestures.Instance}
  693. */
  694. off: function offEvent(gesture, handler){
  695. var gestures = gesture.split(' ');
  696. for(var t = 0; t < gestures.length; t++) {
  697. this.element.removeEventListener(gestures[t], handler, false);
  698. }
  699. return this;
  700. },
  701. /**
  702. * trigger gesture event
  703. * @param {String} gesture
  704. * @param {Object} eventData
  705. * @returns {ionic.Gestures.Instance}
  706. */
  707. trigger: function triggerEvent(gesture, eventData){
  708. // create DOM event
  709. var event = ionic.Gestures.DOCUMENT.createEvent('Event');
  710. event.initEvent(gesture, true, true);
  711. event.gesture = eventData;
  712. // trigger on the target if it is in the instance element,
  713. // this is for event delegation tricks
  714. var element = this.element;
  715. if(ionic.Gestures.utils.hasParent(eventData.target, element)) {
  716. element = eventData.target;
  717. }
  718. element.dispatchEvent(event);
  719. return this;
  720. },
  721. /**
  722. * enable of disable hammer.js detection
  723. * @param {Boolean} state
  724. * @returns {ionic.Gestures.Instance}
  725. */
  726. enable: function enable(state) {
  727. this.enabled = state;
  728. return this;
  729. }
  730. };
  731. /**
  732. * this holds the last move event,
  733. * used to fix empty touchend issue
  734. * see the onTouch event for an explanation
  735. * type {Object}
  736. */
  737. var last_move_event = null;
  738. /**
  739. * when the mouse is hold down, this is true
  740. * type {Boolean}
  741. */
  742. var enable_detect = false;
  743. /**
  744. * when touch events have been fired, this is true
  745. * type {Boolean}
  746. */
  747. var touch_triggered = false;
  748. ionic.Gestures.event = {
  749. /**
  750. * simple addEventListener
  751. * @param {HTMLElement} element
  752. * @param {String} type
  753. * @param {Function} handler
  754. */
  755. bindDom: function(element, type, handler) {
  756. var types = type.split(' ');
  757. for(var t = 0; t < types.length; t++) {
  758. element.addEventListener(types[t], handler, false);
  759. }
  760. },
  761. /**
  762. * touch events with mouse fallback
  763. * @param {HTMLElement} element
  764. * @param {String} eventType like ionic.Gestures.EVENT_MOVE
  765. * @param {Function} handler
  766. */
  767. onTouch: function onTouch(element, eventType, handler) {
  768. var self = this;
  769. this.bindDom(element, ionic.Gestures.EVENT_TYPES[eventType], function bindDomOnTouch(ev) {
  770. var sourceEventType = ev.type.toLowerCase();
  771. // onmouseup, but when touchend has been fired we do nothing.
  772. // this is for touchdevices which also fire a mouseup on touchend
  773. if(sourceEventType.match(/mouse/) && touch_triggered) {
  774. return;
  775. }
  776. // mousebutton must be down or a touch event
  777. else if( sourceEventType.match(/touch/) || // touch events are always on screen
  778. sourceEventType.match(/pointerdown/) || // pointerevents touch
  779. (sourceEventType.match(/mouse/) && ev.which === 1) // mouse is pressed
  780. ){
  781. enable_detect = true;
  782. }
  783. // mouse isn't pressed
  784. else if(sourceEventType.match(/mouse/) && ev.which !== 1) {
  785. enable_detect = false;
  786. }
  787. // we are in a touch event, set the touch triggered bool to true,
  788. // this for the conflicts that may occur on ios and android
  789. if(sourceEventType.match(/touch|pointer/)) {
  790. touch_triggered = true;
  791. }
  792. // count the total touches on the screen
  793. var count_touches = 0;
  794. // when touch has been triggered in this detection session
  795. // and we are now handling a mouse event, we stop that to prevent conflicts
  796. if(enable_detect) {
  797. // update pointerevent
  798. if(ionic.Gestures.HAS_POINTEREVENTS && eventType != ionic.Gestures.EVENT_END) {
  799. count_touches = ionic.Gestures.PointerEvent.updatePointer(eventType, ev);
  800. }
  801. // touch
  802. else if(sourceEventType.match(/touch/)) {
  803. count_touches = ev.touches.length;
  804. }
  805. // mouse
  806. else if(!touch_triggered) {
  807. count_touches = sourceEventType.match(/up/) ? 0 : 1;
  808. }
  809. // if we are in a end event, but when we remove one touch and
  810. // we still have enough, set eventType to move
  811. if(count_touches > 0 && eventType == ionic.Gestures.EVENT_END) {
  812. eventType = ionic.Gestures.EVENT_MOVE;
  813. }
  814. // no touches, force the end event
  815. else if(!count_touches) {
  816. eventType = ionic.Gestures.EVENT_END;
  817. }
  818. // store the last move event
  819. if(count_touches || last_move_event === null) {
  820. last_move_event = ev;
  821. }
  822. // trigger the handler
  823. handler.call(ionic.Gestures.detection, self.collectEventData(element, eventType, self.getTouchList(last_move_event, eventType), ev));
  824. // remove pointerevent from list
  825. if(ionic.Gestures.HAS_POINTEREVENTS && eventType == ionic.Gestures.EVENT_END) {
  826. count_touches = ionic.Gestures.PointerEvent.updatePointer(eventType, ev);
  827. }
  828. }
  829. //debug(sourceEventType +" "+ eventType);
  830. // on the end we reset everything
  831. if(!count_touches) {
  832. last_move_event = null;
  833. enable_detect = false;
  834. touch_triggered = false;
  835. ionic.Gestures.PointerEvent.reset();
  836. }
  837. });
  838. },
  839. /**
  840. * we have different events for each device/browser
  841. * determine what we need and set them in the ionic.Gestures.EVENT_TYPES constant
  842. */
  843. determineEventTypes: function determineEventTypes() {
  844. // determine the eventtype we want to set
  845. var types;
  846. // pointerEvents magic
  847. if(ionic.Gestures.HAS_POINTEREVENTS) {
  848. types = ionic.Gestures.PointerEvent.getEvents();
  849. }
  850. // on Android, iOS, blackberry, windows mobile we dont want any mouseevents
  851. else if(ionic.Gestures.NO_MOUSEEVENTS) {
  852. types = [
  853. 'touchstart',
  854. 'touchmove',
  855. 'touchend touchcancel'];
  856. }
  857. // for non pointer events browsers and mixed browsers,
  858. // like chrome on windows8 touch laptop
  859. else {
  860. types = [
  861. 'touchstart mousedown',
  862. 'touchmove mousemove',
  863. 'touchend touchcancel mouseup'];
  864. }
  865. ionic.Gestures.EVENT_TYPES[ionic.Gestures.EVENT_START] = types[0];
  866. ionic.Gestures.EVENT_TYPES[ionic.Gestures.EVENT_MOVE] = types[1];
  867. ionic.Gestures.EVENT_TYPES[ionic.Gestures.EVENT_END] = types[2];
  868. },
  869. /**
  870. * create touchlist depending on the event
  871. * @param {Object} ev
  872. * @param {String} eventType used by the fakemultitouch plugin
  873. */
  874. getTouchList: function getTouchList(ev/*, eventType*/) {
  875. // get the fake pointerEvent touchlist
  876. if(ionic.Gestures.HAS_POINTEREVENTS) {
  877. return ionic.Gestures.PointerEvent.getTouchList();
  878. }
  879. // get the touchlist
  880. else if(ev.touches) {
  881. return ev.touches;
  882. }
  883. // make fake touchlist from mouse position
  884. else {
  885. ev.identifier = 1;
  886. return [ev];
  887. }
  888. },
  889. /**
  890. * collect event data for ionic.Gestures js
  891. * @param {HTMLElement} element
  892. * @param {String} eventType like ionic.Gestures.EVENT_MOVE
  893. * @param {Object} eventData
  894. */
  895. collectEventData: function collectEventData(element, eventType, touches, ev) {
  896. // find out pointerType
  897. var pointerType = ionic.Gestures.POINTER_TOUCH;
  898. if(ev.type.match(/mouse/) || ionic.Gestures.PointerEvent.matchType(ionic.Gestures.POINTER_MOUSE, ev)) {
  899. pointerType = ionic.Gestures.POINTER_MOUSE;
  900. }
  901. return {
  902. center: ionic.Gestures.utils.getCenter(touches),
  903. timeStamp: new Date().getTime(),
  904. target: ev.target,
  905. touches: touches,
  906. eventType: eventType,
  907. pointerType: pointerType,
  908. srcEvent: ev,
  909. /**
  910. * prevent the browser default actions
  911. * mostly used to disable scrolling of the browser
  912. */
  913. preventDefault: function() {
  914. if(this.srcEvent.preventManipulation) {
  915. this.srcEvent.preventManipulation();
  916. }
  917. if(this.srcEvent.preventDefault) {
  918. // this.srcEvent.preventDefault();
  919. }
  920. },
  921. /**
  922. * stop bubbling the event up to its parents
  923. */
  924. stopPropagation: function() {
  925. this.srcEvent.stopPropagation();
  926. },
  927. /**
  928. * immediately stop gesture detection
  929. * might be useful after a swipe was detected
  930. * @return {*}
  931. */
  932. stopDetect: function() {
  933. return ionic.Gestures.detection.stopDetect();
  934. }
  935. };
  936. }
  937. };
  938. ionic.Gestures.PointerEvent = {
  939. /**
  940. * holds all pointers
  941. * type {Object}
  942. */
  943. pointers: {},
  944. /**
  945. * get a list of pointers
  946. * @returns {Array} touchlist
  947. */
  948. getTouchList: function() {
  949. var self = this;
  950. var touchlist = [];
  951. // we can use forEach since pointerEvents only is in IE10
  952. Object.keys(self.pointers).sort().forEach(function(id) {
  953. touchlist.push(self.pointers[id]);
  954. });
  955. return touchlist;
  956. },
  957. /**
  958. * update the position of a pointer
  959. * @param {String} type ionic.Gestures.EVENT_END
  960. * @param {Object} pointerEvent
  961. */
  962. updatePointer: function(type, pointerEvent) {
  963. if(type == ionic.Gestures.EVENT_END) {
  964. this.pointers = {};
  965. }
  966. else {
  967. pointerEvent.identifier = pointerEvent.pointerId;
  968. this.pointers[pointerEvent.pointerId] = pointerEvent;
  969. }
  970. return Object.keys(this.pointers).length;
  971. },
  972. /**
  973. * check if ev matches pointertype
  974. * @param {String} pointerType ionic.Gestures.POINTER_MOUSE
  975. * @param {PointerEvent} ev
  976. */
  977. matchType: function(pointerType, ev) {
  978. if(!ev.pointerType) {
  979. return false;
  980. }
  981. var types = {};
  982. types[ionic.Gestures.POINTER_MOUSE] = (ev.pointerType == ev.MSPOINTER_TYPE_MOUSE || ev.pointerType == ionic.Gestures.POINTER_MOUSE);
  983. types[ionic.Gestures.POINTER_TOUCH] = (ev.pointerType == ev.MSPOINTER_TYPE_TOUCH || ev.pointerType == ionic.Gestures.POINTER_TOUCH);
  984. types[ionic.Gestures.POINTER_PEN] = (ev.pointerType == ev.MSPOINTER_TYPE_PEN || ev.pointerType == ionic.Gestures.POINTER_PEN);
  985. return types[pointerType];
  986. },
  987. /**
  988. * get events
  989. */
  990. getEvents: function() {
  991. return [
  992. 'pointerdown MSPointerDown',
  993. 'pointermove MSPointerMove',
  994. 'pointerup pointercancel MSPointerUp MSPointerCancel'
  995. ];
  996. },
  997. /**
  998. * reset the list
  999. */
  1000. reset: function() {
  1001. this.pointers = {};
  1002. }
  1003. };
  1004. ionic.Gestures.utils = {
  1005. /**
  1006. * extend method,
  1007. * also used for cloning when dest is an empty object
  1008. * @param {Object} dest
  1009. * @param {Object} src
  1010. * @param {Boolean} merge do a merge
  1011. * @returns {Object} dest
  1012. */
  1013. extend: function extend(dest, src, merge) {
  1014. for (var key in src) {
  1015. if(dest[key] !== undefined && merge) {
  1016. continue;
  1017. }
  1018. dest[key] = src[key];
  1019. }
  1020. return dest;
  1021. },
  1022. /**
  1023. * find if a node is in the given parent
  1024. * used for event delegation tricks
  1025. * @param {HTMLElement} node
  1026. * @param {HTMLElement} parent
  1027. * @returns {boolean} has_parent
  1028. */
  1029. hasParent: function(node, parent) {
  1030. while(node){
  1031. if(node == parent) {
  1032. return true;
  1033. }
  1034. node = node.parentNode;
  1035. }
  1036. return false;
  1037. },
  1038. /**
  1039. * get the center of all the touches
  1040. * @param {Array} touches
  1041. * @returns {Object} center
  1042. */
  1043. getCenter: function getCenter(touches) {
  1044. var valuesX = [], valuesY = [];
  1045. for(var t = 0, len = touches.length; t < len; t++) {
  1046. valuesX.push(touches[t].pageX);
  1047. valuesY.push(touches[t].pageY);
  1048. }
  1049. return {
  1050. pageX: ((Math.min.apply(Math, valuesX) + Math.max.apply(Math, valuesX)) / 2),
  1051. pageY: ((Math.min.apply(Math, valuesY) + Math.max.apply(Math, valuesY)) / 2)
  1052. };
  1053. },
  1054. /**
  1055. * calculate the velocity between two points
  1056. * @param {Number} delta_time
  1057. * @param {Number} delta_x
  1058. * @param {Number} delta_y
  1059. * @returns {Object} velocity
  1060. */
  1061. getVelocity: function getVelocity(delta_time, delta_x, delta_y) {
  1062. return {
  1063. x: Math.abs(delta_x / delta_time) || 0,
  1064. y: Math.abs(delta_y / delta_time) || 0
  1065. };
  1066. },
  1067. /**
  1068. * calculate the angle between two coordinates
  1069. * @param {Touch} touch1
  1070. * @param {Touch} touch2
  1071. * @returns {Number} angle
  1072. */
  1073. getAngle: function getAngle(touch1, touch2) {
  1074. var y = touch2.pageY - touch1.pageY,
  1075. x = touch2.pageX - touch1.pageX;
  1076. return Math.atan2(y, x) * 180 / Math.PI;
  1077. },
  1078. /**
  1079. * angle to direction define
  1080. * @param {Touch} touch1
  1081. * @param {Touch} touch2
  1082. * @returns {String} direction constant, like ionic.Gestures.DIRECTION_LEFT
  1083. */
  1084. getDirection: function getDirection(touch1, touch2) {
  1085. var x = Math.abs(touch1.pageX - touch2.pageX),
  1086. y = Math.abs(touch1.pageY - touch2.pageY);
  1087. if(x >= y) {
  1088. return touch1.pageX - touch2.pageX > 0 ? ionic.Gestures.DIRECTION_LEFT : ionic.Gestures.DIRECTION_RIGHT;
  1089. }
  1090. else {
  1091. return touch1.pageY - touch2.pageY > 0 ? ionic.Gestures.DIRECTION_UP : ionic.Gestures.DIRECTION_DOWN;
  1092. }
  1093. },
  1094. /**
  1095. * calculate the distance between two touches
  1096. * @param {Touch} touch1
  1097. * @param {Touch} touch2
  1098. * @returns {Number} distance
  1099. */
  1100. getDistance: function getDistance(touch1, touch2) {
  1101. var x = touch2.pageX - touch1.pageX,
  1102. y = touch2.pageY - touch1.pageY;
  1103. return Math.sqrt((x * x) + (y * y));
  1104. },
  1105. /**
  1106. * calculate the scale factor between two touchLists (fingers)
  1107. * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
  1108. * @param {Array} start
  1109. * @param {Array} end
  1110. * @returns {Number} scale
  1111. */
  1112. getScale: function getScale(start, end) {
  1113. // need two fingers...
  1114. if(start.length >= 2 && end.length >= 2) {
  1115. return this.getDistance(end[0], end[1]) /
  1116. this.getDistance(start[0], start[1]);
  1117. }
  1118. return 1;
  1119. },
  1120. /**
  1121. * calculate the rotation degrees between two touchLists (fingers)
  1122. * @param {Array} start
  1123. * @param {Array} end
  1124. * @returns {Number} rotation
  1125. */
  1126. getRotation: function getRotation(start, end) {
  1127. // need two fingers
  1128. if(start.length >= 2 && end.length >= 2) {
  1129. return this.getAngle(end[1], end[0]) -
  1130. this.getAngle(start[1], start[0]);
  1131. }
  1132. return 0;
  1133. },
  1134. /**
  1135. * boolean if the direction is vertical
  1136. * @param {String} direction
  1137. * @returns {Boolean} is_vertical
  1138. */
  1139. isVertical: function isVertical(direction) {
  1140. return (direction == ionic.Gestures.DIRECTION_UP || direction == ionic.Gestures.DIRECTION_DOWN);
  1141. },
  1142. /**
  1143. * stop browser default behavior with css class
  1144. * @param {HtmlElement} element
  1145. * @param {Object} css_class
  1146. */
  1147. stopDefaultBrowserBehavior: function stopDefaultBrowserBehavior(element, css_class) {
  1148. // changed from making many style changes to just adding a preset classname
  1149. // less DOM manipulations, less code, and easier to control in the CSS side of things
  1150. // hammer.js doesn't come with CSS, but ionic does, which is why we prefer this method
  1151. if(element && element.classList) {
  1152. element.classList.add(css_class);
  1153. element.onselectstart = function() {
  1154. return false;
  1155. };
  1156. }
  1157. }
  1158. };
  1159. ionic.Gestures.detection = {
  1160. // contains all registred ionic.Gestures.gestures in the correct order
  1161. gestures: [],
  1162. // data of the current ionic.Gestures.gesture detection session
  1163. current: null,
  1164. // the previous ionic.Gestures.gesture session data
  1165. // is a full clone of the previous gesture.current object
  1166. previous: null,
  1167. // when this becomes true, no gestures are fired
  1168. stopped: false,
  1169. /**
  1170. * start ionic.Gestures.gesture detection
  1171. * @param {ionic.Gestures.Instance} inst
  1172. * @param {Object} eventData
  1173. */
  1174. startDetect: function startDetect(inst, eventData) {
  1175. // already busy with a ionic.Gestures.gesture detection on an element
  1176. if(this.current) {
  1177. return;
  1178. }
  1179. this.stopped = false;
  1180. this.current = {
  1181. inst: inst, // reference to ionic.GesturesInstance we're working for
  1182. startEvent: ionic.Gestures.utils.extend({}, eventData), // start eventData for distances, timing etc
  1183. lastEvent: false, // last eventData
  1184. name: '' // current gesture we're in/detected, can be 'tap', 'hold' etc
  1185. };
  1186. this.detect(eventData);
  1187. },
  1188. /**
  1189. * ionic.Gestures.gesture detection
  1190. * @param {Object} eventData
  1191. */
  1192. detect: function detect(eventData) {
  1193. if(!this.current || this.stopped) {
  1194. return null;
  1195. }
  1196. // extend event data with calculations about scale, distance etc
  1197. eventData = this.extendEventData(eventData);
  1198. // instance options
  1199. var inst_options = this.current.inst.options;
  1200. // call ionic.Gestures.gesture handlers
  1201. for(var g = 0, len = this.gestures.length; g < len; g++) {
  1202. var gesture = this.gestures[g];
  1203. // only when the instance options have enabled this gesture
  1204. if(!this.stopped && inst_options[gesture.name] !== false) {
  1205. // if a handler returns false, we stop with the detection
  1206. if(gesture.handler.call(gesture, eventData, this.current.inst) === false) {
  1207. this.stopDetect();
  1208. break;
  1209. }
  1210. }
  1211. }
  1212. // store as previous event event
  1213. if(this.current) {
  1214. this.current.lastEvent = eventData;
  1215. }
  1216. // endevent, but not the last touch, so dont stop
  1217. if(eventData.eventType == ionic.Gestures.EVENT_END && !eventData.touches.length - 1) {
  1218. this.stopDetect();
  1219. }
  1220. return eventData;
  1221. },
  1222. /**
  1223. * clear the ionic.Gestures.gesture vars
  1224. * this is called on endDetect, but can also be used when a final ionic.Gestures.gesture has been detected
  1225. * to stop other ionic.Gestures.gestures from being fired
  1226. */
  1227. stopDetect: function stopDetect() {
  1228. // clone current data to the store as the previous gesture
  1229. // used for the double tap gesture, since this is an other gesture detect session
  1230. this.previous = ionic.Gestures.utils.extend({}, this.current);
  1231. // reset the current
  1232. this.current = null;
  1233. // stopped!
  1234. this.stopped = true;
  1235. },
  1236. /**
  1237. * extend eventData for ionic.Gestures.gestures
  1238. * @param {Object} ev
  1239. * @returns {Object} ev
  1240. */
  1241. extendEventData: function extendEventData(ev) {
  1242. var startEv = this.current.startEvent;
  1243. // if the touches change, set the new touches over the startEvent touches
  1244. // this because touchevents don't have all the touches on touchstart, or the
  1245. // user must place his fingers at the EXACT same time on the screen, which is not realistic
  1246. // but, sometimes it happens that both fingers are touching at the EXACT same time
  1247. if(startEv && (ev.touches.length != startEv.touches.length || ev.touches === startEv.touches)) {
  1248. // extend 1 level deep to get the touchlist with the touch objects
  1249. startEv.touches = [];
  1250. for(var i = 0, len = ev.touches.length; i < len; i++) {
  1251. startEv.touches.push(ionic.Gestures.utils.extend({}, ev.touches[i]));
  1252. }
  1253. }
  1254. var delta_time = ev.timeStamp - startEv.timeStamp,
  1255. delta_x = ev.center.pageX - startEv.center.pageX,
  1256. delta_y = ev.center.pageY - startEv.center.pageY,
  1257. velocity = ionic.Gestures.utils.getVelocity(delta_time, delta_x, delta_y);
  1258. ionic.Gestures.utils.extend(ev, {
  1259. deltaTime: delta_time,
  1260. deltaX: delta_x,
  1261. deltaY: delta_y,
  1262. velocityX: velocity.x,
  1263. velocityY: velocity.y,
  1264. distance: ionic.Gestures.utils.getDistance(startEv.center, ev.center),
  1265. angle: ionic.Gestures.utils.getAngle(startEv.center, ev.center),
  1266. direction: ionic.Gestures.utils.getDirection(startEv.center, ev.center),
  1267. scale: ionic.Gestures.utils.getScale(startEv.touches, ev.touches),
  1268. rotation: ionic.Gestures.utils.getRotation(startEv.touches, ev.touches),
  1269. startEvent: startEv
  1270. });
  1271. return ev;
  1272. },
  1273. /**
  1274. * register new gesture
  1275. * @param {Object} gesture object, see gestures.js for documentation
  1276. * @returns {Array} gestures
  1277. */
  1278. register: function register(gesture) {
  1279. // add an enable gesture options if there is no given
  1280. var options = gesture.defaults || {};
  1281. if(options[gesture.name] === undefined) {
  1282. options[gesture.name] = true;
  1283. }
  1284. // extend ionic.Gestures default options with the ionic.Gestures.gesture options
  1285. ionic.Gestures.utils.extend(ionic.Gestures.defaults, options, true);
  1286. // set its index
  1287. gesture.index = gesture.index || 1000;
  1288. // add ionic.Gestures.gesture to the list
  1289. this.gestures.push(gesture);
  1290. // sort the list by index
  1291. this.gestures.sort(function(a, b) {
  1292. if (a.index < b.index) {
  1293. return -1;
  1294. }
  1295. if (a.index > b.index) {
  1296. return 1;
  1297. }
  1298. return 0;
  1299. });
  1300. return this.gestures;
  1301. }
  1302. };
  1303. ionic.Gestures.gestures = ionic.Gestures.gestures || {};
  1304. /**
  1305. * Custom gestures
  1306. * ==============================
  1307. *
  1308. * Gesture object
  1309. * --------------------
  1310. * The object structure of a gesture:
  1311. *
  1312. * { name: 'mygesture',
  1313. * index: 1337,
  1314. * defaults: {
  1315. * mygesture_option: true
  1316. * }
  1317. * handler: function(type, ev, inst) {
  1318. * // trigger gesture event
  1319. * inst.trigger(this.name, ev);
  1320. * }
  1321. * }
  1322. * @param {String} name
  1323. * this should be the name of the gesture, lowercase
  1324. * it is also being used to disable/enable the gesture per instance config.
  1325. *
  1326. * @param {Number} [index=1000]
  1327. * the index of the gesture, where it is going to be in the stack of gestures detection
  1328. * like when you build an gesture that depends on the drag gesture, it is a good
  1329. * idea to place it after the index of the drag gesture.
  1330. *
  1331. * @param {Object} [defaults={}]
  1332. * the default settings of the gesture. these are added to the instance settings,
  1333. * and can be overruled per instance. you can also add the name of the gesture,
  1334. * but this is also added by default (and set to true).
  1335. *
  1336. * @param {Function} handler
  1337. * this handles the gesture detection of your custom gesture and receives the
  1338. * following arguments:
  1339. *
  1340. * @param {Object} eventData
  1341. * event data containing the following properties:
  1342. * timeStamp {Number} time the event occurred
  1343. * target {HTMLElement} target element
  1344. * touches {Array} touches (fingers, pointers, mouse) on the screen
  1345. * pointerType {String} kind of pointer that was used. matches ionic.Gestures.POINTER_MOUSE|TOUCH
  1346. * center {Object} center position of the touches. contains pageX and pageY
  1347. * deltaTime {Number} the total time of the touches in the screen
  1348. * deltaX {Number} the delta on x axis we haved moved
  1349. * deltaY {Number} the delta on y axis we haved moved
  1350. * velocityX {Number} the velocity on the x
  1351. * velocityY {Number} the velocity on y
  1352. * angle {Number} the angle we are moving
  1353. * direction {String} the direction we are moving. matches ionic.Gestures.DIRECTION_UP|DOWN|LEFT|RIGHT
  1354. * distance {Number} the distance we haved moved
  1355. * scale {Number} scaling of the touches, needs 2 touches
  1356. * rotation {Number} rotation of the touches, needs 2 touches *
  1357. * eventType {String} matches ionic.Gestures.EVENT_START|MOVE|END
  1358. * srcEvent {Object} the source event, like TouchStart or MouseDown *
  1359. * startEvent {Object} contains the same properties as above,
  1360. * but from the first touch. this is used to calculate
  1361. * distances, deltaTime, scaling etc
  1362. *
  1363. * @param {ionic.Gestures.Instance} inst
  1364. * the instance we are doing the detection for. you can get the options from
  1365. * the inst.options object and trigger the gesture event by calling inst.trigger
  1366. *
  1367. *
  1368. * Handle gestures
  1369. * --------------------
  1370. * inside the handler you can get/set ionic.Gestures.detectionic.current. This is the current
  1371. * detection sessionic. It has the following properties
  1372. * @param {String} name
  1373. * contains the name of the gesture we have detected. it has not a real function,
  1374. * only to check in other gestures if something is detected.
  1375. * like in the drag gesture we set it to 'drag' and in the swipe gesture we can
  1376. * check if the current gesture is 'drag' by accessing ionic.Gestures.detectionic.current.name
  1377. *
  1378. * readonly
  1379. * @param {ionic.Gestures.Instance} inst
  1380. * the instance we do the detection for
  1381. *
  1382. * readonly
  1383. * @param {Object} startEvent
  1384. * contains the properties of the first gesture detection in this sessionic.
  1385. * Used for calculations about timing, distance, etc.
  1386. *
  1387. * readonly
  1388. * @param {Object} lastEvent
  1389. * contains all the properties of the last gesture detect in this sessionic.
  1390. *
  1391. * after the gesture detection session has been completed (user has released the screen)
  1392. * the ionic.Gestures.detectionic.current object is copied into ionic.Gestures.detectionic.previous,
  1393. * this is usefull for gestures like doubletap, where you need to know if the
  1394. * previous gesture was a tap
  1395. *
  1396. * options that have been set by the instance can be received by calling inst.options
  1397. *
  1398. * You can trigger a gesture event by calling inst.trigger("mygesture", event).
  1399. * The first param is the name of your gesture, the second the event argument
  1400. *
  1401. *
  1402. * Register gestures
  1403. * --------------------
  1404. * When an gesture is added to the ionic.Gestures.gestures object, it is auto registered
  1405. * at the setup of the first ionic.Gestures instance. You can also call ionic.Gestures.detectionic.register
  1406. * manually and pass your gesture object as a param
  1407. *
  1408. */
  1409. /**
  1410. * Hold
  1411. * Touch stays at the same place for x time
  1412. * events hold
  1413. */
  1414. ionic.Gestures.gestures.Hold = {
  1415. name: 'hold',
  1416. index: 10,
  1417. defaults: {
  1418. hold_timeout: 500,
  1419. hold_threshold: 9
  1420. },
  1421. timer: null,
  1422. handler: function holdGesture(ev, inst) {
  1423. switch(ev.eventType) {
  1424. case ionic.Gestures.EVENT_START:
  1425. // clear any running timers
  1426. clearTimeout(this.timer);
  1427. // set the gesture so we can check in the timeout if it still is
  1428. ionic.Gestures.detection.current.name = this.name;
  1429. // set timer and if after the timeout it still is hold,
  1430. // we trigger the hold event
  1431. this.timer = setTimeout(function() {
  1432. if(ionic.Gestures.detection.current.name == 'hold') {
  1433. ionic.tap.cancelClick();
  1434. inst.trigger('hold', ev);
  1435. }
  1436. }, inst.options.hold_timeout);
  1437. break;
  1438. // when you move or end we clear the timer
  1439. case ionic.Gestures.EVENT_MOVE:
  1440. if(ev.distance > inst.options.hold_threshold) {
  1441. clearTimeout(this.timer);
  1442. }
  1443. break;
  1444. case ionic.Gestures.EVENT_END:
  1445. clearTimeout(this.timer);
  1446. break;
  1447. }
  1448. }
  1449. };
  1450. /**
  1451. * Tap/DoubleTap
  1452. * Quick touch at a place or double at the same place
  1453. * events tap, doubletap
  1454. */
  1455. ionic.Gestures.gestures.Tap = {
  1456. name: 'tap',
  1457. index: 100,
  1458. defaults: {
  1459. tap_max_touchtime: 250,
  1460. tap_max_distance: 10,
  1461. tap_always: true,
  1462. doubletap_distance: 20,
  1463. doubletap_interval: 300
  1464. },
  1465. handler: function tapGesture(ev, inst) {
  1466. if(ev.eventType == ionic.Gestures.EVENT_END && ev.srcEvent.type != 'touchcancel') {
  1467. // previous gesture, for the double tap since these are two different gesture detections
  1468. var prev = ionic.Gestures.detection.previous,
  1469. did_doubletap = false;
  1470. // when the touchtime is higher then the max touch time
  1471. // or when the moving distance is too much
  1472. if(ev.deltaTime > inst.options.tap_max_touchtime ||
  1473. ev.distance > inst.options.tap_max_distance) {
  1474. return;
  1475. }
  1476. // check if double tap
  1477. if(prev && prev.name == 'tap' &&
  1478. (ev.timeStamp - prev.lastEvent.timeStamp) < inst.options.doubletap_interval &&
  1479. ev.distance < inst.options.doubletap_distance) {
  1480. inst.trigger('doubletap', ev);
  1481. did_doubletap = true;
  1482. }
  1483. // do a single tap
  1484. if(!did_doubletap || inst.options.tap_always) {
  1485. ionic.Gestures.detection.current.name = 'tap';
  1486. inst.trigger('tap', ev);
  1487. }
  1488. }
  1489. }
  1490. };
  1491. /**
  1492. * Swipe
  1493. * triggers swipe events when the end velocity is above the threshold
  1494. * events swipe, swipeleft, swiperight, swipeup, swipedown
  1495. */
  1496. ionic.Gestures.gestures.Swipe = {
  1497. name: 'swipe',
  1498. index: 40,
  1499. defaults: {
  1500. // set 0 for unlimited, but this can conflict with transform
  1501. swipe_max_touches: 1,
  1502. swipe_velocity: 0.4
  1503. },
  1504. handler: function swipeGesture(ev, inst) {
  1505. if(ev.eventType == ionic.Gestures.EVENT_END) {
  1506. // max touches
  1507. if(inst.options.swipe_max_touches > 0 &&
  1508. ev.touches.length > inst.options.swipe_max_touches) {
  1509. return;
  1510. }
  1511. // when the distance we moved is too small we skip this gesture
  1512. // or we can be already in dragging
  1513. if(ev.velocityX > inst.options.swipe_velocity ||
  1514. ev.velocityY > inst.options.swipe_velocity) {
  1515. // trigger swipe events
  1516. inst.trigger(this.name, ev);
  1517. inst.trigger(this.name + ev.direction, ev);
  1518. }
  1519. }
  1520. }
  1521. };
  1522. /**
  1523. * Drag
  1524. * Move with x fingers (default 1) around on the page. Blocking the scrolling when
  1525. * moving left and right is a good practice. When all the drag events are blocking
  1526. * you disable scrolling on that area.
  1527. * events drag, drapleft, dragright, dragup, dragdown
  1528. */
  1529. ionic.Gestures.gestures.Drag = {
  1530. name: 'drag',
  1531. index: 50,
  1532. defaults: {
  1533. drag_min_distance: 10,
  1534. // Set correct_for_drag_min_distance to true to make the starting point of the drag
  1535. // be calculated from where the drag was triggered, not from where the touch started.
  1536. // Useful to avoid a jerk-starting drag, which can make fine-adjustments
  1537. // through dragging difficult, and be visually unappealing.
  1538. correct_for_drag_min_distance: true,
  1539. // set 0 for unlimited, but this can conflict with transform
  1540. drag_max_touches: 1,
  1541. // prevent default browser behavior when dragging occurs
  1542. // be careful with it, it makes the element a blocking element
  1543. // when you are using the drag gesture, it is a good practice to set this true
  1544. drag_block_horizontal: true,
  1545. drag_block_vertical: true,
  1546. // drag_lock_to_axis keeps the drag gesture on the axis that it started on,
  1547. // It disallows vertical directions if the initial direction was horizontal, and vice versa.
  1548. drag_lock_to_axis: false,
  1549. // drag lock only kicks in when distance > drag_lock_min_distance
  1550. // This way, locking occurs only when the distance has become large enough to reliably determine the direction
  1551. drag_lock_min_distance: 25,
  1552. // prevent default if the gesture is going the given direction
  1553. prevent_default_directions: []
  1554. },
  1555. triggered: false,
  1556. handler: function dragGesture(ev, inst) {
  1557. if (ev.srcEvent.type == 'touchstart' || ev.srcEvent.type == 'touchend') {
  1558. this.preventedFirstMove = false;
  1559. } else if (!this.preventedFirstMove && ev.srcEvent.type == 'touchmove') {
  1560. // Prevent gestures that are not intended for this event handler from firing subsequent times
  1561. if (inst.options.prevent_default_directions.length > 0
  1562. && inst.options.prevent_default_directions.indexOf(ev.direction) != -1) {
  1563. ev.srcEvent.preventDefault();
  1564. }
  1565. this.preventedFirstMove = true;
  1566. }
  1567. // current gesture isnt drag, but dragged is true
  1568. // this means an other gesture is busy. now call dragend
  1569. if(ionic.Gestures.detection.current.name != this.name && this.triggered) {
  1570. inst.trigger(this.name + 'end', ev);
  1571. this.triggered = false;
  1572. return;
  1573. }
  1574. // max touches
  1575. if(inst.options.drag_max_touches > 0 &&
  1576. ev.touches.length > inst.options.drag_max_touches) {
  1577. return;
  1578. }
  1579. switch(ev.eventType) {
  1580. case ionic.Gestures.EVENT_START:
  1581. this.triggered = false;
  1582. break;
  1583. case ionic.Gestures.EVENT_MOVE:
  1584. // when the distance we moved is too small we skip this gesture
  1585. // or we can be already in dragging
  1586. if(ev.distance < inst.options.drag_min_distance &&
  1587. ionic.Gestures.detection.current.name != this.name) {
  1588. return;
  1589. }
  1590. // we are dragging!
  1591. if(ionic.Gestures.detection.current.name != this.name) {
  1592. ionic.Gestures.detection.current.name = this.name;
  1593. if (inst.options.correct_for_drag_min_distance) {
  1594. // When a drag is triggered, set the event center to drag_min_distance pixels from the original event center.
  1595. // Without this correction, the dragged distance would jumpstart at drag_min_distance pixels instead of at 0.
  1596. // It might be useful to save the original start point somewhere
  1597. var factor = Math.abs(inst.options.drag_min_distance / ev.distance);
  1598. ionic.Gestures.detection.current.startEvent.center.pageX += ev.deltaX * factor;
  1599. ionic.Gestures.detection.current.startEvent.center.pageY += ev.deltaY * factor;
  1600. // recalculate event data using new start point
  1601. ev = ionic.Gestures.detection.extendEventData(ev);
  1602. }
  1603. }
  1604. // lock drag to axis?
  1605. if(ionic.Gestures.detection.current.lastEvent.drag_locked_to_axis || (inst.options.drag_lock_to_axis && inst.options.drag_lock_min_distance <= ev.distance)) {
  1606. ev.drag_locked_to_axis = true;
  1607. }
  1608. var last_direction = ionic.Gestures.detection.current.lastEvent.direction;
  1609. if(ev.drag_locked_to_axis && last_direction !== ev.direction) {
  1610. // keep direction on the axis that the drag gesture started on
  1611. if(ionic.Gestures.utils.isVertical(last_direction)) {
  1612. ev.direction = (ev.deltaY < 0) ? ionic.Gestures.DIRECTION_UP : ionic.Gestures.DIRECTION_DOWN;
  1613. }
  1614. else {
  1615. ev.direction = (ev.deltaX < 0) ? ionic.Gestures.DIRECTION_LEFT : ionic.Gestures.DIRECTION_RIGHT;
  1616. }
  1617. }
  1618. // first time, trigger dragstart event
  1619. if(!this.triggered) {
  1620. inst.trigger(this.name + 'start', ev);
  1621. this.triggered = true;
  1622. }
  1623. // trigger normal event
  1624. inst.trigger(this.name, ev);
  1625. // direction event, like dragdown
  1626. inst.trigger(this.name + ev.direction, ev);
  1627. // block the browser events
  1628. if( (inst.options.drag_block_vertical && ionic.Gestures.utils.isVertical(ev.direction)) ||
  1629. (inst.options.drag_block_horizontal && !ionic.Gestures.utils.isVertical(ev.direction))) {
  1630. ev.preventDefault();
  1631. }
  1632. break;
  1633. case ionic.Gestures.EVENT_END:
  1634. // trigger dragend
  1635. if(this.triggered) {
  1636. inst.trigger(this.name + 'end', ev);
  1637. }
  1638. this.triggered = false;
  1639. break;
  1640. }
  1641. }
  1642. };
  1643. /**
  1644. * Transform
  1645. * User want to scale or rotate with 2 fingers
  1646. * events transform, pinch, pinchin, pinchout, rotate
  1647. */
  1648. ionic.Gestures.gestures.Transform = {
  1649. name: 'transform',
  1650. index: 45,
  1651. defaults: {
  1652. // factor, no scale is 1, zoomin is to 0 and zoomout until higher then 1
  1653. transform_min_scale: 0.01,
  1654. // rotation in degrees
  1655. transform_min_rotation: 1,
  1656. // prevent default browser behavior when two touches are on the screen
  1657. // but it makes the element a blocking element
  1658. // when you are using the transform gesture, it is a good practice to set this true
  1659. transform_always_block: false
  1660. },
  1661. triggered: false,
  1662. handler: function transformGesture(ev, inst) {
  1663. // current gesture isnt drag, but dragged is true
  1664. // this means an other gesture is busy. now call dragend
  1665. if(ionic.Gestures.detection.current.name != this.name && this.triggered) {
  1666. inst.trigger(this.name + 'end', ev);
  1667. this.triggered = false;
  1668. return;
  1669. }
  1670. // atleast multitouch
  1671. if(ev.touches.length < 2) {
  1672. return;
  1673. }
  1674. // prevent default when two fingers are on the screen
  1675. if(inst.options.transform_always_block) {
  1676. ev.preventDefault();
  1677. }
  1678. switch(ev.eventType) {
  1679. case ionic.Gestures.EVENT_START:
  1680. this.triggered = false;
  1681. break;
  1682. case ionic.Gestures.EVENT_MOVE:
  1683. var scale_threshold = Math.abs(1 - ev.scale);
  1684. var rotation_threshold = Math.abs(ev.rotation);
  1685. // when the distance we moved is too small we skip this gesture
  1686. // or we can be already in dragging
  1687. if(scale_threshold < inst.options.transform_min_scale &&
  1688. rotation_threshold < inst.options.transform_min_rotation) {
  1689. return;
  1690. }
  1691. // we are transforming!
  1692. ionic.Gestures.detection.current.name = this.name;
  1693. // first time, trigger dragstart event
  1694. if(!this.triggered) {
  1695. inst.trigger(this.name + 'start', ev);
  1696. this.triggered = true;
  1697. }
  1698. inst.trigger(this.name, ev); // basic transform event
  1699. // trigger rotate event
  1700. if(rotation_threshold > inst.options.transform_min_rotation) {
  1701. inst.trigger('rotate', ev);
  1702. }
  1703. // trigger pinch event
  1704. if(scale_threshold > inst.options.transform_min_scale) {
  1705. inst.trigger('pinch', ev);
  1706. inst.trigger('pinch' + ((ev.scale < 1) ? 'in' : 'out'), ev);
  1707. }
  1708. break;
  1709. case ionic.Gestures.EVENT_END:
  1710. // trigger dragend
  1711. if(this.triggered) {
  1712. inst.trigger(this.name + 'end', ev);
  1713. }
  1714. this.triggered = false;
  1715. break;
  1716. }
  1717. }
  1718. };
  1719. /**
  1720. * Touch
  1721. * Called as first, tells the user has touched the screen
  1722. * events touch
  1723. */
  1724. ionic.Gestures.gestures.Touch = {
  1725. name: 'touch',
  1726. index: -Infinity,
  1727. defaults: {
  1728. // call preventDefault at touchstart, and makes the element blocking by
  1729. // disabling the scrolling of the page, but it improves gestures like
  1730. // transforming and dragging.
  1731. // be careful with using this, it can be very annoying for users to be stuck
  1732. // on the page
  1733. prevent_default: false,
  1734. // disable mouse events, so only touch (or pen!) input triggers events
  1735. prevent_mouseevents: false
  1736. },
  1737. handler: function touchGesture(ev, inst) {
  1738. if(inst.options.prevent_mouseevents && ev.pointerType == ionic.Gestures.POINTER_MOUSE) {
  1739. ev.stopDetect();
  1740. return;
  1741. }
  1742. if(inst.options.prevent_default) {
  1743. ev.preventDefault();
  1744. }
  1745. if(ev.eventType == ionic.Gestures.EVENT_START) {
  1746. inst.trigger(this.name, ev);
  1747. }
  1748. }
  1749. };
  1750. /**
  1751. * Release
  1752. * Called as last, tells the user has released the screen
  1753. * events release
  1754. */
  1755. ionic.Gestures.gestures.Release = {
  1756. name: 'release',
  1757. index: Infinity,
  1758. handler: function releaseGesture(ev, inst) {
  1759. if(ev.eventType == ionic.Gestures.EVENT_END) {
  1760. inst.trigger(this.name, ev);
  1761. }
  1762. }
  1763. };
  1764. })(window.ionic);
  1765. (function(window, document, ionic) {
  1766. function getParameterByName(name) {
  1767. name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  1768. var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  1769. results = regex.exec(location.search);
  1770. return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  1771. }
  1772. var IOS = 'ios';
  1773. var ANDROID = 'android';
  1774. var WINDOWS_PHONE = 'windowsphone';
  1775. var EDGE = 'edge';
  1776. var CROSSWALK = 'crosswalk';
  1777. var requestAnimationFrame = ionic.requestAnimationFrame;
  1778. /**
  1779. * @ngdoc utility
  1780. * @name ionic.Platform
  1781. * @module ionic
  1782. * @description
  1783. * A set of utility methods that can be used to retrieve the device ready state and
  1784. * various other information such as what kind of platform the app is currently installed on.
  1785. *
  1786. * @usage
  1787. * ```js
  1788. * angular.module('PlatformApp', ['ionic'])
  1789. * .controller('PlatformCtrl', function($scope) {
  1790. *
  1791. * ionic.Platform.ready(function(){
  1792. * // will execute when device is ready, or immediately if the device is already ready.
  1793. * });
  1794. *
  1795. * var deviceInformation = ionic.Platform.device();
  1796. *
  1797. * var isWebView = ionic.Platform.isWebView();
  1798. * var isIPad = ionic.Platform.isIPad();
  1799. * var isIOS = ionic.Platform.isIOS();
  1800. * var isAndroid = ionic.Platform.isAndroid();
  1801. * var isWindowsPhone = ionic.Platform.isWindowsPhone();
  1802. *
  1803. * var currentPlatform = ionic.Platform.platform();
  1804. * var currentPlatformVersion = ionic.Platform.version();
  1805. *
  1806. * ionic.Platform.exitApp(); // stops the app
  1807. * });
  1808. * ```
  1809. */
  1810. var self = ionic.Platform = {
  1811. // Put navigator on platform so it can be mocked and set
  1812. // the browser does not allow window.navigator to be set
  1813. navigator: window.navigator,
  1814. /**
  1815. * @ngdoc property
  1816. * @name ionic.Platform#isReady
  1817. * @returns {boolean} Whether the device is ready.
  1818. */
  1819. isReady: false,
  1820. /**
  1821. * @ngdoc property
  1822. * @name ionic.Platform#isFullScreen
  1823. * @returns {boolean} Whether the device is fullscreen.
  1824. */
  1825. isFullScreen: false,
  1826. /**
  1827. * @ngdoc property
  1828. * @name ionic.Platform#platforms
  1829. * @returns {Array(string)} An array of all platforms found.
  1830. */
  1831. platforms: null,
  1832. /**
  1833. * @ngdoc property
  1834. * @name ionic.Platform#grade
  1835. * @returns {string} What grade the current platform is.
  1836. */
  1837. grade: null,
  1838. /**
  1839. * @ngdoc property
  1840. * @name ionic.Platform#ua
  1841. * @returns {string} What User Agent is.
  1842. */
  1843. ua: navigator.userAgent,
  1844. /**
  1845. * @ngdoc method
  1846. * @name ionic.Platform#ready
  1847. * @description
  1848. * Trigger a callback once the device is ready, or immediately
  1849. * if the device is already ready. This method can be run from
  1850. * anywhere and does not need to be wrapped by any additonal methods.
  1851. * When the app is within a WebView (Cordova), it'll fire
  1852. * the callback once the device is ready. If the app is within
  1853. * a web browser, it'll fire the callback after `window.load`.
  1854. * Please remember that Cordova features (Camera, FileSystem, etc) still
  1855. * will not work in a web browser.
  1856. * @param {function} callback The function to call.
  1857. */
  1858. ready: function(cb) {
  1859. // run through tasks to complete now that the device is ready
  1860. if (self.isReady) {
  1861. cb();
  1862. } else {
  1863. // the platform isn't ready yet, add it to this array
  1864. // which will be called once the platform is ready
  1865. readyCallbacks.push(cb);
  1866. }
  1867. },
  1868. /**
  1869. * @private
  1870. */
  1871. detect: function() {
  1872. self._checkPlatforms();
  1873. requestAnimationFrame(function() {
  1874. // only add to the body class if we got platform info
  1875. for (var i = 0; i < self.platforms.length; i++) {
  1876. document.body.classList.add('platform-' + self.platforms[i]);
  1877. }
  1878. });
  1879. },
  1880. /**
  1881. * @ngdoc method
  1882. * @name ionic.Platform#setGrade
  1883. * @description Set the grade of the device: 'a', 'b', or 'c'. 'a' is the best
  1884. * (most css features enabled), 'c' is the worst. By default, sets the grade
  1885. * depending on the current device.
  1886. * @param {string} grade The new grade to set.
  1887. */
  1888. setGrade: function(grade) {
  1889. var oldGrade = self.grade;
  1890. self.grade = grade;
  1891. requestAnimationFrame(function() {
  1892. if (oldGrade) {
  1893. document.body.classList.remove('grade-' + oldGrade);
  1894. }
  1895. document.body.classList.add('grade-' + grade);
  1896. });
  1897. },
  1898. /**
  1899. * @ngdoc method
  1900. * @name ionic.Platform#device
  1901. * @description Return the current device (given by cordova).
  1902. * @returns {object} The device object.
  1903. */
  1904. device: function() {
  1905. return window.device || {};
  1906. },
  1907. _checkPlatforms: function() {
  1908. self.platforms = [];
  1909. var grade = 'a';
  1910. if (self.isWebView()) {
  1911. self.platforms.push('webview');
  1912. if (!(!window.cordova && !window.PhoneGap && !window.phonegap)) {
  1913. self.platforms.push('cordova');
  1914. } else if (typeof window.forge === 'object') {
  1915. self.platforms.push('trigger');
  1916. }
  1917. } else {
  1918. self.platforms.push('browser');
  1919. }
  1920. if (self.isIPad()) self.platforms.push('ipad');
  1921. var platform = self.platform();
  1922. if (platform) {
  1923. self.platforms.push(platform);
  1924. var version = self.version();
  1925. if (version) {
  1926. var v = version.toString();
  1927. if (v.indexOf('.') > 0) {
  1928. v = v.replace('.', '_');
  1929. } else {
  1930. v += '_0';
  1931. }
  1932. self.platforms.push(platform + v.split('_')[0]);
  1933. self.platforms.push(platform + v);
  1934. if (self.isAndroid() && version < 4.4) {
  1935. grade = (version < 4 ? 'c' : 'b');
  1936. } else if (self.isWindowsPhone()) {
  1937. grade = 'b';
  1938. }
  1939. }
  1940. }
  1941. self.setGrade(grade);
  1942. },
  1943. /**
  1944. * @ngdoc method
  1945. * @name ionic.Platform#isWebView
  1946. * @returns {boolean} Check if we are running within a WebView (such as Cordova).
  1947. */
  1948. isWebView: function() {
  1949. return !(!window.cordova && !window.PhoneGap && !window.phonegap && window.forge !== 'object');
  1950. },
  1951. /**
  1952. * @ngdoc method
  1953. * @name ionic.Platform#isIPad
  1954. * @returns {boolean} Whether we are running on iPad.
  1955. */
  1956. isIPad: function() {
  1957. if (/iPad/i.test(self.navigator.platform)) {
  1958. return true;
  1959. }
  1960. return /iPad/i.test(self.ua);
  1961. },
  1962. /**
  1963. * @ngdoc method
  1964. * @name ionic.Platform#isIOS
  1965. * @returns {boolean} Whether we are running on iOS.
  1966. */
  1967. isIOS: function() {
  1968. return self.is(IOS);
  1969. },
  1970. /**
  1971. * @ngdoc method
  1972. * @name ionic.Platform#isAndroid
  1973. * @returns {boolean} Whether we are running on Android.
  1974. */
  1975. isAndroid: function() {
  1976. return self.is(ANDROID);
  1977. },
  1978. /**
  1979. * @ngdoc method
  1980. * @name ionic.Platform#isWindowsPhone
  1981. * @returns {boolean} Whether we are running on Windows Phone.
  1982. */
  1983. isWindowsPhone: function() {
  1984. return self.is(WINDOWS_PHONE);
  1985. },
  1986. /**
  1987. * @ngdoc method
  1988. * @name ionic.Platform#isEdge
  1989. * @returns {boolean} Whether we are running on MS Edge/Windows 10 (inc. Phone)
  1990. */
  1991. isEdge: function() {
  1992. return self.is(EDGE);
  1993. },
  1994. isCrosswalk: function() {
  1995. return self.is(CROSSWALK);
  1996. },
  1997. /**
  1998. * @ngdoc method
  1999. * @name ionic.Platform#platform
  2000. * @returns {string} The name of the current platform.
  2001. */
  2002. platform: function() {
  2003. // singleton to get the platform name
  2004. if (platformName === null) self.setPlatform(self.device().platform);
  2005. return platformName;
  2006. },
  2007. /**
  2008. * @private
  2009. */
  2010. setPlatform: function(n) {
  2011. if (typeof n != 'undefined' && n !== null && n.length) {
  2012. platformName = n.toLowerCase();
  2013. } else if (getParameterByName('ionicplatform')) {
  2014. platformName = getParameterByName('ionicplatform');
  2015. } else if (self.ua.indexOf('Edge') > -1) {
  2016. platformName = EDGE;
  2017. } else if (self.ua.indexOf('Windows Phone') > -1) {
  2018. platformName = WINDOWS_PHONE;
  2019. } else if (self.ua.indexOf('Android') > 0) {
  2020. platformName = ANDROID;
  2021. } else if (/iPhone|iPad|iPod/.test(self.ua)) {
  2022. platformName = IOS;
  2023. } else {
  2024. platformName = self.navigator.platform && navigator.platform.toLowerCase().split(' ')[0] || '';
  2025. }
  2026. },
  2027. /**
  2028. * @ngdoc method
  2029. * @name ionic.Platform#version
  2030. * @returns {number} The version of the current device platform.
  2031. */
  2032. version: function() {
  2033. // singleton to get the platform version
  2034. if (platformVersion === null) self.setVersion(self.device().version);
  2035. return platformVersion;
  2036. },
  2037. /**
  2038. * @private
  2039. */
  2040. setVersion: function(v) {
  2041. if (typeof v != 'undefined' && v !== null) {
  2042. v = v.split('.');
  2043. v = parseFloat(v[0] + '.' + (v.length > 1 ? v[1] : 0));
  2044. if (!isNaN(v)) {
  2045. platformVersion = v;
  2046. return;
  2047. }
  2048. }
  2049. platformVersion = 0;
  2050. // fallback to user-agent checking
  2051. var pName = self.platform();
  2052. var versionMatch = {
  2053. 'android': /Android (\d+).(\d+)?/,
  2054. 'ios': /OS (\d+)_(\d+)?/,
  2055. 'windowsphone': /Windows Phone (\d+).(\d+)?/
  2056. };
  2057. if (versionMatch[pName]) {
  2058. v = self.ua.match(versionMatch[pName]);
  2059. if (v && v.length > 2) {
  2060. platformVersion = parseFloat(v[1] + '.' + v[2]);
  2061. }
  2062. }
  2063. },
  2064. /**
  2065. * @ngdoc method
  2066. * @name ionic.Platform#is
  2067. * @param {string} Platform name.
  2068. * @returns {boolean} Whether the platform name provided is detected.
  2069. */
  2070. is: function(type) {
  2071. type = type.toLowerCase();
  2072. // check if it has an array of platforms
  2073. if (self.platforms) {
  2074. for (var x = 0; x < self.platforms.length; x++) {
  2075. if (self.platforms[x] === type) return true;
  2076. }
  2077. }
  2078. // exact match
  2079. var pName = self.platform();
  2080. if (pName) {
  2081. return pName === type.toLowerCase();
  2082. }
  2083. // A quick hack for to check userAgent
  2084. return self.ua.toLowerCase().indexOf(type) >= 0;
  2085. },
  2086. /**
  2087. * @ngdoc method
  2088. * @name ionic.Platform#exitApp
  2089. * @description Exit the app.
  2090. */
  2091. exitApp: function() {
  2092. self.ready(function() {
  2093. navigator.app && navigator.app.exitApp && navigator.app.exitApp();
  2094. });
  2095. },
  2096. /**
  2097. * @ngdoc method
  2098. * @name ionic.Platform#showStatusBar
  2099. * @description Shows or hides the device status bar (in Cordova). Requires `cordova plugin add org.apache.cordova.statusbar`
  2100. * @param {boolean} shouldShow Whether or not to show the status bar.
  2101. */
  2102. showStatusBar: function(val) {
  2103. // Only useful when run within cordova
  2104. self._showStatusBar = val;
  2105. self.ready(function() {
  2106. // run this only when or if the platform (cordova) is ready
  2107. requestAnimationFrame(function() {
  2108. if (self._showStatusBar) {
  2109. // they do not want it to be full screen
  2110. window.StatusBar && window.StatusBar.show();
  2111. document.body.classList.remove('status-bar-hide');
  2112. } else {
  2113. // it should be full screen
  2114. window.StatusBar && window.StatusBar.hide();
  2115. document.body.classList.add('status-bar-hide');
  2116. }
  2117. });
  2118. });
  2119. },
  2120. /**
  2121. * @ngdoc method
  2122. * @name ionic.Platform#fullScreen
  2123. * @description
  2124. * Sets whether the app is fullscreen or not (in Cordova).
  2125. * @param {boolean=} showFullScreen Whether or not to set the app to fullscreen. Defaults to true. Requires `cordova plugin add org.apache.cordova.statusbar`
  2126. * @param {boolean=} showStatusBar Whether or not to show the device's status bar. Defaults to false.
  2127. */
  2128. fullScreen: function(showFullScreen, showStatusBar) {
  2129. // showFullScreen: default is true if no param provided
  2130. self.isFullScreen = (showFullScreen !== false);
  2131. // add/remove the fullscreen classname to the body
  2132. ionic.DomUtil.ready(function() {
  2133. // run this only when or if the DOM is ready
  2134. requestAnimationFrame(function() {
  2135. if (self.isFullScreen) {
  2136. document.body.classList.add('fullscreen');
  2137. } else {
  2138. document.body.classList.remove('fullscreen');
  2139. }
  2140. });
  2141. // showStatusBar: default is false if no param provided
  2142. self.showStatusBar((showStatusBar === true));
  2143. });
  2144. }
  2145. };
  2146. var platformName = null, // just the name, like iOS or Android
  2147. platformVersion = null, // a float of the major and minor, like 7.1
  2148. readyCallbacks = [],
  2149. windowLoadListenderAttached,
  2150. platformReadyTimer = 2000; // How long to wait for platform ready before emitting a warning
  2151. verifyPlatformReady();
  2152. // Warn the user if deviceready did not fire in a reasonable amount of time, and how to fix it.
  2153. function verifyPlatformReady() {
  2154. setTimeout(function() {
  2155. if(!self.isReady && self.isWebView()) {
  2156. void 0;
  2157. }
  2158. }, platformReadyTimer);
  2159. }
  2160. // setup listeners to know when the device is ready to go
  2161. function onWindowLoad() {
  2162. if (self.isWebView()) {
  2163. // the window and scripts are fully loaded, and a cordova/phonegap
  2164. // object exists then let's listen for the deviceready
  2165. document.addEventListener("deviceready", onPlatformReady, false);
  2166. } else {
  2167. // the window and scripts are fully loaded, but the window object doesn't have the
  2168. // cordova/phonegap object, so its just a browser, not a webview wrapped w/ cordova
  2169. onPlatformReady();
  2170. }
  2171. if (windowLoadListenderAttached) {
  2172. window.removeEventListener("load", onWindowLoad, false);
  2173. }
  2174. }
  2175. if (document.readyState === 'complete') {
  2176. onWindowLoad();
  2177. } else {
  2178. windowLoadListenderAttached = true;
  2179. window.addEventListener("load", onWindowLoad, false);
  2180. }
  2181. function onPlatformReady() {
  2182. // the device is all set to go, init our own stuff then fire off our event
  2183. self.isReady = true;
  2184. self.detect();
  2185. for (var x = 0; x < readyCallbacks.length; x++) {
  2186. // fire off all the callbacks that were added before the platform was ready
  2187. readyCallbacks[x]();
  2188. }
  2189. readyCallbacks = [];
  2190. ionic.trigger('platformready', { target: document });
  2191. requestAnimationFrame(function() {
  2192. document.body.classList.add('platform-ready');
  2193. });
  2194. }
  2195. })(window, document, ionic);
  2196. (function(document, ionic) {
  2197. 'use strict';
  2198. // Ionic CSS polyfills
  2199. ionic.CSS = {};
  2200. ionic.CSS.TRANSITION = [];
  2201. ionic.CSS.TRANSFORM = [];
  2202. ionic.EVENTS = {};
  2203. (function() {
  2204. // transform
  2205. var i, keys = ['webkitTransform', 'transform', '-webkit-transform', 'webkit-transform',
  2206. '-moz-transform', 'moz-transform', 'MozTransform', 'mozTransform', 'msTransform'];
  2207. for (i = 0; i < keys.length; i++) {
  2208. if (document.documentElement.style[keys[i]] !== undefined) {
  2209. ionic.CSS.TRANSFORM = keys[i];
  2210. break;
  2211. }
  2212. }
  2213. // transition
  2214. keys = ['webkitTransition', 'mozTransition', 'msTransition', 'transition'];
  2215. for (i = 0; i < keys.length; i++) {
  2216. if (document.documentElement.style[keys[i]] !== undefined) {
  2217. ionic.CSS.TRANSITION = keys[i];
  2218. break;
  2219. }
  2220. }
  2221. // Fallback in case the keys don't exist at all
  2222. ionic.CSS.TRANSITION = ionic.CSS.TRANSITION || 'transition';
  2223. // The only prefix we care about is webkit for transitions.
  2224. var isWebkit = ionic.CSS.TRANSITION.indexOf('webkit') > -1;
  2225. // transition duration
  2226. ionic.CSS.TRANSITION_DURATION = (isWebkit ? '-webkit-' : '') + 'transition-duration';
  2227. // To be sure transitionend works everywhere, include *both* the webkit and non-webkit events
  2228. ionic.CSS.TRANSITIONEND = (isWebkit ? 'webkitTransitionEnd ' : '') + 'transitionend';
  2229. })();
  2230. (function() {
  2231. var touchStartEvent = 'touchstart';
  2232. var touchMoveEvent = 'touchmove';
  2233. var touchEndEvent = 'touchend';
  2234. var touchCancelEvent = 'touchcancel';
  2235. if (window.navigator.pointerEnabled) {
  2236. touchStartEvent = 'pointerdown';
  2237. touchMoveEvent = 'pointermove';
  2238. touchEndEvent = 'pointerup';
  2239. touchCancelEvent = 'pointercancel';
  2240. } else if (window.navigator.msPointerEnabled) {
  2241. touchStartEvent = 'MSPointerDown';
  2242. touchMoveEvent = 'MSPointerMove';
  2243. touchEndEvent = 'MSPointerUp';
  2244. touchCancelEvent = 'MSPointerCancel';
  2245. }
  2246. ionic.EVENTS.touchstart = touchStartEvent;
  2247. ionic.EVENTS.touchmove = touchMoveEvent;
  2248. ionic.EVENTS.touchend = touchEndEvent;
  2249. ionic.EVENTS.touchcancel = touchCancelEvent;
  2250. })();
  2251. // classList polyfill for them older Androids
  2252. // https://gist.github.com/devongovett/1381839
  2253. if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
  2254. Object.defineProperty(HTMLElement.prototype, 'classList', {
  2255. get: function() {
  2256. var self = this;
  2257. function update(fn) {
  2258. return function() {
  2259. var x, classes = self.className.split(/\s+/);
  2260. for (x = 0; x < arguments.length; x++) {
  2261. fn(classes, classes.indexOf(arguments[x]), arguments[x]);
  2262. }
  2263. self.className = classes.join(" ");
  2264. };
  2265. }
  2266. return {
  2267. add: update(function(classes, index, value) {
  2268. ~index || classes.push(value);
  2269. }),
  2270. remove: update(function(classes, index) {
  2271. ~index && classes.splice(index, 1);
  2272. }),
  2273. toggle: update(function(classes, index, value) {
  2274. ~index ? classes.splice(index, 1) : classes.push(value);
  2275. }),
  2276. contains: function(value) {
  2277. return !!~self.className.split(/\s+/).indexOf(value);
  2278. },
  2279. item: function(i) {
  2280. return self.className.split(/\s+/)[i] || null;
  2281. }
  2282. };
  2283. }
  2284. });
  2285. }
  2286. })(document, ionic);
  2287. /**
  2288. * @ngdoc page
  2289. * @name tap
  2290. * @module ionic
  2291. * @description
  2292. * On touch devices such as a phone or tablet, some browsers implement a 300ms delay between
  2293. * the time the user stops touching the display and the moment the browser executes the
  2294. * click. This delay was initially introduced so the browser can know whether the user wants to
  2295. * double-tap to zoom in on the webpage. Basically, the browser waits roughly 300ms to see if
  2296. * the user is double-tapping, or just tapping on the display once.
  2297. *
  2298. * Out of the box, Ionic automatically removes the 300ms delay in order to make Ionic apps
  2299. * feel more "native" like. Resultingly, other solutions such as
  2300. * [fastclick](https://github.com/ftlabs/fastclick) and Angular's
  2301. * [ngTouch](https://docs.angularjs.org/api/ngTouch) should not be included, to avoid conflicts.
  2302. *
  2303. * Some browsers already remove the delay with certain settings, such as the CSS property
  2304. * `touch-events: none` or with specific meta tag viewport values. However, each of these
  2305. * browsers still handle clicks differently, such as when to fire off or cancel the event
  2306. * (like scrolling when the target is a button, or holding a button down).
  2307. * For browsers that already remove the 300ms delay, consider Ionic's tap system as a way to
  2308. * normalize how clicks are handled across the various devices so there's an expected response
  2309. * no matter what the device, platform or version. Additionally, Ionic will prevent
  2310. * ghostclicks which even browsers that remove the delay still experience.
  2311. *
  2312. * In some cases, third-party libraries may also be working with touch events which can interfere
  2313. * with the tap system. For example, mapping libraries like Google or Leaflet Maps often implement
  2314. * a touch detection system which conflicts with Ionic's tap system.
  2315. *
  2316. * ### Disabling the tap system
  2317. *
  2318. * To disable the tap for an element and all of its children elements,
  2319. * add the attribute `data-tap-disabled="true"`.
  2320. *
  2321. * ```html
  2322. * <div data-tap-disabled="true">
  2323. * <div id="google-map"></div>
  2324. * </div>
  2325. * ```
  2326. *
  2327. * ### Additional Notes:
  2328. *
  2329. * - Ionic tap works with Ionic's JavaScript scrolling
  2330. * - Elements can come and go from the DOM and Ionic tap doesn't keep adding and removing
  2331. * listeners
  2332. * - No "tap delay" after the first "tap" (you can tap as fast as you want, they all click)
  2333. * - Minimal events listeners, only being added to document
  2334. * - Correct focus in/out on each input type (select, textearea, range) on each platform/device
  2335. * - Shows and hides virtual keyboard correctly for each platform/device
  2336. * - Works with labels surrounding inputs
  2337. * - Does not fire off a click if the user moves the pointer too far
  2338. * - Adds and removes an 'activated' css class
  2339. * - Multiple [unit tests](https://github.com/driftyco/ionic/blob/master/test/unit/utils/tap.unit.js) for each scenario
  2340. *
  2341. */
  2342. /*
  2343. IONIC TAP
  2344. ---------------
  2345. - Both touch and mouse events are added to the document.body on DOM ready
  2346. - If a touch event happens, it does not use mouse event listeners
  2347. - On touchend, if the distance between start and end was small, trigger a click
  2348. - In the triggered click event, add a 'isIonicTap' property
  2349. - The triggered click receives the same x,y coordinates as as the end event
  2350. - On document.body click listener (with useCapture=true), only allow clicks with 'isIonicTap'
  2351. - Triggering clicks with mouse events work the same as touch, except with mousedown/mouseup
  2352. - Tapping inputs is disabled during scrolling
  2353. */
  2354. var tapDoc; // the element which the listeners are on (document.body)
  2355. var tapActiveEle; // the element which is active (probably has focus)
  2356. var tapEnabledTouchEvents;
  2357. var tapMouseResetTimer;
  2358. var tapPointerMoved;
  2359. var tapPointerStart;
  2360. var tapTouchFocusedInput;
  2361. var tapLastTouchTarget;
  2362. var tapTouchMoveListener = 'touchmove';
  2363. // how much the coordinates can be off between start/end, but still a click
  2364. var TAP_RELEASE_TOLERANCE = 12; // default tolerance
  2365. var TAP_RELEASE_BUTTON_TOLERANCE = 50; // button elements should have a larger tolerance
  2366. var tapEventListeners = {
  2367. 'click': tapClickGateKeeper,
  2368. 'mousedown': tapMouseDown,
  2369. 'mouseup': tapMouseUp,
  2370. 'mousemove': tapMouseMove,
  2371. 'touchstart': tapTouchStart,
  2372. 'touchend': tapTouchEnd,
  2373. 'touchcancel': tapTouchCancel,
  2374. 'touchmove': tapTouchMove,
  2375. 'pointerdown': tapTouchStart,
  2376. 'pointerup': tapTouchEnd,
  2377. 'pointercancel': tapTouchCancel,
  2378. 'pointermove': tapTouchMove,
  2379. 'MSPointerDown': tapTouchStart,
  2380. 'MSPointerUp': tapTouchEnd,
  2381. 'MSPointerCancel': tapTouchCancel,
  2382. 'MSPointerMove': tapTouchMove,
  2383. 'focusin': tapFocusIn,
  2384. 'focusout': tapFocusOut
  2385. };
  2386. ionic.tap = {
  2387. register: function(ele) {
  2388. tapDoc = ele;
  2389. tapEventListener('click', true, true);
  2390. tapEventListener('mouseup');
  2391. tapEventListener('mousedown');
  2392. if (window.navigator.pointerEnabled) {
  2393. tapEventListener('pointerdown');
  2394. tapEventListener('pointerup');
  2395. tapEventListener('pointercancel');
  2396. tapTouchMoveListener = 'pointermove';
  2397. } else if (window.navigator.msPointerEnabled) {
  2398. tapEventListener('MSPointerDown');
  2399. tapEventListener('MSPointerUp');
  2400. tapEventListener('MSPointerCancel');
  2401. tapTouchMoveListener = 'MSPointerMove';
  2402. } else {
  2403. tapEventListener('touchstart');
  2404. tapEventListener('touchend');
  2405. tapEventListener('touchcancel');
  2406. }
  2407. tapEventListener('focusin');
  2408. tapEventListener('focusout');
  2409. return function() {
  2410. for (var type in tapEventListeners) {
  2411. tapEventListener(type, false);
  2412. }
  2413. tapDoc = null;
  2414. tapActiveEle = null;
  2415. tapEnabledTouchEvents = false;
  2416. tapPointerMoved = false;
  2417. tapPointerStart = null;
  2418. };
  2419. },
  2420. ignoreScrollStart: function(e) {
  2421. return (e.defaultPrevented) || // defaultPrevented has been assigned by another component handling the event
  2422. (/^(file|range)$/i).test(e.target.type) ||
  2423. (e.target.dataset ? e.target.dataset.preventScroll : e.target.getAttribute('data-prevent-scroll')) == 'true' || // manually set within an elements attributes
  2424. (!!(/^(object|embed)$/i).test(e.target.tagName)) || // flash/movie/object touches should not try to scroll
  2425. ionic.tap.isElementTapDisabled(e.target); // check if this element, or an ancestor, has `data-tap-disabled` attribute
  2426. },
  2427. isTextInput: function(ele) {
  2428. return !!ele &&
  2429. (ele.tagName == 'TEXTAREA' ||
  2430. ele.contentEditable === 'true' ||
  2431. (ele.tagName == 'INPUT' && !(/^(radio|checkbox|range|file|submit|reset|color|image|button)$/i).test(ele.type)));
  2432. },
  2433. isDateInput: function(ele) {
  2434. return !!ele &&
  2435. (ele.tagName == 'INPUT' && (/^(date|time|datetime-local|month|week)$/i).test(ele.type));
  2436. },
  2437. isVideo: function(ele) {
  2438. return !!ele &&
  2439. (ele.tagName == 'VIDEO');
  2440. },
  2441. isKeyboardElement: function(ele) {
  2442. if ( !ionic.Platform.isIOS() || ionic.Platform.isIPad() ) {
  2443. return ionic.tap.isTextInput(ele) && !ionic.tap.isDateInput(ele);
  2444. } else {
  2445. return ionic.tap.isTextInput(ele) || ( !!ele && ele.tagName == "SELECT");
  2446. }
  2447. },
  2448. isLabelWithTextInput: function(ele) {
  2449. var container = tapContainingElement(ele, false);
  2450. return !!container &&
  2451. ionic.tap.isTextInput(tapTargetElement(container));
  2452. },
  2453. containsOrIsTextInput: function(ele) {
  2454. return ionic.tap.isTextInput(ele) || ionic.tap.isLabelWithTextInput(ele);
  2455. },
  2456. cloneFocusedInput: function(container) {
  2457. if (ionic.tap.hasCheckedClone) return;
  2458. ionic.tap.hasCheckedClone = true;
  2459. ionic.requestAnimationFrame(function() {
  2460. var focusInput = container.querySelector(':focus');
  2461. if (ionic.tap.isTextInput(focusInput) && !ionic.tap.isDateInput(focusInput)) {
  2462. var clonedInput = focusInput.cloneNode(true);
  2463. clonedInput.value = focusInput.value;
  2464. clonedInput.classList.add('cloned-text-input');
  2465. clonedInput.readOnly = true;
  2466. if (focusInput.isContentEditable) {
  2467. clonedInput.contentEditable = focusInput.contentEditable;
  2468. clonedInput.innerHTML = focusInput.innerHTML;
  2469. }
  2470. focusInput.parentElement.insertBefore(clonedInput, focusInput);
  2471. focusInput.classList.add('previous-input-focus');
  2472. clonedInput.scrollTop = focusInput.scrollTop;
  2473. }
  2474. });
  2475. },
  2476. hasCheckedClone: false,
  2477. removeClonedInputs: function(container) {
  2478. ionic.tap.hasCheckedClone = false;
  2479. ionic.requestAnimationFrame(function() {
  2480. var clonedInputs = container.querySelectorAll('.cloned-text-input');
  2481. var previousInputFocus = container.querySelectorAll('.previous-input-focus');
  2482. var x;
  2483. for (x = 0; x < clonedInputs.length; x++) {
  2484. clonedInputs[x].parentElement.removeChild(clonedInputs[x]);
  2485. }
  2486. for (x = 0; x < previousInputFocus.length; x++) {
  2487. previousInputFocus[x].classList.remove('previous-input-focus');
  2488. previousInputFocus[x].style.top = '';
  2489. if ( ionic.keyboard.isOpen && !ionic.keyboard.isClosing ) previousInputFocus[x].focus();
  2490. }
  2491. });
  2492. },
  2493. requiresNativeClick: function(ele) {
  2494. if (ionic.Platform.isWindowsPhone() && (ele.tagName == 'A' || ele.tagName == 'BUTTON' || ele.hasAttribute('ng-click') || (ele.tagName == 'INPUT' && (ele.type == 'button' || ele.type == 'submit')))) {
  2495. return true; //Windows Phone edge case, prevent ng-click (and similar) events from firing twice on this platform
  2496. }
  2497. if (!ele || ele.disabled || (/^(file|range)$/i).test(ele.type) || (/^(object|video)$/i).test(ele.tagName) || ionic.tap.isLabelContainingFileInput(ele)) {
  2498. return true;
  2499. }
  2500. return ionic.tap.isElementTapDisabled(ele);
  2501. },
  2502. isLabelContainingFileInput: function(ele) {
  2503. var lbl = tapContainingElement(ele);
  2504. if (lbl.tagName !== 'LABEL') return false;
  2505. var fileInput = lbl.querySelector('input[type=file]');
  2506. if (fileInput && fileInput.disabled === false) return true;
  2507. return false;
  2508. },
  2509. isElementTapDisabled: function(ele) {
  2510. if (ele && ele.nodeType === 1) {
  2511. var element = ele;
  2512. while (element) {
  2513. if (element.getAttribute && element.getAttribute('data-tap-disabled') == 'true') {
  2514. return true;
  2515. }
  2516. element = element.parentElement;
  2517. }
  2518. }
  2519. return false;
  2520. },
  2521. setTolerance: function(releaseTolerance, releaseButtonTolerance) {
  2522. TAP_RELEASE_TOLERANCE = releaseTolerance;
  2523. TAP_RELEASE_BUTTON_TOLERANCE = releaseButtonTolerance;
  2524. },
  2525. cancelClick: function() {
  2526. // used to cancel any simulated clicks which may happen on a touchend/mouseup
  2527. // gestures uses this method within its tap and hold events
  2528. tapPointerMoved = true;
  2529. },
  2530. pointerCoord: function(event) {
  2531. // This method can get coordinates for both a mouse click
  2532. // or a touch depending on the given event
  2533. var c = { x: 0, y: 0 };
  2534. if (event) {
  2535. var touches = event.touches && event.touches.length ? event.touches : [event];
  2536. var e = (event.changedTouches && event.changedTouches[0]) || touches[0];
  2537. if (e) {
  2538. c.x = e.clientX || e.pageX || 0;
  2539. c.y = e.clientY || e.pageY || 0;
  2540. }
  2541. }
  2542. return c;
  2543. }
  2544. };
  2545. function tapEventListener(type, enable, useCapture) {
  2546. if (enable !== false) {
  2547. tapDoc.addEventListener(type, tapEventListeners[type], useCapture);
  2548. } else {
  2549. tapDoc.removeEventListener(type, tapEventListeners[type]);
  2550. }
  2551. }
  2552. function tapClick(e) {
  2553. // simulate a normal click by running the element's click method then focus on it
  2554. var container = tapContainingElement(e.target);
  2555. var ele = tapTargetElement(container);
  2556. if (ionic.tap.requiresNativeClick(ele) || tapPointerMoved) return false;
  2557. var c = ionic.tap.pointerCoord(e);
  2558. //console.log('tapClick', e.type, ele.tagName, '('+c.x+','+c.y+')');
  2559. triggerMouseEvent('click', ele, c.x, c.y);
  2560. // if it's an input, focus in on the target, otherwise blur
  2561. tapHandleFocus(ele);
  2562. }
  2563. function triggerMouseEvent(type, ele, x, y) {
  2564. // using initMouseEvent instead of MouseEvent for our Android friends
  2565. var clickEvent = document.createEvent("MouseEvents");
  2566. clickEvent.initMouseEvent(type, true, true, window, 1, 0, 0, x, y, false, false, false, false, 0, null);
  2567. clickEvent.isIonicTap = true;
  2568. ele.dispatchEvent(clickEvent);
  2569. }
  2570. function tapClickGateKeeper(e) {
  2571. //console.log('click ' + Date.now() + ' isIonicTap: ' + (e.isIonicTap ? true : false));
  2572. if (e.target.type == 'submit' && e.detail === 0) {
  2573. // do not prevent click if it came from an "Enter" or "Go" keypress submit
  2574. return null;
  2575. }
  2576. // do not allow through any click events that were not created by ionic.tap
  2577. if ((ionic.scroll.isScrolling && ionic.tap.containsOrIsTextInput(e.target)) ||
  2578. (!e.isIonicTap && !ionic.tap.requiresNativeClick(e.target))) {
  2579. //console.log('clickPrevent', e.target.tagName);
  2580. e.stopPropagation();
  2581. if (!ionic.tap.isLabelWithTextInput(e.target)) {
  2582. // labels clicks from native should not preventDefault othersize keyboard will not show on input focus
  2583. e.preventDefault();
  2584. }
  2585. return false;
  2586. }
  2587. }
  2588. // MOUSE
  2589. function tapMouseDown(e) {
  2590. //console.log('mousedown ' + Date.now());
  2591. if (e.isIonicTap || tapIgnoreEvent(e)) return null;
  2592. if (tapEnabledTouchEvents) {
  2593. //console.log('mousedown', 'stop event');
  2594. e.stopPropagation();
  2595. if (!ionic.Platform.isEdge() && (!ionic.tap.isTextInput(e.target) || tapLastTouchTarget !== e.target) &&
  2596. !isSelectOrOption(e.target.tagName) && !ionic.tap.isVideo(e.target)) {
  2597. // If you preventDefault on a text input then you cannot move its text caret/cursor.
  2598. // Allow through only the text input default. However, without preventDefault on an
  2599. // input the 300ms delay can change focus on inputs after the keyboard shows up.
  2600. // The focusin event handles the chance of focus changing after the keyboard shows.
  2601. // Windows Phone - if you preventDefault on a video element then you cannot operate
  2602. // its native controls.
  2603. e.preventDefault();
  2604. }
  2605. return false;
  2606. }
  2607. tapPointerMoved = false;
  2608. tapPointerStart = ionic.tap.pointerCoord(e);
  2609. tapEventListener('mousemove');
  2610. ionic.activator.start(e);
  2611. }
  2612. function tapMouseUp(e) {
  2613. //console.log("mouseup " + Date.now());
  2614. if (tapEnabledTouchEvents) {
  2615. e.stopPropagation();
  2616. e.preventDefault();
  2617. return false;
  2618. }
  2619. if (tapIgnoreEvent(e) || isSelectOrOption(e.target.tagName)) return false;
  2620. if (!tapHasPointerMoved(e)) {
  2621. tapClick(e);
  2622. }
  2623. tapEventListener('mousemove', false);
  2624. ionic.activator.end();
  2625. tapPointerMoved = false;
  2626. }
  2627. function tapMouseMove(e) {
  2628. if (tapHasPointerMoved(e)) {
  2629. tapEventListener('mousemove', false);
  2630. ionic.activator.end();
  2631. tapPointerMoved = true;
  2632. return false;
  2633. }
  2634. }
  2635. // TOUCH
  2636. function tapTouchStart(e) {
  2637. //console.log("touchstart " + Date.now());
  2638. if (tapIgnoreEvent(e)) return;
  2639. tapPointerMoved = false;
  2640. tapEnableTouchEvents();
  2641. tapPointerStart = ionic.tap.pointerCoord(e);
  2642. tapEventListener(tapTouchMoveListener);
  2643. ionic.activator.start(e);
  2644. if (ionic.Platform.isIOS() && ionic.tap.isLabelWithTextInput(e.target)) {
  2645. // if the tapped element is a label, which has a child input
  2646. // then preventDefault so iOS doesn't ugly auto scroll to the input
  2647. // but do not prevent default on Android or else you cannot move the text caret
  2648. // and do not prevent default on Android or else no virtual keyboard shows up
  2649. var textInput = tapTargetElement(tapContainingElement(e.target));
  2650. if (textInput !== tapActiveEle) {
  2651. // don't preventDefault on an already focused input or else iOS's text caret isn't usable
  2652. //console.log('Would prevent default here');
  2653. e.preventDefault();
  2654. }
  2655. }
  2656. }
  2657. function tapTouchEnd(e) {
  2658. //console.log('touchend ' + Date.now());
  2659. if (tapIgnoreEvent(e)) return;
  2660. tapEnableTouchEvents();
  2661. if (!tapHasPointerMoved(e)) {
  2662. tapClick(e);
  2663. if (isSelectOrOption(e.target.tagName)) {
  2664. e.preventDefault();
  2665. }
  2666. }
  2667. tapLastTouchTarget = e.target;
  2668. tapTouchCancel();
  2669. }
  2670. function tapTouchMove(e) {
  2671. if (tapHasPointerMoved(e)) {
  2672. tapPointerMoved = true;
  2673. tapEventListener(tapTouchMoveListener, false);
  2674. ionic.activator.end();
  2675. return false;
  2676. }
  2677. }
  2678. function tapTouchCancel() {
  2679. tapEventListener(tapTouchMoveListener, false);
  2680. ionic.activator.end();
  2681. tapPointerMoved = false;
  2682. }
  2683. function tapEnableTouchEvents() {
  2684. tapEnabledTouchEvents = true;
  2685. clearTimeout(tapMouseResetTimer);
  2686. tapMouseResetTimer = setTimeout(function() {
  2687. tapEnabledTouchEvents = false;
  2688. }, 600);
  2689. }
  2690. function tapIgnoreEvent(e) {
  2691. if (e.isTapHandled) return true;
  2692. e.isTapHandled = true;
  2693. if(ionic.tap.isElementTapDisabled(e.target)) {
  2694. return true;
  2695. }
  2696. if (ionic.scroll.isScrolling && ionic.tap.containsOrIsTextInput(e.target)) {
  2697. e.preventDefault();
  2698. return true;
  2699. }
  2700. }
  2701. function tapHandleFocus(ele) {
  2702. tapTouchFocusedInput = null;
  2703. var triggerFocusIn = false;
  2704. if (ele.tagName == 'SELECT') {
  2705. // trick to force Android options to show up
  2706. triggerMouseEvent('mousedown', ele, 0, 0);
  2707. ele.focus && ele.focus();
  2708. triggerFocusIn = true;
  2709. } else if (tapActiveElement() === ele) {
  2710. // already is the active element and has focus
  2711. triggerFocusIn = true;
  2712. } else if ((/^(input|textarea|ion-label)$/i).test(ele.tagName) || ele.isContentEditable) {
  2713. triggerFocusIn = true;
  2714. ele.focus && ele.focus();
  2715. ele.value = ele.value;
  2716. if (tapEnabledTouchEvents) {
  2717. tapTouchFocusedInput = ele;
  2718. }
  2719. } else {
  2720. tapFocusOutActive();
  2721. }
  2722. if (triggerFocusIn) {
  2723. tapActiveElement(ele);
  2724. ionic.trigger('ionic.focusin', {
  2725. target: ele
  2726. }, true);
  2727. }
  2728. }
  2729. function tapFocusOutActive() {
  2730. var ele = tapActiveElement();
  2731. if (ele && ((/^(input|textarea|select)$/i).test(ele.tagName) || ele.isContentEditable)) {
  2732. //console.log('tapFocusOutActive', ele.tagName);
  2733. ele.blur();
  2734. }
  2735. tapActiveElement(null);
  2736. }
  2737. function tapFocusIn(e) {
  2738. //console.log('focusin ' + Date.now());
  2739. // Because a text input doesn't preventDefault (so the caret still works) there's a chance
  2740. // that its mousedown event 300ms later will change the focus to another element after
  2741. // the keyboard shows up.
  2742. if (tapEnabledTouchEvents &&
  2743. ionic.tap.isTextInput(tapActiveElement()) &&
  2744. ionic.tap.isTextInput(tapTouchFocusedInput) &&
  2745. tapTouchFocusedInput !== e.target) {
  2746. // 1) The pointer is from touch events
  2747. // 2) There is an active element which is a text input
  2748. // 3) A text input was just set to be focused on by a touch event
  2749. // 4) A new focus has been set, however the target isn't the one the touch event wanted
  2750. //console.log('focusin', 'tapTouchFocusedInput');
  2751. tapTouchFocusedInput.focus();
  2752. tapTouchFocusedInput = null;
  2753. }
  2754. ionic.scroll.isScrolling = false;
  2755. }
  2756. function tapFocusOut() {
  2757. //console.log("focusout");
  2758. tapActiveElement(null);
  2759. }
  2760. function tapActiveElement(ele) {
  2761. if (arguments.length) {
  2762. tapActiveEle = ele;
  2763. }
  2764. return tapActiveEle || document.activeElement;
  2765. }
  2766. function tapHasPointerMoved(endEvent) {
  2767. if (!endEvent || endEvent.target.nodeType !== 1 || !tapPointerStart || (tapPointerStart.x === 0 && tapPointerStart.y === 0)) {
  2768. return false;
  2769. }
  2770. var endCoordinates = ionic.tap.pointerCoord(endEvent);
  2771. var hasClassList = !!(endEvent.target.classList && endEvent.target.classList.contains &&
  2772. typeof endEvent.target.classList.contains === 'function');
  2773. var releaseTolerance = hasClassList && endEvent.target.classList.contains('button') ?
  2774. TAP_RELEASE_BUTTON_TOLERANCE :
  2775. TAP_RELEASE_TOLERANCE;
  2776. return Math.abs(tapPointerStart.x - endCoordinates.x) > releaseTolerance ||
  2777. Math.abs(tapPointerStart.y - endCoordinates.y) > releaseTolerance;
  2778. }
  2779. function tapContainingElement(ele, allowSelf) {
  2780. var climbEle = ele;
  2781. for (var x = 0; x < 6; x++) {
  2782. if (!climbEle) break;
  2783. if (climbEle.tagName === 'LABEL') return climbEle;
  2784. climbEle = climbEle.parentElement;
  2785. }
  2786. if (allowSelf !== false) return ele;
  2787. }
  2788. function tapTargetElement(ele) {
  2789. if (ele && ele.tagName === 'LABEL') {
  2790. if (ele.control) return ele.control;
  2791. // older devices do not support the "control" property
  2792. if (ele.querySelector) {
  2793. var control = ele.querySelector('input,textarea,select');
  2794. if (control) return control;
  2795. }
  2796. }
  2797. return ele;
  2798. }
  2799. function isSelectOrOption(tagName){
  2800. return (/^(select|option)$/i).test(tagName);
  2801. }
  2802. ionic.DomUtil.ready(function() {
  2803. var ng = typeof angular !== 'undefined' ? angular : null;
  2804. //do nothing for e2e tests
  2805. if (!ng || (ng && !ng.scenario)) {
  2806. ionic.tap.register(document);
  2807. }
  2808. });
  2809. (function(document, ionic) {
  2810. 'use strict';
  2811. var queueElements = {}; // elements that should get an active state in XX milliseconds
  2812. var activeElements = {}; // elements that are currently active
  2813. var keyId = 0; // a counter for unique keys for the above ojects
  2814. var ACTIVATED_CLASS = 'activated';
  2815. ionic.activator = {
  2816. start: function(e) {
  2817. var hitX = ionic.tap.pointerCoord(e).x;
  2818. if (hitX > 0 && hitX < 30) {
  2819. return;
  2820. }
  2821. // when an element is touched/clicked, it climbs up a few
  2822. // parents to see if it is an .item or .button element
  2823. ionic.requestAnimationFrame(function() {
  2824. if ((ionic.scroll && ionic.scroll.isScrolling) || ionic.tap.requiresNativeClick(e.target)) return;
  2825. var ele = e.target;
  2826. var eleToActivate;
  2827. for (var x = 0; x < 6; x++) {
  2828. if (!ele || ele.nodeType !== 1) break;
  2829. if (eleToActivate && ele.classList && ele.classList.contains('item')) {
  2830. eleToActivate = ele;
  2831. break;
  2832. }
  2833. if (ele.tagName == 'A' || ele.tagName == 'BUTTON' || ele.hasAttribute('ng-click')) {
  2834. eleToActivate = ele;
  2835. break;
  2836. }
  2837. if (ele.classList && ele.classList.contains('button')) {
  2838. eleToActivate = ele;
  2839. break;
  2840. }
  2841. // no sense climbing past these
  2842. if (ele.tagName == 'ION-CONTENT' || (ele.classList && ele.classList.contains('pane')) || ele.tagName == 'BODY') {
  2843. break;
  2844. }
  2845. ele = ele.parentElement;
  2846. }
  2847. if (eleToActivate) {
  2848. // queue that this element should be set to active
  2849. queueElements[keyId] = eleToActivate;
  2850. // on the next frame, set the queued elements to active
  2851. ionic.requestAnimationFrame(activateElements);
  2852. keyId = (keyId > 29 ? 0 : keyId + 1);
  2853. }
  2854. });
  2855. },
  2856. end: function() {
  2857. // clear out any active/queued elements after XX milliseconds
  2858. setTimeout(clear, 200);
  2859. }
  2860. };
  2861. function clear() {
  2862. // clear out any elements that are queued to be set to active
  2863. queueElements = {};
  2864. // in the next frame, remove the active class from all active elements
  2865. ionic.requestAnimationFrame(deactivateElements);
  2866. }
  2867. function activateElements() {
  2868. // activate all elements in the queue
  2869. for (var key in queueElements) {
  2870. if (queueElements[key]) {
  2871. queueElements[key].classList.add(ACTIVATED_CLASS);
  2872. activeElements[key] = queueElements[key];
  2873. }
  2874. }
  2875. queueElements = {};
  2876. }
  2877. function deactivateElements() {
  2878. if (ionic.transition && ionic.transition.isActive) {
  2879. setTimeout(deactivateElements, 400);
  2880. return;
  2881. }
  2882. for (var key in activeElements) {
  2883. if (activeElements[key]) {
  2884. activeElements[key].classList.remove(ACTIVATED_CLASS);
  2885. delete activeElements[key];
  2886. }
  2887. }
  2888. }
  2889. })(document, ionic);
  2890. (function(ionic) {
  2891. /* for nextUid function below */
  2892. var nextId = 0;
  2893. /**
  2894. * Various utilities used throughout Ionic
  2895. *
  2896. * Some of these are adopted from underscore.js and backbone.js, both also MIT licensed.
  2897. */
  2898. ionic.Utils = {
  2899. arrayMove: function(arr, oldIndex, newIndex) {
  2900. if (newIndex >= arr.length) {
  2901. var k = newIndex - arr.length;
  2902. while ((k--) + 1) {
  2903. arr.push(undefined);
  2904. }
  2905. }
  2906. arr.splice(newIndex, 0, arr.splice(oldIndex, 1)[0]);
  2907. return arr;
  2908. },
  2909. /**
  2910. * Return a function that will be called with the given context
  2911. */
  2912. proxy: function(func, context) {
  2913. var args = Array.prototype.slice.call(arguments, 2);
  2914. return function() {
  2915. return func.apply(context, args.concat(Array.prototype.slice.call(arguments)));
  2916. };
  2917. },
  2918. /**
  2919. * Only call a function once in the given interval.
  2920. *
  2921. * @param func {Function} the function to call
  2922. * @param wait {int} how long to wait before/after to allow function calls
  2923. * @param immediate {boolean} whether to call immediately or after the wait interval
  2924. */
  2925. debounce: function(func, wait, immediate) {
  2926. var timeout, args, context, timestamp, result;
  2927. return function() {
  2928. context = this;
  2929. args = arguments;
  2930. timestamp = new Date();
  2931. var later = function() {
  2932. var last = (new Date()) - timestamp;
  2933. if (last < wait) {
  2934. timeout = setTimeout(later, wait - last);
  2935. } else {
  2936. timeout = null;
  2937. if (!immediate) result = func.apply(context, args);
  2938. }
  2939. };
  2940. var callNow = immediate && !timeout;
  2941. if (!timeout) {
  2942. timeout = setTimeout(later, wait);
  2943. }
  2944. if (callNow) result = func.apply(context, args);
  2945. return result;
  2946. };
  2947. },
  2948. /**
  2949. * Throttle the given fun, only allowing it to be
  2950. * called at most every `wait` ms.
  2951. */
  2952. throttle: function(func, wait, options) {
  2953. var context, args, result;
  2954. var timeout = null;
  2955. var previous = 0;
  2956. options || (options = {});
  2957. var later = function() {
  2958. previous = options.leading === false ? 0 : Date.now();
  2959. timeout = null;
  2960. result = func.apply(context, args);
  2961. };
  2962. return function() {
  2963. var now = Date.now();
  2964. if (!previous && options.leading === false) previous = now;
  2965. var remaining = wait - (now - previous);
  2966. context = this;
  2967. args = arguments;
  2968. if (remaining <= 0) {
  2969. clearTimeout(timeout);
  2970. timeout = null;
  2971. previous = now;
  2972. result = func.apply(context, args);
  2973. } else if (!timeout && options.trailing !== false) {
  2974. timeout = setTimeout(later, remaining);
  2975. }
  2976. return result;
  2977. };
  2978. },
  2979. // Borrowed from Backbone.js's extend
  2980. // Helper function to correctly set up the prototype chain, for subclasses.
  2981. // Similar to `goog.inherits`, but uses a hash of prototype properties and
  2982. // class properties to be extended.
  2983. inherit: function(protoProps, staticProps) {
  2984. var parent = this;
  2985. var child;
  2986. // The constructor function for the new subclass is either defined by you
  2987. // (the "constructor" property in your `extend` definition), or defaulted
  2988. // by us to simply call the parent's constructor.
  2989. if (protoProps && protoProps.hasOwnProperty('constructor')) {
  2990. child = protoProps.constructor;
  2991. } else {
  2992. child = function() { return parent.apply(this, arguments); };
  2993. }
  2994. // Add static properties to the constructor function, if supplied.
  2995. ionic.extend(child, parent, staticProps);
  2996. // Set the prototype chain to inherit from `parent`, without calling
  2997. // `parent`'s constructor function.
  2998. var Surrogate = function() { this.constructor = child; };
  2999. Surrogate.prototype = parent.prototype;
  3000. child.prototype = new Surrogate();
  3001. // Add prototype properties (instance properties) to the subclass,
  3002. // if supplied.
  3003. if (protoProps) ionic.extend(child.prototype, protoProps);
  3004. // Set a convenience property in case the parent's prototype is needed
  3005. // later.
  3006. child.__super__ = parent.prototype;
  3007. return child;
  3008. },
  3009. // Extend adapted from Underscore.js
  3010. extend: function(obj) {
  3011. var args = Array.prototype.slice.call(arguments, 1);
  3012. for (var i = 0; i < args.length; i++) {
  3013. var source = args[i];
  3014. if (source) {
  3015. for (var prop in source) {
  3016. obj[prop] = source[prop];
  3017. }
  3018. }
  3019. }
  3020. return obj;
  3021. },
  3022. nextUid: function() {
  3023. return 'ion' + (nextId++);
  3024. },
  3025. disconnectScope: function disconnectScope(scope) {
  3026. if (!scope) return;
  3027. if (scope.$root === scope) {
  3028. return; // we can't disconnect the root node;
  3029. }
  3030. var parent = scope.$parent;
  3031. scope.$$disconnected = true;
  3032. scope.$broadcast('$ionic.disconnectScope', scope);
  3033. // See Scope.$destroy
  3034. if (parent.$$childHead === scope) {
  3035. parent.$$childHead = scope.$$nextSibling;
  3036. }
  3037. if (parent.$$childTail === scope) {
  3038. parent.$$childTail = scope.$$prevSibling;
  3039. }
  3040. if (scope.$$prevSibling) {
  3041. scope.$$prevSibling.$$nextSibling = scope.$$nextSibling;
  3042. }
  3043. if (scope.$$nextSibling) {
  3044. scope.$$nextSibling.$$prevSibling = scope.$$prevSibling;
  3045. }
  3046. scope.$$nextSibling = scope.$$prevSibling = null;
  3047. },
  3048. reconnectScope: function reconnectScope(scope) {
  3049. if (!scope) return;
  3050. if (scope.$root === scope) {
  3051. return; // we can't disconnect the root node;
  3052. }
  3053. if (!scope.$$disconnected) {
  3054. return;
  3055. }
  3056. var parent = scope.$parent;
  3057. scope.$$disconnected = false;
  3058. scope.$broadcast('$ionic.reconnectScope', scope);
  3059. // See Scope.$new for this logic...
  3060. scope.$$prevSibling = parent.$$childTail;
  3061. if (parent.$$childHead) {
  3062. parent.$$childTail.$$nextSibling = scope;
  3063. parent.$$childTail = scope;
  3064. } else {
  3065. parent.$$childHead = parent.$$childTail = scope;
  3066. }
  3067. },
  3068. isScopeDisconnected: function(scope) {
  3069. var climbScope = scope;
  3070. while (climbScope) {
  3071. if (climbScope.$$disconnected) return true;
  3072. climbScope = climbScope.$parent;
  3073. }
  3074. return false;
  3075. }
  3076. };
  3077. // Bind a few of the most useful functions to the ionic scope
  3078. ionic.inherit = ionic.Utils.inherit;
  3079. ionic.extend = ionic.Utils.extend;
  3080. ionic.throttle = ionic.Utils.throttle;
  3081. ionic.proxy = ionic.Utils.proxy;
  3082. ionic.debounce = ionic.Utils.debounce;
  3083. })(window.ionic);
  3084. /**
  3085. * @ngdoc page
  3086. * @name keyboard
  3087. * @module ionic
  3088. * @description
  3089. * On both Android and iOS, Ionic will attempt to prevent the keyboard from
  3090. * obscuring inputs and focusable elements when it appears by scrolling them
  3091. * into view. In order for this to work, any focusable elements must be within
  3092. * a [Scroll View](http://ionicframework.com/docs/api/directive/ionScroll/)
  3093. * or a directive such as [Content](http://ionicframework.com/docs/api/directive/ionContent/)
  3094. * that has a Scroll View.
  3095. *
  3096. * It will also attempt to prevent the native overflow scrolling on focus,
  3097. * which can cause layout issues such as pushing headers up and out of view.
  3098. *
  3099. * The keyboard fixes work best in conjunction with the
  3100. * [Ionic Keyboard Plugin](https://github.com/driftyco/ionic-plugins-keyboard),
  3101. * although it will perform reasonably well without. However, if you are using
  3102. * Cordova there is no reason not to use the plugin.
  3103. *
  3104. * ### Hide when keyboard shows
  3105. *
  3106. * To hide an element when the keyboard is open, add the class `hide-on-keyboard-open`.
  3107. *
  3108. * ```html
  3109. * <div class="hide-on-keyboard-open">
  3110. * <div id="google-map"></div>
  3111. * </div>
  3112. * ```
  3113. *
  3114. * Note: For performance reasons, elements will not be hidden for 400ms after the start of the `native.keyboardshow` event
  3115. * from the Ionic Keyboard plugin. If you would like them to disappear immediately, you could do something
  3116. * like:
  3117. *
  3118. * ```js
  3119. * window.addEventListener('native.keyboardshow', function(){
  3120. * document.body.classList.add('keyboard-open');
  3121. * });
  3122. * ```
  3123. * This adds the same `keyboard-open` class that is normally added by Ionic 400ms after the keyboard
  3124. * opens. However, bear in mind that adding this class to the body immediately may cause jank in any
  3125. * animations on Android that occur when the keyboard opens (for example, scrolling any obscured inputs into view).
  3126. *
  3127. * ----------
  3128. *
  3129. * ### Plugin Usage
  3130. * Information on using the plugin can be found at
  3131. * [https://github.com/driftyco/ionic-plugins-keyboard](https://github.com/driftyco/ionic-plugins-keyboard).
  3132. *
  3133. * ----------
  3134. *
  3135. * ### Android Notes
  3136. * - If your app is running in fullscreen, i.e. you have
  3137. * `<preference name="Fullscreen" value="true" />` in your `config.xml` file
  3138. * you will need to set `ionic.Platform.isFullScreen = true` manually.
  3139. *
  3140. * - You can configure the behavior of the web view when the keyboard shows by setting
  3141. * [android:windowSoftInputMode](http://developer.android.com/reference/android/R.attr.html#windowSoftInputMode)
  3142. * to either `adjustPan`, `adjustResize` or `adjustNothing` in your app's
  3143. * activity in `AndroidManifest.xml`. `adjustResize` is the recommended setting
  3144. * for Ionic, but if for some reason you do use `adjustPan` you will need to
  3145. * set `ionic.Platform.isFullScreen = true`.
  3146. *
  3147. * ```xml
  3148. * <activity android:windowSoftInputMode="adjustResize">
  3149. *
  3150. * ```
  3151. *
  3152. * ### iOS Notes
  3153. * - If the content of your app (including the header) is being pushed up and
  3154. * out of view on input focus, try setting `cordova.plugins.Keyboard.disableScroll(true)`.
  3155. * This does **not** disable scrolling in the Ionic scroll view, rather it
  3156. * disables the native overflow scrolling that happens automatically as a
  3157. * result of focusing on inputs below the keyboard.
  3158. *
  3159. */
  3160. /**
  3161. * The current viewport height.
  3162. */
  3163. var keyboardCurrentViewportHeight = 0;
  3164. /**
  3165. * The viewport height when in portrait orientation.
  3166. */
  3167. var keyboardPortraitViewportHeight = 0;
  3168. /**
  3169. * The viewport height when in landscape orientation.
  3170. */
  3171. var keyboardLandscapeViewportHeight = 0;
  3172. /**
  3173. * The currently focused input.
  3174. */
  3175. var keyboardActiveElement;
  3176. /**
  3177. * The previously focused input used to reset keyboard after focusing on a
  3178. * new non-keyboard element
  3179. */
  3180. var lastKeyboardActiveElement;
  3181. /**
  3182. * The scroll view containing the currently focused input.
  3183. */
  3184. var scrollView;
  3185. /**
  3186. * Timer for the setInterval that polls window.innerHeight to determine whether
  3187. * the layout has updated for the keyboard showing/hiding.
  3188. */
  3189. var waitForResizeTimer;
  3190. /**
  3191. * Sometimes when switching inputs or orientations, focusout will fire before
  3192. * focusin, so this timer is for the small setTimeout to determine if we should
  3193. * really focusout/hide the keyboard.
  3194. */
  3195. var keyboardFocusOutTimer;
  3196. /**
  3197. * on Android, orientationchange will fire before the keyboard plugin notifies
  3198. * the browser that the keyboard will show/is showing, so this flag indicates
  3199. * to nativeShow that there was an orientationChange and we should update
  3200. * the viewport height with an accurate keyboard height value
  3201. */
  3202. var wasOrientationChange = false;
  3203. /**
  3204. * CSS class added to the body indicating the keyboard is open.
  3205. */
  3206. var KEYBOARD_OPEN_CSS = 'keyboard-open';
  3207. /**
  3208. * CSS class that indicates a scroll container.
  3209. */
  3210. var SCROLL_CONTAINER_CSS = 'scroll-content';
  3211. /**
  3212. * Debounced keyboardFocusIn function
  3213. */
  3214. var debouncedKeyboardFocusIn = ionic.debounce(keyboardFocusIn, 200, true);
  3215. /**
  3216. * Debounced keyboardNativeShow function
  3217. */
  3218. var debouncedKeyboardNativeShow = ionic.debounce(keyboardNativeShow, 100, true);
  3219. /**
  3220. * Ionic keyboard namespace.
  3221. * @namespace keyboard
  3222. */
  3223. ionic.keyboard = {
  3224. /**
  3225. * Whether the keyboard is open or not.
  3226. */
  3227. isOpen: false,
  3228. /**
  3229. * Whether the keyboard is closing or not.
  3230. */
  3231. isClosing: false,
  3232. /**
  3233. * Whether the keyboard is opening or not.
  3234. */
  3235. isOpening: false,
  3236. /**
  3237. * The height of the keyboard in pixels, as reported by the keyboard plugin.
  3238. * If the plugin is not available, calculated as the difference in
  3239. * window.innerHeight after the keyboard has shown.
  3240. */
  3241. height: 0,
  3242. /**
  3243. * Whether the device is in landscape orientation or not.
  3244. */
  3245. isLandscape: false,
  3246. /**
  3247. * Whether the keyboard event listeners have been added or not
  3248. */
  3249. isInitialized: false,
  3250. /**
  3251. * Hide the keyboard, if it is open.
  3252. */
  3253. hide: function() {
  3254. if (keyboardHasPlugin()) {
  3255. cordova.plugins.Keyboard.close();
  3256. }
  3257. keyboardActiveElement && keyboardActiveElement.blur();
  3258. },
  3259. /**
  3260. * An alias for cordova.plugins.Keyboard.show(). If the keyboard plugin
  3261. * is installed, show the keyboard.
  3262. */
  3263. show: function() {
  3264. if (keyboardHasPlugin()) {
  3265. cordova.plugins.Keyboard.show();
  3266. }
  3267. },
  3268. /**
  3269. * Remove all keyboard related event listeners, effectively disabling Ionic's
  3270. * keyboard adjustments.
  3271. */
  3272. disable: function() {
  3273. if (keyboardHasPlugin()) {
  3274. window.removeEventListener('native.keyboardshow', debouncedKeyboardNativeShow );
  3275. window.removeEventListener('native.keyboardhide', keyboardFocusOut);
  3276. } else {
  3277. document.body.removeEventListener('focusout', keyboardFocusOut);
  3278. }
  3279. document.body.removeEventListener('ionic.focusin', debouncedKeyboardFocusIn);
  3280. document.body.removeEventListener('focusin', debouncedKeyboardFocusIn);
  3281. window.removeEventListener('orientationchange', keyboardOrientationChange);
  3282. if ( window.navigator.msPointerEnabled ) {
  3283. document.removeEventListener("MSPointerDown", keyboardInit);
  3284. } else {
  3285. document.removeEventListener('touchstart', keyboardInit);
  3286. }
  3287. ionic.keyboard.isInitialized = false;
  3288. },
  3289. /**
  3290. * Alias for keyboardInit, initialize all keyboard related event listeners.
  3291. */
  3292. enable: function() {
  3293. keyboardInit();
  3294. }
  3295. };
  3296. // Initialize the viewport height (after ionic.keyboard.height has been
  3297. // defined).
  3298. keyboardCurrentViewportHeight = getViewportHeight();
  3299. /* Event handlers */
  3300. /* ------------------------------------------------------------------------- */
  3301. /**
  3302. * Event handler for first touch event, initializes all event listeners
  3303. * for keyboard related events. Also aliased by ionic.keyboard.enable.
  3304. */
  3305. function keyboardInit() {
  3306. if (ionic.keyboard.isInitialized) return;
  3307. if (keyboardHasPlugin()) {
  3308. window.addEventListener('native.keyboardshow', debouncedKeyboardNativeShow);
  3309. window.addEventListener('native.keyboardhide', keyboardFocusOut);
  3310. } else {
  3311. document.body.addEventListener('focusout', keyboardFocusOut);
  3312. }
  3313. document.body.addEventListener('ionic.focusin', debouncedKeyboardFocusIn);
  3314. document.body.addEventListener('focusin', debouncedKeyboardFocusIn);
  3315. if (window.navigator.msPointerEnabled) {
  3316. document.removeEventListener("MSPointerDown", keyboardInit);
  3317. } else {
  3318. document.removeEventListener('touchstart', keyboardInit);
  3319. }
  3320. ionic.keyboard.isInitialized = true;
  3321. }
  3322. /**
  3323. * Event handler for 'native.keyboardshow' event, sets keyboard.height to the
  3324. * reported height and keyboard.isOpening to true. Then calls
  3325. * keyboardWaitForResize with keyboardShow or keyboardUpdateViewportHeight as
  3326. * the callback depending on whether the event was triggered by a focusin or
  3327. * an orientationchange.
  3328. */
  3329. function keyboardNativeShow(e) {
  3330. clearTimeout(keyboardFocusOutTimer);
  3331. //console.log("keyboardNativeShow fired at: " + Date.now());
  3332. //console.log("keyboardNativeshow window.innerHeight: " + window.innerHeight);
  3333. if (!ionic.keyboard.isOpen || ionic.keyboard.isClosing) {
  3334. ionic.keyboard.isOpening = true;
  3335. ionic.keyboard.isClosing = false;
  3336. }
  3337. ionic.keyboard.height = e.keyboardHeight;
  3338. //console.log('nativeshow keyboard height:' + e.keyboardHeight);
  3339. if (wasOrientationChange) {
  3340. keyboardWaitForResize(keyboardUpdateViewportHeight, true);
  3341. } else {
  3342. keyboardWaitForResize(keyboardShow, true);
  3343. }
  3344. }
  3345. /**
  3346. * Event handler for 'focusin' and 'ionic.focusin' events. Initializes
  3347. * keyboard state (keyboardActiveElement and keyboard.isOpening) for the
  3348. * appropriate adjustments once the window has resized. If not using the
  3349. * keyboard plugin, calls keyboardWaitForResize with keyboardShow as the
  3350. * callback or keyboardShow right away if the keyboard is already open. If
  3351. * using the keyboard plugin does nothing and lets keyboardNativeShow handle
  3352. * adjustments with a more accurate keyboard height.
  3353. */
  3354. function keyboardFocusIn(e) {
  3355. clearTimeout(keyboardFocusOutTimer);
  3356. //console.log("keyboardFocusIn from: " + e.type + " at: " + Date.now());
  3357. if (!e.target ||
  3358. e.target.readOnly ||
  3359. !ionic.tap.isKeyboardElement(e.target) ||
  3360. !(scrollView = ionic.DomUtil.getParentWithClass(e.target, SCROLL_CONTAINER_CSS))) {
  3361. if (keyboardActiveElement) {
  3362. lastKeyboardActiveElement = keyboardActiveElement;
  3363. }
  3364. keyboardActiveElement = null;
  3365. return;
  3366. }
  3367. keyboardActiveElement = e.target;
  3368. // if using JS scrolling, undo the effects of native overflow scroll so the
  3369. // scroll view is positioned correctly
  3370. if (!scrollView.classList.contains("overflow-scroll")) {
  3371. document.body.scrollTop = 0;
  3372. scrollView.scrollTop = 0;
  3373. ionic.requestAnimationFrame(function(){
  3374. document.body.scrollTop = 0;
  3375. scrollView.scrollTop = 0;
  3376. });
  3377. // any showing part of the document that isn't within the scroll the user
  3378. // could touchmove and cause some ugly changes to the app, so disable
  3379. // any touchmove events while the keyboard is open using e.preventDefault()
  3380. if (window.navigator.msPointerEnabled) {
  3381. document.addEventListener("MSPointerMove", keyboardPreventDefault, false);
  3382. } else {
  3383. document.addEventListener('touchmove', keyboardPreventDefault, false);
  3384. }
  3385. }
  3386. if (!ionic.keyboard.isOpen || ionic.keyboard.isClosing) {
  3387. ionic.keyboard.isOpening = true;
  3388. ionic.keyboard.isClosing = false;
  3389. }
  3390. // attempt to prevent browser from natively scrolling input into view while
  3391. // we are trying to do the same (while we are scrolling) if the user taps the
  3392. // keyboard
  3393. document.addEventListener('keydown', keyboardOnKeyDown, false);
  3394. // if we aren't using the plugin and the keyboard isn't open yet, wait for the
  3395. // window to resize so we can get an accurate estimate of the keyboard size,
  3396. // otherwise we do nothing and let nativeShow call keyboardShow once we have
  3397. // an exact keyboard height
  3398. // if the keyboard is already open, go ahead and scroll the input into view
  3399. // if necessary
  3400. if (!ionic.keyboard.isOpen && !keyboardHasPlugin()) {
  3401. keyboardWaitForResize(keyboardShow, true);
  3402. } else if (ionic.keyboard.isOpen) {
  3403. keyboardShow();
  3404. }
  3405. }
  3406. /**
  3407. * Event handler for 'focusout' events. Sets keyboard.isClosing to true and
  3408. * calls keyboardWaitForResize with keyboardHide as the callback after a small
  3409. * timeout.
  3410. */
  3411. function keyboardFocusOut() {
  3412. clearTimeout(keyboardFocusOutTimer);
  3413. //console.log("keyboardFocusOut fired at: " + Date.now());
  3414. //console.log("keyboardFocusOut event type: " + e.type);
  3415. if (ionic.keyboard.isOpen || ionic.keyboard.isOpening) {
  3416. ionic.keyboard.isClosing = true;
  3417. ionic.keyboard.isOpening = false;
  3418. }
  3419. // Call keyboardHide with a slight delay because sometimes on focus or
  3420. // orientation change focusin is called immediately after, so we give it time
  3421. // to cancel keyboardHide
  3422. keyboardFocusOutTimer = setTimeout(function() {
  3423. ionic.requestAnimationFrame(function() {
  3424. // focusOut during or right after an orientationchange, so we didn't get
  3425. // a chance to update the viewport height yet, do it and keyboardHide
  3426. //console.log("focusOut, wasOrientationChange: " + wasOrientationChange);
  3427. if (wasOrientationChange) {
  3428. keyboardWaitForResize(function(){
  3429. keyboardUpdateViewportHeight();
  3430. keyboardHide();
  3431. }, false);
  3432. } else {
  3433. keyboardWaitForResize(keyboardHide, false);
  3434. }
  3435. });
  3436. }, 50);
  3437. }
  3438. /**
  3439. * Event handler for 'orientationchange' events. If using the keyboard plugin
  3440. * and the keyboard is open on Android, sets wasOrientationChange to true so
  3441. * nativeShow can update the viewport height with an accurate keyboard height.
  3442. * If the keyboard isn't open or keyboard plugin isn't being used,
  3443. * waits for the window to resize before updating the viewport height.
  3444. *
  3445. * On iOS, where orientationchange fires after the keyboard has already shown,
  3446. * updates the viewport immediately, regardless of if the keyboard is already
  3447. * open.
  3448. */
  3449. function keyboardOrientationChange() {
  3450. //console.log("orientationchange fired at: " + Date.now());
  3451. //console.log("orientation was: " + (ionic.keyboard.isLandscape ? "landscape" : "portrait"));
  3452. // toggle orientation
  3453. ionic.keyboard.isLandscape = !ionic.keyboard.isLandscape;
  3454. // //console.log("now orientation is: " + (ionic.keyboard.isLandscape ? "landscape" : "portrait"));
  3455. // no need to wait for resizing on iOS, and orientationchange always fires
  3456. // after the keyboard has opened, so it doesn't matter if it's open or not
  3457. if (ionic.Platform.isIOS()) {
  3458. keyboardUpdateViewportHeight();
  3459. }
  3460. // On Android, if the keyboard isn't open or we aren't using the keyboard
  3461. // plugin, update the viewport height once everything has resized. If the
  3462. // keyboard is open and we are using the keyboard plugin do nothing and let
  3463. // nativeShow handle it using an accurate keyboard height.
  3464. if ( ionic.Platform.isAndroid()) {
  3465. if (!ionic.keyboard.isOpen || !keyboardHasPlugin()) {
  3466. keyboardWaitForResize(keyboardUpdateViewportHeight, false);
  3467. } else {
  3468. wasOrientationChange = true;
  3469. }
  3470. }
  3471. }
  3472. /**
  3473. * Event handler for 'keydown' event. Tries to prevent browser from natively
  3474. * scrolling an input into view when a user taps the keyboard while we are
  3475. * scrolling the input into view ourselves with JS.
  3476. */
  3477. function keyboardOnKeyDown(e) {
  3478. if (ionic.scroll.isScrolling) {
  3479. keyboardPreventDefault(e);
  3480. }
  3481. }
  3482. /**
  3483. * Event for 'touchmove' or 'MSPointerMove'. Prevents native scrolling on
  3484. * elements outside the scroll view while the keyboard is open.
  3485. */
  3486. function keyboardPreventDefault(e) {
  3487. if (e.target.tagName !== 'TEXTAREA') {
  3488. e.preventDefault();
  3489. }
  3490. }
  3491. /* Private API */
  3492. /* -------------------------------------------------------------------------- */
  3493. /**
  3494. * Polls window.innerHeight until it has updated to an expected value (or
  3495. * sufficient time has passed) before calling the specified callback function.
  3496. * Only necessary for non-fullscreen Android which sometimes reports multiple
  3497. * window.innerHeight values during interim layouts while it is resizing.
  3498. *
  3499. * On iOS, the window.innerHeight will already be updated, but we use the 50ms
  3500. * delay as essentially a timeout so that scroll view adjustments happen after
  3501. * the keyboard has shown so there isn't a white flash from us resizing too
  3502. * quickly.
  3503. *
  3504. * @param {Function} callback the function to call once the window has resized
  3505. * @param {boolean} isOpening whether the resize is from the keyboard opening
  3506. * or not
  3507. */
  3508. function keyboardWaitForResize(callback, isOpening) {
  3509. clearInterval(waitForResizeTimer);
  3510. var count = 0;
  3511. var maxCount;
  3512. var initialHeight = getViewportHeight();
  3513. var viewportHeight = initialHeight;
  3514. //console.log("waitForResize initial viewport height: " + viewportHeight);
  3515. //var start = Date.now();
  3516. //console.log("start: " + start);
  3517. // want to fail relatively quickly on modern android devices, since it's much
  3518. // more likely we just have a bad keyboard height
  3519. if (ionic.Platform.isAndroid() && ionic.Platform.version() < 4.4) {
  3520. maxCount = 30;
  3521. } else if (ionic.Platform.isAndroid()) {
  3522. maxCount = 10;
  3523. } else {
  3524. maxCount = 1;
  3525. }
  3526. // poll timer
  3527. waitForResizeTimer = setInterval(function(){
  3528. viewportHeight = getViewportHeight();
  3529. // height hasn't updated yet, try again in 50ms
  3530. // if not using plugin, wait for maxCount to ensure we have waited long enough
  3531. // to get an accurate keyboard height
  3532. if (++count < maxCount &&
  3533. ((!isPortraitViewportHeight(viewportHeight) &&
  3534. !isLandscapeViewportHeight(viewportHeight)) ||
  3535. !ionic.keyboard.height)) {
  3536. return;
  3537. }
  3538. // infer the keyboard height from the resize if not using the keyboard plugin
  3539. if (!keyboardHasPlugin()) {
  3540. ionic.keyboard.height = Math.abs(initialHeight - window.innerHeight);
  3541. }
  3542. // set to true if we were waiting for the keyboard to open
  3543. ionic.keyboard.isOpen = isOpening;
  3544. clearInterval(waitForResizeTimer);
  3545. //var end = Date.now();
  3546. //console.log("waitForResize count: " + count);
  3547. //console.log("end: " + end);
  3548. //console.log("difference: " + ( end - start ) + "ms");
  3549. //console.log("callback: " + callback.name);
  3550. callback();
  3551. }, 50);
  3552. return maxCount; //for tests
  3553. }
  3554. /**
  3555. * On keyboard close sets keyboard state to closed, resets the scroll view,
  3556. * removes CSS from body indicating keyboard was open, removes any event
  3557. * listeners for when the keyboard is open and on Android blurs the active
  3558. * element (which in some cases will still have focus even if the keyboard
  3559. * is closed and can cause it to reappear on subsequent taps).
  3560. */
  3561. function keyboardHide() {
  3562. clearTimeout(keyboardFocusOutTimer);
  3563. //console.log("keyboardHide");
  3564. ionic.keyboard.isOpen = false;
  3565. ionic.keyboard.isClosing = false;
  3566. if (keyboardActiveElement || lastKeyboardActiveElement) {
  3567. ionic.trigger('resetScrollView', {
  3568. target: keyboardActiveElement || lastKeyboardActiveElement
  3569. }, true);
  3570. }
  3571. ionic.requestAnimationFrame(function(){
  3572. document.body.classList.remove(KEYBOARD_OPEN_CSS);
  3573. });
  3574. // the keyboard is gone now, remove the touchmove that disables native scroll
  3575. if (window.navigator.msPointerEnabled) {
  3576. document.removeEventListener("MSPointerMove", keyboardPreventDefault);
  3577. } else {
  3578. document.removeEventListener('touchmove', keyboardPreventDefault);
  3579. }
  3580. document.removeEventListener('keydown', keyboardOnKeyDown);
  3581. if (ionic.Platform.isAndroid()) {
  3582. // on android closing the keyboard with the back/dismiss button won't remove
  3583. // focus and keyboard can re-appear on subsequent taps (like scrolling)
  3584. if (keyboardHasPlugin()) cordova.plugins.Keyboard.close();
  3585. keyboardActiveElement && keyboardActiveElement.blur();
  3586. }
  3587. keyboardActiveElement = null;
  3588. lastKeyboardActiveElement = null;
  3589. }
  3590. /**
  3591. * On keyboard open sets keyboard state to open, adds CSS to the body
  3592. * indicating the keyboard is open and tells the scroll view to resize and
  3593. * the currently focused input into view if necessary.
  3594. */
  3595. function keyboardShow() {
  3596. ionic.keyboard.isOpen = true;
  3597. ionic.keyboard.isOpening = false;
  3598. var details = {
  3599. keyboardHeight: keyboardGetHeight(),
  3600. viewportHeight: keyboardCurrentViewportHeight
  3601. };
  3602. if (keyboardActiveElement) {
  3603. details.target = keyboardActiveElement;
  3604. var elementBounds = keyboardActiveElement.getBoundingClientRect();
  3605. details.elementTop = Math.round(elementBounds.top);
  3606. details.elementBottom = Math.round(elementBounds.bottom);
  3607. details.windowHeight = details.viewportHeight - details.keyboardHeight;
  3608. //console.log("keyboardShow viewportHeight: " + details.viewportHeight +
  3609. //", windowHeight: " + details.windowHeight +
  3610. //", keyboardHeight: " + details.keyboardHeight);
  3611. // figure out if the element is under the keyboard
  3612. details.isElementUnderKeyboard = (details.elementBottom > details.windowHeight);
  3613. //console.log("isUnderKeyboard: " + details.isElementUnderKeyboard);
  3614. //console.log("elementBottom: " + details.elementBottom);
  3615. // send event so the scroll view adjusts
  3616. ionic.trigger('scrollChildIntoView', details, true);
  3617. }
  3618. setTimeout(function(){
  3619. document.body.classList.add(KEYBOARD_OPEN_CSS);
  3620. }, 400);
  3621. return details; //for testing
  3622. }
  3623. /* eslint no-unused-vars:0 */
  3624. function keyboardGetHeight() {
  3625. // check if we already have a keyboard height from the plugin or resize calculations
  3626. if (ionic.keyboard.height) {
  3627. return ionic.keyboard.height;
  3628. }
  3629. if (ionic.Platform.isAndroid()) {
  3630. // should be using the plugin, no way to know how big the keyboard is, so guess
  3631. if ( ionic.Platform.isFullScreen ) {
  3632. return 275;
  3633. }
  3634. // otherwise just calculate it
  3635. var contentHeight = window.innerHeight;
  3636. if (contentHeight < keyboardCurrentViewportHeight) {
  3637. return keyboardCurrentViewportHeight - contentHeight;
  3638. } else {
  3639. return 0;
  3640. }
  3641. }
  3642. // fallback for when it's the webview without the plugin
  3643. // or for just the standard web browser
  3644. // TODO: have these be based on device
  3645. if (ionic.Platform.isIOS()) {
  3646. if (ionic.keyboard.isLandscape) {
  3647. return 206;
  3648. }
  3649. if (!ionic.Platform.isWebView()) {
  3650. return 216;
  3651. }
  3652. return 260;
  3653. }
  3654. // safe guess
  3655. return 275;
  3656. }
  3657. function isPortraitViewportHeight(viewportHeight) {
  3658. return !!(!ionic.keyboard.isLandscape &&
  3659. keyboardPortraitViewportHeight &&
  3660. (Math.abs(keyboardPortraitViewportHeight - viewportHeight) < 2));
  3661. }
  3662. function isLandscapeViewportHeight(viewportHeight) {
  3663. return !!(ionic.keyboard.isLandscape &&
  3664. keyboardLandscapeViewportHeight &&
  3665. (Math.abs(keyboardLandscapeViewportHeight - viewportHeight) < 2));
  3666. }
  3667. function keyboardUpdateViewportHeight() {
  3668. wasOrientationChange = false;
  3669. keyboardCurrentViewportHeight = getViewportHeight();
  3670. if (ionic.keyboard.isLandscape && !keyboardLandscapeViewportHeight) {
  3671. //console.log("saved landscape: " + keyboardCurrentViewportHeight);
  3672. keyboardLandscapeViewportHeight = keyboardCurrentViewportHeight;
  3673. } else if (!ionic.keyboard.isLandscape && !keyboardPortraitViewportHeight) {
  3674. //console.log("saved portrait: " + keyboardCurrentViewportHeight);
  3675. keyboardPortraitViewportHeight = keyboardCurrentViewportHeight;
  3676. }
  3677. if (keyboardActiveElement) {
  3678. ionic.trigger('resetScrollView', {
  3679. target: keyboardActiveElement
  3680. }, true);
  3681. }
  3682. if (ionic.keyboard.isOpen && ionic.tap.isTextInput(keyboardActiveElement)) {
  3683. keyboardShow();
  3684. }
  3685. }
  3686. function keyboardInitViewportHeight() {
  3687. var viewportHeight = getViewportHeight();
  3688. //console.log("Keyboard init VP: " + viewportHeight + " " + window.innerWidth);
  3689. // can't just use window.innerHeight in case the keyboard is opened immediately
  3690. if ((viewportHeight / window.innerWidth) < 1) {
  3691. ionic.keyboard.isLandscape = true;
  3692. }
  3693. //console.log("ionic.keyboard.isLandscape is: " + ionic.keyboard.isLandscape);
  3694. // initialize or update the current viewport height values
  3695. keyboardCurrentViewportHeight = viewportHeight;
  3696. if (ionic.keyboard.isLandscape && !keyboardLandscapeViewportHeight) {
  3697. keyboardLandscapeViewportHeight = keyboardCurrentViewportHeight;
  3698. } else if (!ionic.keyboard.isLandscape && !keyboardPortraitViewportHeight) {
  3699. keyboardPortraitViewportHeight = keyboardCurrentViewportHeight;
  3700. }
  3701. }
  3702. function getViewportHeight() {
  3703. var windowHeight = window.innerHeight;
  3704. //console.log('window.innerHeight is: ' + windowHeight);
  3705. //console.log('kb height is: ' + ionic.keyboard.height);
  3706. //console.log('kb isOpen: ' + ionic.keyboard.isOpen);
  3707. //TODO: add iPad undocked/split kb once kb plugin supports it
  3708. // the keyboard overlays the window on Android fullscreen
  3709. if (!(ionic.Platform.isAndroid() && ionic.Platform.isFullScreen) &&
  3710. (ionic.keyboard.isOpen || ionic.keyboard.isOpening) &&
  3711. !ionic.keyboard.isClosing) {
  3712. return windowHeight + keyboardGetHeight();
  3713. }
  3714. return windowHeight;
  3715. }
  3716. function keyboardHasPlugin() {
  3717. return !!(window.cordova && cordova.plugins && cordova.plugins.Keyboard);
  3718. }
  3719. ionic.Platform.ready(function() {
  3720. keyboardInitViewportHeight();
  3721. window.addEventListener('orientationchange', keyboardOrientationChange);
  3722. // if orientation changes while app is in background, update on resuming
  3723. /*
  3724. if ( ionic.Platform.isWebView() ) {
  3725. document.addEventListener('resume', keyboardInitViewportHeight);
  3726. if (ionic.Platform.isAndroid()) {
  3727. //TODO: onbackpressed to detect keyboard close without focusout or plugin
  3728. }
  3729. }
  3730. */
  3731. // if orientation changes while app is in background, update on resuming
  3732. /* if ( ionic.Platform.isWebView() ) {
  3733. document.addEventListener('pause', function() {
  3734. window.removeEventListener('orientationchange', keyboardOrientationChange);
  3735. })
  3736. document.addEventListener('resume', function() {
  3737. keyboardInitViewportHeight();
  3738. window.addEventListener('orientationchange', keyboardOrientationChange)
  3739. });
  3740. }*/
  3741. // Android sometimes reports bad innerHeight on window.load
  3742. // try it again in a lil bit to play it safe
  3743. setTimeout(keyboardInitViewportHeight, 999);
  3744. // only initialize the adjustments for the virtual keyboard
  3745. // if a touchstart event happens
  3746. if (window.navigator.msPointerEnabled) {
  3747. document.addEventListener("MSPointerDown", keyboardInit, false);
  3748. } else {
  3749. document.addEventListener('touchstart', keyboardInit, false);
  3750. }
  3751. });
  3752. var viewportTag;
  3753. var viewportProperties = {};
  3754. ionic.viewport = {
  3755. orientation: function() {
  3756. // 0 = Portrait
  3757. // 90 = Landscape
  3758. // not using window.orientation because each device has a different implementation
  3759. return (window.innerWidth > window.innerHeight ? 90 : 0);
  3760. }
  3761. };
  3762. function viewportLoadTag() {
  3763. var x;
  3764. for (x = 0; x < document.head.children.length; x++) {
  3765. if (document.head.children[x].name == 'viewport') {
  3766. viewportTag = document.head.children[x];
  3767. break;
  3768. }
  3769. }
  3770. if (viewportTag) {
  3771. var props = viewportTag.content.toLowerCase().replace(/\s+/g, '').split(',');
  3772. var keyValue;
  3773. for (x = 0; x < props.length; x++) {
  3774. if (props[x]) {
  3775. keyValue = props[x].split('=');
  3776. viewportProperties[ keyValue[0] ] = (keyValue.length > 1 ? keyValue[1] : '_');
  3777. }
  3778. }
  3779. viewportUpdate();
  3780. }
  3781. }
  3782. function viewportUpdate() {
  3783. // unit tests in viewport.unit.js
  3784. var initWidth = viewportProperties.width;
  3785. var initHeight = viewportProperties.height;
  3786. var p = ionic.Platform;
  3787. var version = p.version();
  3788. var DEVICE_WIDTH = 'device-width';
  3789. var DEVICE_HEIGHT = 'device-height';
  3790. var orientation = ionic.viewport.orientation();
  3791. // Most times we're removing the height and adding the width
  3792. // So this is the default to start with, then modify per platform/version/oreintation
  3793. delete viewportProperties.height;
  3794. viewportProperties.width = DEVICE_WIDTH;
  3795. if (p.isIPad()) {
  3796. // iPad
  3797. if (version > 7) {
  3798. // iPad >= 7.1
  3799. // https://issues.apache.org/jira/browse/CB-4323
  3800. delete viewportProperties.width;
  3801. } else {
  3802. // iPad <= 7.0
  3803. if (p.isWebView()) {
  3804. // iPad <= 7.0 WebView
  3805. if (orientation == 90) {
  3806. // iPad <= 7.0 WebView Landscape
  3807. viewportProperties.height = '0';
  3808. } else if (version == 7) {
  3809. // iPad <= 7.0 WebView Portait
  3810. viewportProperties.height = DEVICE_HEIGHT;
  3811. }
  3812. } else {
  3813. // iPad <= 6.1 Browser
  3814. if (version < 7) {
  3815. viewportProperties.height = '0';
  3816. }
  3817. }
  3818. }
  3819. } else if (p.isIOS()) {
  3820. // iPhone
  3821. if (p.isWebView()) {
  3822. // iPhone WebView
  3823. if (version > 7) {
  3824. // iPhone >= 7.1 WebView
  3825. delete viewportProperties.width;
  3826. } else if (version < 7) {
  3827. // iPhone <= 6.1 WebView
  3828. // if height was set it needs to get removed with this hack for <= 6.1
  3829. if (initHeight) viewportProperties.height = '0';
  3830. } else if (version == 7) {
  3831. //iPhone == 7.0 WebView
  3832. viewportProperties.height = DEVICE_HEIGHT;
  3833. }
  3834. } else {
  3835. // iPhone Browser
  3836. if (version < 7) {
  3837. // iPhone <= 6.1 Browser
  3838. // if height was set it needs to get removed with this hack for <= 6.1
  3839. if (initHeight) viewportProperties.height = '0';
  3840. }
  3841. }
  3842. }
  3843. // only update the viewport tag if there was a change
  3844. if (initWidth !== viewportProperties.width || initHeight !== viewportProperties.height) {
  3845. viewportTagUpdate();
  3846. }
  3847. }
  3848. function viewportTagUpdate() {
  3849. var key, props = [];
  3850. for (key in viewportProperties) {
  3851. if (viewportProperties[key]) {
  3852. props.push(key + (viewportProperties[key] == '_' ? '' : '=' + viewportProperties[key]));
  3853. }
  3854. }
  3855. viewportTag.content = props.join(', ');
  3856. }
  3857. ionic.Platform.ready(function() {
  3858. viewportLoadTag();
  3859. window.addEventListener("orientationchange", function() {
  3860. setTimeout(viewportUpdate, 1000);
  3861. }, false);
  3862. });
  3863. (function(ionic) {
  3864. 'use strict';
  3865. ionic.views.View = function() {
  3866. this.initialize.apply(this, arguments);
  3867. };
  3868. ionic.views.View.inherit = ionic.inherit;
  3869. ionic.extend(ionic.views.View.prototype, {
  3870. initialize: function() {}
  3871. });
  3872. })(window.ionic);
  3873. /*
  3874. * Scroller
  3875. * http://github.com/zynga/scroller
  3876. *
  3877. * Copyright 2011, Zynga Inc.
  3878. * Licensed under the MIT License.
  3879. * https://raw.github.com/zynga/scroller/master/MIT-LICENSE.txt
  3880. *
  3881. * Based on the work of: Unify Project (unify-project.org)
  3882. * http://unify-project.org
  3883. * Copyright 2011, Deutsche Telekom AG
  3884. * License: MIT + Apache (V2)
  3885. */
  3886. /* jshint eqnull: true */
  3887. /**
  3888. * Generic animation class with support for dropped frames both optional easing and duration.
  3889. *
  3890. * Optional duration is useful when the lifetime is defined by another condition than time
  3891. * e.g. speed of an animating object, etc.
  3892. *
  3893. * Dropped frame logic allows to keep using the same updater logic independent from the actual
  3894. * rendering. This eases a lot of cases where it might be pretty complex to break down a state
  3895. * based on the pure time difference.
  3896. */
  3897. var zyngaCore = { effect: {} };
  3898. (function(global) {
  3899. var time = Date.now || function() {
  3900. return +new Date();
  3901. };
  3902. var desiredFrames = 60;
  3903. var millisecondsPerSecond = 1000;
  3904. var running = {};
  3905. var counter = 1;
  3906. zyngaCore.effect.Animate = {
  3907. /**
  3908. * A requestAnimationFrame wrapper / polyfill.
  3909. *
  3910. * @param callback {Function} The callback to be invoked before the next repaint.
  3911. * @param root {HTMLElement} The root element for the repaint
  3912. */
  3913. requestAnimationFrame: (function() {
  3914. // Check for request animation Frame support
  3915. var requestFrame = global.requestAnimationFrame || global.webkitRequestAnimationFrame || global.mozRequestAnimationFrame || global.oRequestAnimationFrame;
  3916. var isNative = !!requestFrame;
  3917. if (requestFrame && !/requestAnimationFrame\(\)\s*\{\s*\[native code\]\s*\}/i.test(requestFrame.toString())) {
  3918. isNative = false;
  3919. }
  3920. if (isNative) {
  3921. return function(callback, root) {
  3922. requestFrame(callback, root);
  3923. };
  3924. }
  3925. var TARGET_FPS = 60;
  3926. var requests = {};
  3927. var requestCount = 0;
  3928. var rafHandle = 1;
  3929. var intervalHandle = null;
  3930. var lastActive = +new Date();
  3931. return function(callback) {
  3932. var callbackHandle = rafHandle++;
  3933. // Store callback
  3934. requests[callbackHandle] = callback;
  3935. requestCount++;
  3936. // Create timeout at first request
  3937. if (intervalHandle === null) {
  3938. intervalHandle = setInterval(function() {
  3939. var time = +new Date();
  3940. var currentRequests = requests;
  3941. // Reset data structure before executing callbacks
  3942. requests = {};
  3943. requestCount = 0;
  3944. for(var key in currentRequests) {
  3945. if (currentRequests.hasOwnProperty(key)) {
  3946. currentRequests[key](time);
  3947. lastActive = time;
  3948. }
  3949. }
  3950. // Disable the timeout when nothing happens for a certain
  3951. // period of time
  3952. if (time - lastActive > 2500) {
  3953. clearInterval(intervalHandle);
  3954. intervalHandle = null;
  3955. }
  3956. }, 1000 / TARGET_FPS);
  3957. }
  3958. return callbackHandle;
  3959. };
  3960. })(),
  3961. /**
  3962. * Stops the given animation.
  3963. *
  3964. * @param id {Integer} Unique animation ID
  3965. * @return {Boolean} Whether the animation was stopped (aka, was running before)
  3966. */
  3967. stop: function(id) {
  3968. var cleared = running[id] != null;
  3969. if (cleared) {
  3970. running[id] = null;
  3971. }
  3972. return cleared;
  3973. },
  3974. /**
  3975. * Whether the given animation is still running.
  3976. *
  3977. * @param id {Integer} Unique animation ID
  3978. * @return {Boolean} Whether the animation is still running
  3979. */
  3980. isRunning: function(id) {
  3981. return running[id] != null;
  3982. },
  3983. /**
  3984. * Start the animation.
  3985. *
  3986. * @param stepCallback {Function} Pointer to function which is executed on every step.
  3987. * Signature of the method should be `function(percent, now, virtual) { return continueWithAnimation; }`
  3988. * @param verifyCallback {Function} Executed before every animation step.
  3989. * Signature of the method should be `function() { return continueWithAnimation; }`
  3990. * @param completedCallback {Function}
  3991. * Signature of the method should be `function(droppedFrames, finishedAnimation) {}`
  3992. * @param duration {Integer} Milliseconds to run the animation
  3993. * @param easingMethod {Function} Pointer to easing function
  3994. * Signature of the method should be `function(percent) { return modifiedValue; }`
  3995. * @param root {Element} Render root, when available. Used for internal
  3996. * usage of requestAnimationFrame.
  3997. * @return {Integer} Identifier of animation. Can be used to stop it any time.
  3998. */
  3999. start: function(stepCallback, verifyCallback, completedCallback, duration, easingMethod, root) {
  4000. var start = time();
  4001. var lastFrame = start;
  4002. var percent = 0;
  4003. var dropCounter = 0;
  4004. var id = counter++;
  4005. if (!root) {
  4006. root = document.body;
  4007. }
  4008. // Compacting running db automatically every few new animations
  4009. if (id % 20 === 0) {
  4010. var newRunning = {};
  4011. for (var usedId in running) {
  4012. newRunning[usedId] = true;
  4013. }
  4014. running = newRunning;
  4015. }
  4016. // This is the internal step method which is called every few milliseconds
  4017. var step = function(virtual) {
  4018. // Normalize virtual value
  4019. var render = virtual !== true;
  4020. // Get current time
  4021. var now = time();
  4022. // Verification is executed before next animation step
  4023. if (!running[id] || (verifyCallback && !verifyCallback(id))) {
  4024. running[id] = null;
  4025. completedCallback && completedCallback(desiredFrames - (dropCounter / ((now - start) / millisecondsPerSecond)), id, false);
  4026. return;
  4027. }
  4028. // For the current rendering to apply let's update omitted steps in memory.
  4029. // This is important to bring internal state variables up-to-date with progress in time.
  4030. if (render) {
  4031. var droppedFrames = Math.round((now - lastFrame) / (millisecondsPerSecond / desiredFrames)) - 1;
  4032. for (var j = 0; j < Math.min(droppedFrames, 4); j++) {
  4033. step(true);
  4034. dropCounter++;
  4035. }
  4036. }
  4037. // Compute percent value
  4038. if (duration) {
  4039. percent = (now - start) / duration;
  4040. if (percent > 1) {
  4041. percent = 1;
  4042. }
  4043. }
  4044. // Execute step callback, then...
  4045. var value = easingMethod ? easingMethod(percent) : percent;
  4046. if ((stepCallback(value, now, render) === false || percent === 1) && render) {
  4047. running[id] = null;
  4048. completedCallback && completedCallback(desiredFrames - (dropCounter / ((now - start) / millisecondsPerSecond)), id, percent === 1 || duration == null);
  4049. } else if (render) {
  4050. lastFrame = now;
  4051. zyngaCore.effect.Animate.requestAnimationFrame(step, root);
  4052. }
  4053. };
  4054. // Mark as running
  4055. running[id] = true;
  4056. // Init first step
  4057. zyngaCore.effect.Animate.requestAnimationFrame(step, root);
  4058. // Return unique animation ID
  4059. return id;
  4060. }
  4061. };
  4062. })(window);
  4063. /*
  4064. * Scroller
  4065. * http://github.com/zynga/scroller
  4066. *
  4067. * Copyright 2011, Zynga Inc.
  4068. * Licensed under the MIT License.
  4069. * https://raw.github.com/zynga/scroller/master/MIT-LICENSE.txt
  4070. *
  4071. * Based on the work of: Unify Project (unify-project.org)
  4072. * http://unify-project.org
  4073. * Copyright 2011, Deutsche Telekom AG
  4074. * License: MIT + Apache (V2)
  4075. */
  4076. (function(ionic) {
  4077. var NOOP = function(){};
  4078. // Easing Equations (c) 2003 Robert Penner, all rights reserved.
  4079. // Open source under the BSD License.
  4080. /**
  4081. * @param pos {Number} position between 0 (start of effect) and 1 (end of effect)
  4082. **/
  4083. var easeOutCubic = function(pos) {
  4084. return (Math.pow((pos - 1), 3) + 1);
  4085. };
  4086. /**
  4087. * @param pos {Number} position between 0 (start of effect) and 1 (end of effect)
  4088. **/
  4089. var easeInOutCubic = function(pos) {
  4090. if ((pos /= 0.5) < 1) {
  4091. return 0.5 * Math.pow(pos, 3);
  4092. }
  4093. return 0.5 * (Math.pow((pos - 2), 3) + 2);
  4094. };
  4095. /**
  4096. * ionic.views.Scroll
  4097. * A powerful scroll view with support for bouncing, pull to refresh, and paging.
  4098. * @param {Object} options options for the scroll view
  4099. * @class A scroll view system
  4100. * @memberof ionic.views
  4101. */
  4102. ionic.views.Scroll = ionic.views.View.inherit({
  4103. initialize: function(options) {
  4104. var self = this;
  4105. self.__container = options.el;
  4106. self.__content = options.el.firstElementChild;
  4107. //Remove any scrollTop attached to these elements; they are virtual scroll now
  4108. //This also stops on-load-scroll-to-window.location.hash that the browser does
  4109. setTimeout(function() {
  4110. if (self.__container && self.__content) {
  4111. self.__container.scrollTop = 0;
  4112. self.__content.scrollTop = 0;
  4113. }
  4114. });
  4115. self.options = {
  4116. /** Disable scrolling on x-axis by default */
  4117. scrollingX: false,
  4118. scrollbarX: true,
  4119. /** Enable scrolling on y-axis */
  4120. scrollingY: true,
  4121. scrollbarY: true,
  4122. startX: 0,
  4123. startY: 0,
  4124. /** The amount to dampen mousewheel events */
  4125. wheelDampen: 6,
  4126. /** The minimum size the scrollbars scale to while scrolling */
  4127. minScrollbarSizeX: 5,
  4128. minScrollbarSizeY: 5,
  4129. /** Scrollbar fading after scrolling */
  4130. scrollbarsFade: true,
  4131. scrollbarFadeDelay: 300,
  4132. /** The initial fade delay when the pane is resized or initialized */
  4133. scrollbarResizeFadeDelay: 1000,
  4134. /** Enable animations for deceleration, snap back, zooming and scrolling */
  4135. animating: true,
  4136. /** duration for animations triggered by scrollTo/zoomTo */
  4137. animationDuration: 250,
  4138. /** The velocity required to make the scroll view "slide" after touchend */
  4139. decelVelocityThreshold: 4,
  4140. /** The velocity required to make the scroll view "slide" after touchend when using paging */
  4141. decelVelocityThresholdPaging: 4,
  4142. /** Enable bouncing (content can be slowly moved outside and jumps back after releasing) */
  4143. bouncing: true,
  4144. /** Enable locking to the main axis if user moves only slightly on one of them at start */
  4145. locking: true,
  4146. /** Enable pagination mode (switching between full page content panes) */
  4147. paging: false,
  4148. /** Enable snapping of content to a configured pixel grid */
  4149. snapping: false,
  4150. /** Enable zooming of content via API, fingers and mouse wheel */
  4151. zooming: false,
  4152. /** Minimum zoom level */
  4153. minZoom: 0.5,
  4154. /** Maximum zoom level */
  4155. maxZoom: 3,
  4156. /** Multiply or decrease scrolling speed **/
  4157. speedMultiplier: 1,
  4158. deceleration: 0.97,
  4159. /** Whether to prevent default on a scroll operation to capture drag events **/
  4160. preventDefault: false,
  4161. /** Callback that is fired on the later of touch end or deceleration end,
  4162. provided that another scrolling action has not begun. Used to know
  4163. when to fade out a scrollbar. */
  4164. scrollingComplete: NOOP,
  4165. /** This configures the amount of change applied to deceleration when reaching boundaries **/
  4166. penetrationDeceleration: 0.03,
  4167. /** This configures the amount of change applied to acceleration when reaching boundaries **/
  4168. penetrationAcceleration: 0.08,
  4169. // The ms interval for triggering scroll events
  4170. scrollEventInterval: 10,
  4171. freeze: false,
  4172. getContentWidth: function() {
  4173. return Math.max(self.__content.scrollWidth, self.__content.offsetWidth);
  4174. },
  4175. getContentHeight: function() {
  4176. return Math.max(self.__content.scrollHeight, self.__content.offsetHeight + (self.__content.offsetTop * 2));
  4177. }
  4178. };
  4179. for (var key in options) {
  4180. self.options[key] = options[key];
  4181. }
  4182. self.hintResize = ionic.debounce(function() {
  4183. self.resize();
  4184. }, 1000, true);
  4185. self.onScroll = function() {
  4186. if (!ionic.scroll.isScrolling) {
  4187. setTimeout(self.setScrollStart, 50);
  4188. } else {
  4189. clearTimeout(self.scrollTimer);
  4190. self.scrollTimer = setTimeout(self.setScrollStop, 80);
  4191. }
  4192. };
  4193. self.freeze = function(shouldFreeze) {
  4194. if (arguments.length) {
  4195. self.options.freeze = shouldFreeze;
  4196. }
  4197. return self.options.freeze;
  4198. };
  4199. // We can just use the standard freeze pop in our mouth
  4200. self.freezeShut = self.freeze;
  4201. self.setScrollStart = function() {
  4202. ionic.scroll.isScrolling = Math.abs(ionic.scroll.lastTop - self.__scrollTop) > 1;
  4203. clearTimeout(self.scrollTimer);
  4204. self.scrollTimer = setTimeout(self.setScrollStop, 80);
  4205. };
  4206. self.setScrollStop = function() {
  4207. ionic.scroll.isScrolling = false;
  4208. ionic.scroll.lastTop = self.__scrollTop;
  4209. };
  4210. self.triggerScrollEvent = ionic.throttle(function() {
  4211. self.onScroll();
  4212. ionic.trigger('scroll', {
  4213. scrollTop: self.__scrollTop,
  4214. scrollLeft: self.__scrollLeft,
  4215. target: self.__container
  4216. });
  4217. }, self.options.scrollEventInterval);
  4218. self.triggerScrollEndEvent = function() {
  4219. ionic.trigger('scrollend', {
  4220. scrollTop: self.__scrollTop,
  4221. scrollLeft: self.__scrollLeft,
  4222. target: self.__container
  4223. });
  4224. };
  4225. self.__scrollLeft = self.options.startX;
  4226. self.__scrollTop = self.options.startY;
  4227. // Get the render update function, initialize event handlers,
  4228. // and calculate the size of the scroll container
  4229. self.__callback = self.getRenderFn();
  4230. self.__initEventHandlers();
  4231. self.__createScrollbars();
  4232. },
  4233. run: function() {
  4234. this.resize();
  4235. // Fade them out
  4236. this.__fadeScrollbars('out', this.options.scrollbarResizeFadeDelay);
  4237. },
  4238. /*
  4239. ---------------------------------------------------------------------------
  4240. INTERNAL FIELDS :: STATUS
  4241. ---------------------------------------------------------------------------
  4242. */
  4243. /** Whether only a single finger is used in touch handling */
  4244. __isSingleTouch: false,
  4245. /** Whether a touch event sequence is in progress */
  4246. __isTracking: false,
  4247. /** Whether a deceleration animation went to completion. */
  4248. __didDecelerationComplete: false,
  4249. /**
  4250. * Whether a gesture zoom/rotate event is in progress. Activates when
  4251. * a gesturestart event happens. This has higher priority than dragging.
  4252. */
  4253. __isGesturing: false,
  4254. /**
  4255. * Whether the user has moved by such a distance that we have enabled
  4256. * dragging mode. Hint: It's only enabled after some pixels of movement to
  4257. * not interrupt with clicks etc.
  4258. */
  4259. __isDragging: false,
  4260. /**
  4261. * Not touching and dragging anymore, and smoothly animating the
  4262. * touch sequence using deceleration.
  4263. */
  4264. __isDecelerating: false,
  4265. /**
  4266. * Smoothly animating the currently configured change
  4267. */
  4268. __isAnimating: false,
  4269. /*
  4270. ---------------------------------------------------------------------------
  4271. INTERNAL FIELDS :: DIMENSIONS
  4272. ---------------------------------------------------------------------------
  4273. */
  4274. /** Available outer left position (from document perspective) */
  4275. __clientLeft: 0,
  4276. /** Available outer top position (from document perspective) */
  4277. __clientTop: 0,
  4278. /** Available outer width */
  4279. __clientWidth: 0,
  4280. /** Available outer height */
  4281. __clientHeight: 0,
  4282. /** Outer width of content */
  4283. __contentWidth: 0,
  4284. /** Outer height of content */
  4285. __contentHeight: 0,
  4286. /** Snapping width for content */
  4287. __snapWidth: 100,
  4288. /** Snapping height for content */
  4289. __snapHeight: 100,
  4290. /** Height to assign to refresh area */
  4291. __refreshHeight: null,
  4292. /** Whether the refresh process is enabled when the event is released now */
  4293. __refreshActive: false,
  4294. /** Callback to execute on activation. This is for signalling the user about a refresh is about to happen when he release */
  4295. __refreshActivate: null,
  4296. /** Callback to execute on deactivation. This is for signalling the user about the refresh being cancelled */
  4297. __refreshDeactivate: null,
  4298. /** Callback to execute to start the actual refresh. Call {@link #refreshFinish} when done */
  4299. __refreshStart: null,
  4300. /** Zoom level */
  4301. __zoomLevel: 1,
  4302. /** Scroll position on x-axis */
  4303. __scrollLeft: 0,
  4304. /** Scroll position on y-axis */
  4305. __scrollTop: 0,
  4306. /** Maximum allowed scroll position on x-axis */
  4307. __maxScrollLeft: 0,
  4308. /** Maximum allowed scroll position on y-axis */
  4309. __maxScrollTop: 0,
  4310. /* Scheduled left position (final position when animating) */
  4311. __scheduledLeft: 0,
  4312. /* Scheduled top position (final position when animating) */
  4313. __scheduledTop: 0,
  4314. /* Scheduled zoom level (final scale when animating) */
  4315. __scheduledZoom: 0,
  4316. /*
  4317. ---------------------------------------------------------------------------
  4318. INTERNAL FIELDS :: LAST POSITIONS
  4319. ---------------------------------------------------------------------------
  4320. */
  4321. /** Left position of finger at start */
  4322. __lastTouchLeft: null,
  4323. /** Top position of finger at start */
  4324. __lastTouchTop: null,
  4325. /** Timestamp of last move of finger. Used to limit tracking range for deceleration speed. */
  4326. __lastTouchMove: null,
  4327. /** List of positions, uses three indexes for each state: left, top, timestamp */
  4328. __positions: null,
  4329. /*
  4330. ---------------------------------------------------------------------------
  4331. INTERNAL FIELDS :: DECELERATION SUPPORT
  4332. ---------------------------------------------------------------------------
  4333. */
  4334. /** Minimum left scroll position during deceleration */
  4335. __minDecelerationScrollLeft: null,
  4336. /** Minimum top scroll position during deceleration */
  4337. __minDecelerationScrollTop: null,
  4338. /** Maximum left scroll position during deceleration */
  4339. __maxDecelerationScrollLeft: null,
  4340. /** Maximum top scroll position during deceleration */
  4341. __maxDecelerationScrollTop: null,
  4342. /** Current factor to modify horizontal scroll position with on every step */
  4343. __decelerationVelocityX: null,
  4344. /** Current factor to modify vertical scroll position with on every step */
  4345. __decelerationVelocityY: null,
  4346. /** the browser-specific property to use for transforms */
  4347. __transformProperty: null,
  4348. __perspectiveProperty: null,
  4349. /** scrollbar indicators */
  4350. __indicatorX: null,
  4351. __indicatorY: null,
  4352. /** Timeout for scrollbar fading */
  4353. __scrollbarFadeTimeout: null,
  4354. /** whether we've tried to wait for size already */
  4355. __didWaitForSize: null,
  4356. __sizerTimeout: null,
  4357. __initEventHandlers: function() {
  4358. var self = this;
  4359. // Event Handler
  4360. var container = self.__container;
  4361. // save height when scroll view is shrunk so we don't need to reflow
  4362. var scrollViewOffsetHeight;
  4363. /**
  4364. * Shrink the scroll view when the keyboard is up if necessary and if the
  4365. * focused input is below the bottom of the shrunk scroll view, scroll it
  4366. * into view.
  4367. */
  4368. self.scrollChildIntoView = function(e) {
  4369. //console.log("scrollChildIntoView at: " + Date.now());
  4370. // D
  4371. var scrollBottomOffsetToTop = container.getBoundingClientRect().bottom;
  4372. // D - A
  4373. scrollViewOffsetHeight = container.offsetHeight;
  4374. var alreadyShrunk = self.isShrunkForKeyboard;
  4375. var isModal = container.parentNode.classList.contains('modal');
  4376. // 680px is when the media query for 60% modal width kicks in
  4377. var isInsetModal = isModal && window.innerWidth >= 680;
  4378. /*
  4379. * _______
  4380. * |---A---| <- top of scroll view
  4381. * | |
  4382. * |---B---| <- keyboard
  4383. * | C | <- input
  4384. * |---D---| <- initial bottom of scroll view
  4385. * |___E___| <- bottom of viewport
  4386. *
  4387. * All commented calculations relative to the top of the viewport (ie E
  4388. * is the viewport height, not 0)
  4389. */
  4390. if (!alreadyShrunk) {
  4391. // shrink scrollview so we can actually scroll if the input is hidden
  4392. // if it isn't shrink so we can scroll to inputs under the keyboard
  4393. // inset modals won't shrink on Android on their own when the keyboard appears
  4394. if ( ionic.Platform.isIOS() || ionic.Platform.isFullScreen || isInsetModal ) {
  4395. // if there are things below the scroll view account for them and
  4396. // subtract them from the keyboard height when resizing
  4397. // E - D E D
  4398. var scrollBottomOffsetToBottom = e.detail.viewportHeight - scrollBottomOffsetToTop;
  4399. // 0 or D - B if D > B E - B E - D
  4400. var keyboardOffset = Math.max(0, e.detail.keyboardHeight - scrollBottomOffsetToBottom);
  4401. ionic.requestAnimationFrame(function(){
  4402. // D - A or B - A if D > B D - A max(0, D - B)
  4403. scrollViewOffsetHeight = scrollViewOffsetHeight - keyboardOffset;
  4404. container.style.height = scrollViewOffsetHeight + "px";
  4405. container.style.overflow = "visible";
  4406. //update scroll view
  4407. self.resize();
  4408. });
  4409. }
  4410. self.isShrunkForKeyboard = true;
  4411. }
  4412. /*
  4413. * _______
  4414. * |---A---| <- top of scroll view
  4415. * | * | <- where we want to scroll to
  4416. * |--B-D--| <- keyboard, bottom of scroll view
  4417. * | C | <- input
  4418. * | |
  4419. * |___E___| <- bottom of viewport
  4420. *
  4421. * All commented calculations relative to the top of the viewport (ie E
  4422. * is the viewport height, not 0)
  4423. */
  4424. // if the element is positioned under the keyboard scroll it into view
  4425. if (e.detail.isElementUnderKeyboard) {
  4426. ionic.requestAnimationFrame(function(){
  4427. container.scrollTop = 0;
  4428. // update D if we shrunk
  4429. if (self.isShrunkForKeyboard && !alreadyShrunk) {
  4430. scrollBottomOffsetToTop = container.getBoundingClientRect().bottom;
  4431. }
  4432. // middle of the scrollview, this is where we want to scroll to
  4433. // (D - A) / 2
  4434. var scrollMidpointOffset = scrollViewOffsetHeight * 0.5;
  4435. //console.log("container.offsetHeight: " + scrollViewOffsetHeight);
  4436. // middle of the input we want to scroll into view
  4437. // C
  4438. var inputMidpoint = ((e.detail.elementBottom + e.detail.elementTop) / 2);
  4439. // distance from middle of input to the bottom of the scroll view
  4440. // C - D C D
  4441. var inputMidpointOffsetToScrollBottom = inputMidpoint - scrollBottomOffsetToTop;
  4442. //C - D + (D - A)/2 C - D (D - A)/ 2
  4443. var scrollTop = inputMidpointOffsetToScrollBottom + scrollMidpointOffset;
  4444. if ( scrollTop > 0) {
  4445. if (ionic.Platform.isIOS()) ionic.tap.cloneFocusedInput(container, self);
  4446. self.scrollBy(0, scrollTop, true);
  4447. self.onScroll();
  4448. }
  4449. });
  4450. }
  4451. // Only the first scrollView parent of the element that broadcasted this event
  4452. // (the active element that needs to be shown) should receive this event
  4453. e.stopPropagation();
  4454. };
  4455. self.resetScrollView = function() {
  4456. //return scrollview to original height once keyboard has hidden
  4457. if ( self.isShrunkForKeyboard ) {
  4458. self.isShrunkForKeyboard = false;
  4459. container.style.height = "";
  4460. container.style.overflow = "";
  4461. }
  4462. self.resize();
  4463. };
  4464. //Broadcasted when keyboard is shown on some platforms.
  4465. //See js/utils/keyboard.js
  4466. container.addEventListener('scrollChildIntoView', self.scrollChildIntoView);
  4467. // Listen on document because container may not have had the last
  4468. // keyboardActiveElement, for example after closing a modal with a focused
  4469. // input and returning to a previously resized scroll view in an ion-content.
  4470. // Since we can only resize scroll views that are currently visible, just resize
  4471. // the current scroll view when the keyboard is closed.
  4472. document.addEventListener('resetScrollView', self.resetScrollView);
  4473. function getEventTouches(e) {
  4474. return e.touches && e.touches.length ? e.touches : [{
  4475. pageX: e.pageX,
  4476. pageY: e.pageY
  4477. }];
  4478. }
  4479. self.touchStart = function(e) {
  4480. self.startCoordinates = ionic.tap.pointerCoord(e);
  4481. if ( ionic.tap.ignoreScrollStart(e) ) {
  4482. return;
  4483. }
  4484. self.__isDown = true;
  4485. if ( ionic.tap.containsOrIsTextInput(e.target) || e.target.tagName === 'SELECT' ) {
  4486. // do not start if the target is a text input
  4487. // if there is a touchmove on this input, then we can start the scroll
  4488. self.__hasStarted = false;
  4489. return;
  4490. }
  4491. self.__isSelectable = true;
  4492. self.__enableScrollY = true;
  4493. self.__hasStarted = true;
  4494. self.doTouchStart(getEventTouches(e), e.timeStamp);
  4495. e.preventDefault();
  4496. };
  4497. self.touchMove = function(e) {
  4498. if (self.options.freeze || !self.__isDown ||
  4499. (!self.__isDown && e.defaultPrevented) ||
  4500. (e.target.tagName === 'TEXTAREA' && e.target.parentElement.querySelector(':focus')) ) {
  4501. return;
  4502. }
  4503. if ( !self.__hasStarted && ( ionic.tap.containsOrIsTextInput(e.target) || e.target.tagName === 'SELECT' ) ) {
  4504. // the target is a text input and scroll has started
  4505. // since the text input doesn't start on touchStart, do it here
  4506. self.__hasStarted = true;
  4507. self.doTouchStart(getEventTouches(e), e.timeStamp);
  4508. e.preventDefault();
  4509. return;
  4510. }
  4511. if (self.startCoordinates) {
  4512. // we have start coordinates, so get this touch move's current coordinates
  4513. var currentCoordinates = ionic.tap.pointerCoord(e);
  4514. if ( self.__isSelectable &&
  4515. ionic.tap.isTextInput(e.target) &&
  4516. Math.abs(self.startCoordinates.x - currentCoordinates.x) > 20 ) {
  4517. // user slid the text input's caret on its x axis, disable any future y scrolling
  4518. self.__enableScrollY = false;
  4519. self.__isSelectable = true;
  4520. }
  4521. if ( self.__enableScrollY && Math.abs(self.startCoordinates.y - currentCoordinates.y) > 10 ) {
  4522. // user scrolled the entire view on the y axis
  4523. // disabled being able to select text on an input
  4524. // hide the input which has focus, and show a cloned one that doesn't have focus
  4525. self.__isSelectable = false;
  4526. ionic.tap.cloneFocusedInput(container, self);
  4527. }
  4528. }
  4529. self.doTouchMove(getEventTouches(e), e.timeStamp, e.scale);
  4530. self.__isDown = true;
  4531. };
  4532. self.touchMoveBubble = function(e) {
  4533. if(self.__isDown && self.options.preventDefault) {
  4534. e.preventDefault();
  4535. }
  4536. };
  4537. self.touchEnd = function(e) {
  4538. if (!self.__isDown) return;
  4539. self.doTouchEnd(e, e.timeStamp);
  4540. self.__isDown = false;
  4541. self.__hasStarted = false;
  4542. self.__isSelectable = true;
  4543. self.__enableScrollY = true;
  4544. if ( !self.__isDragging && !self.__isDecelerating && !self.__isAnimating ) {
  4545. ionic.tap.removeClonedInputs(container, self);
  4546. }
  4547. };
  4548. self.mouseWheel = ionic.animationFrameThrottle(function(e) {
  4549. var scrollParent = ionic.DomUtil.getParentOrSelfWithClass(e.target, 'ionic-scroll');
  4550. if (!self.options.freeze && scrollParent === self.__container) {
  4551. self.hintResize();
  4552. self.scrollBy(
  4553. (e.wheelDeltaX || e.deltaX || 0) / self.options.wheelDampen,
  4554. (-e.wheelDeltaY || e.deltaY || 0) / self.options.wheelDampen
  4555. );
  4556. self.__fadeScrollbars('in');
  4557. clearTimeout(self.__wheelHideBarTimeout);
  4558. self.__wheelHideBarTimeout = setTimeout(function() {
  4559. self.__fadeScrollbars('out');
  4560. }, 100);
  4561. }
  4562. });
  4563. if ('ontouchstart' in window) {
  4564. // Touch Events
  4565. container.addEventListener("touchstart", self.touchStart, false);
  4566. if(self.options.preventDefault) container.addEventListener("touchmove", self.touchMoveBubble, false);
  4567. document.addEventListener("touchmove", self.touchMove, false);
  4568. document.addEventListener("touchend", self.touchEnd, false);
  4569. document.addEventListener("touchcancel", self.touchEnd, false);
  4570. document.addEventListener("wheel", self.mouseWheel, false);
  4571. } else if (window.navigator.pointerEnabled) {
  4572. // Pointer Events
  4573. container.addEventListener("pointerdown", self.touchStart, false);
  4574. if(self.options.preventDefault) container.addEventListener("pointermove", self.touchMoveBubble, false);
  4575. document.addEventListener("pointermove", self.touchMove, false);
  4576. document.addEventListener("pointerup", self.touchEnd, false);
  4577. document.addEventListener("pointercancel", self.touchEnd, false);
  4578. document.addEventListener("wheel", self.mouseWheel, false);
  4579. } else if (window.navigator.msPointerEnabled) {
  4580. // IE10, WP8 (Pointer Events)
  4581. container.addEventListener("MSPointerDown", self.touchStart, false);
  4582. if(self.options.preventDefault) container.addEventListener("MSPointerMove", self.touchMoveBubble, false);
  4583. document.addEventListener("MSPointerMove", self.touchMove, false);
  4584. document.addEventListener("MSPointerUp", self.touchEnd, false);
  4585. document.addEventListener("MSPointerCancel", self.touchEnd, false);
  4586. document.addEventListener("wheel", self.mouseWheel, false);
  4587. } else {
  4588. // Mouse Events
  4589. var mousedown = false;
  4590. self.mouseDown = function(e) {
  4591. if ( ionic.tap.ignoreScrollStart(e) || e.target.tagName === 'SELECT' ) {
  4592. return;
  4593. }
  4594. self.doTouchStart(getEventTouches(e), e.timeStamp);
  4595. if ( !ionic.tap.isTextInput(e.target) ) {
  4596. e.preventDefault();
  4597. }
  4598. mousedown = true;
  4599. };
  4600. self.mouseMove = function(e) {
  4601. if (self.options.freeze || !mousedown || (!mousedown && e.defaultPrevented)) {
  4602. return;
  4603. }
  4604. self.doTouchMove(getEventTouches(e), e.timeStamp);
  4605. mousedown = true;
  4606. };
  4607. self.mouseMoveBubble = function(e) {
  4608. if (mousedown && self.options.preventDefault) {
  4609. e.preventDefault();
  4610. }
  4611. };
  4612. self.mouseUp = function(e) {
  4613. if (!mousedown) {
  4614. return;
  4615. }
  4616. self.doTouchEnd(e, e.timeStamp);
  4617. mousedown = false;
  4618. };
  4619. container.addEventListener("mousedown", self.mouseDown, false);
  4620. if(self.options.preventDefault) container.addEventListener("mousemove", self.mouseMoveBubble, false);
  4621. document.addEventListener("mousemove", self.mouseMove, false);
  4622. document.addEventListener("mouseup", self.mouseUp, false);
  4623. document.addEventListener('mousewheel', self.mouseWheel, false);
  4624. document.addEventListener('wheel', self.mouseWheel, false);
  4625. }
  4626. },
  4627. __cleanup: function() {
  4628. var self = this;
  4629. var container = self.__container;
  4630. container.removeEventListener('touchstart', self.touchStart);
  4631. container.removeEventListener('touchmove', self.touchMoveBubble);
  4632. document.removeEventListener('touchmove', self.touchMove);
  4633. document.removeEventListener('touchend', self.touchEnd);
  4634. document.removeEventListener('touchcancel', self.touchEnd);
  4635. container.removeEventListener("pointerdown", self.touchStart);
  4636. container.removeEventListener("pointermove", self.touchMoveBubble);
  4637. document.removeEventListener("pointermove", self.touchMove);
  4638. document.removeEventListener("pointerup", self.touchEnd);
  4639. document.removeEventListener("pointercancel", self.touchEnd);
  4640. container.removeEventListener("MSPointerDown", self.touchStart);
  4641. container.removeEventListener("MSPointerMove", self.touchMoveBubble);
  4642. document.removeEventListener("MSPointerMove", self.touchMove);
  4643. document.removeEventListener("MSPointerUp", self.touchEnd);
  4644. document.removeEventListener("MSPointerCancel", self.touchEnd);
  4645. container.removeEventListener("mousedown", self.mouseDown);
  4646. container.removeEventListener("mousemove", self.mouseMoveBubble);
  4647. document.removeEventListener("mousemove", self.mouseMove);
  4648. document.removeEventListener("mouseup", self.mouseUp);
  4649. document.removeEventListener('mousewheel', self.mouseWheel);
  4650. document.removeEventListener('wheel', self.mouseWheel);
  4651. container.removeEventListener('scrollChildIntoView', self.scrollChildIntoView);
  4652. document.removeEventListener('resetScrollView', self.resetScrollView);
  4653. ionic.tap.removeClonedInputs(container, self);
  4654. delete self.__container;
  4655. delete self.__content;
  4656. delete self.__indicatorX;
  4657. delete self.__indicatorY;
  4658. delete self.options.el;
  4659. self.__callback = self.scrollChildIntoView = self.resetScrollView = NOOP;
  4660. self.mouseMove = self.mouseDown = self.mouseUp = self.mouseWheel =
  4661. self.touchStart = self.touchMove = self.touchEnd = self.touchCancel = NOOP;
  4662. self.resize = self.scrollTo = self.zoomTo =
  4663. self.__scrollingComplete = NOOP;
  4664. container = null;
  4665. },
  4666. /** Create a scroll bar div with the given direction **/
  4667. __createScrollbar: function(direction) {
  4668. var bar = document.createElement('div'),
  4669. indicator = document.createElement('div');
  4670. indicator.className = 'scroll-bar-indicator scroll-bar-fade-out';
  4671. if (direction == 'h') {
  4672. bar.className = 'scroll-bar scroll-bar-h';
  4673. } else {
  4674. bar.className = 'scroll-bar scroll-bar-v';
  4675. }
  4676. bar.appendChild(indicator);
  4677. return bar;
  4678. },
  4679. __createScrollbars: function() {
  4680. var self = this;
  4681. var indicatorX, indicatorY;
  4682. if (self.options.scrollingX) {
  4683. indicatorX = {
  4684. el: self.__createScrollbar('h'),
  4685. sizeRatio: 1
  4686. };
  4687. indicatorX.indicator = indicatorX.el.children[0];
  4688. if (self.options.scrollbarX) {
  4689. self.__container.appendChild(indicatorX.el);
  4690. }
  4691. self.__indicatorX = indicatorX;
  4692. }
  4693. if (self.options.scrollingY) {
  4694. indicatorY = {
  4695. el: self.__createScrollbar('v'),
  4696. sizeRatio: 1
  4697. };
  4698. indicatorY.indicator = indicatorY.el.children[0];
  4699. if (self.options.scrollbarY) {
  4700. self.__container.appendChild(indicatorY.el);
  4701. }
  4702. self.__indicatorY = indicatorY;
  4703. }
  4704. },
  4705. __resizeScrollbars: function() {
  4706. var self = this;
  4707. // Update horiz bar
  4708. if (self.__indicatorX) {
  4709. var width = Math.max(Math.round(self.__clientWidth * self.__clientWidth / (self.__contentWidth)), 20);
  4710. if (width > self.__contentWidth) {
  4711. width = 0;
  4712. }
  4713. if (width !== self.__indicatorX.size) {
  4714. ionic.requestAnimationFrame(function(){
  4715. self.__indicatorX.indicator.style.width = width + 'px';
  4716. });
  4717. }
  4718. self.__indicatorX.size = width;
  4719. self.__indicatorX.minScale = self.options.minScrollbarSizeX / width;
  4720. self.__indicatorX.maxPos = self.__clientWidth - width;
  4721. self.__indicatorX.sizeRatio = self.__maxScrollLeft ? self.__indicatorX.maxPos / self.__maxScrollLeft : 1;
  4722. }
  4723. // Update vert bar
  4724. if (self.__indicatorY) {
  4725. var height = Math.max(Math.round(self.__clientHeight * self.__clientHeight / (self.__contentHeight)), 20);
  4726. if (height > self.__contentHeight) {
  4727. height = 0;
  4728. }
  4729. if (height !== self.__indicatorY.size) {
  4730. ionic.requestAnimationFrame(function(){
  4731. self.__indicatorY && (self.__indicatorY.indicator.style.height = height + 'px');
  4732. });
  4733. }
  4734. self.__indicatorY.size = height;
  4735. self.__indicatorY.minScale = self.options.minScrollbarSizeY / height;
  4736. self.__indicatorY.maxPos = self.__clientHeight - height;
  4737. self.__indicatorY.sizeRatio = self.__maxScrollTop ? self.__indicatorY.maxPos / self.__maxScrollTop : 1;
  4738. }
  4739. },
  4740. /**
  4741. * Move and scale the scrollbars as the page scrolls.
  4742. */
  4743. __repositionScrollbars: function() {
  4744. var self = this,
  4745. heightScale, widthScale,
  4746. widthDiff, heightDiff,
  4747. x, y,
  4748. xstop = 0, ystop = 0;
  4749. if (self.__indicatorX) {
  4750. // Handle the X scrollbar
  4751. // Don't go all the way to the right if we have a vertical scrollbar as well
  4752. if (self.__indicatorY) xstop = 10;
  4753. x = Math.round(self.__indicatorX.sizeRatio * self.__scrollLeft) || 0;
  4754. // The the difference between the last content X position, and our overscrolled one
  4755. widthDiff = self.__scrollLeft - (self.__maxScrollLeft - xstop);
  4756. if (self.__scrollLeft < 0) {
  4757. widthScale = Math.max(self.__indicatorX.minScale,
  4758. (self.__indicatorX.size - Math.abs(self.__scrollLeft)) / self.__indicatorX.size);
  4759. // Stay at left
  4760. x = 0;
  4761. // Make sure scale is transformed from the left/center origin point
  4762. self.__indicatorX.indicator.style[self.__transformOriginProperty] = 'left center';
  4763. } else if (widthDiff > 0) {
  4764. widthScale = Math.max(self.__indicatorX.minScale,
  4765. (self.__indicatorX.size - widthDiff) / self.__indicatorX.size);
  4766. // Stay at the furthest x for the scrollable viewport
  4767. x = self.__indicatorX.maxPos - xstop;
  4768. // Make sure scale is transformed from the right/center origin point
  4769. self.__indicatorX.indicator.style[self.__transformOriginProperty] = 'right center';
  4770. } else {
  4771. // Normal motion
  4772. x = Math.min(self.__maxScrollLeft, Math.max(0, x));
  4773. widthScale = 1;
  4774. }
  4775. var translate3dX = 'translate3d(' + x + 'px, 0, 0) scaleX(' + widthScale + ')';
  4776. if (self.__indicatorX.transformProp !== translate3dX) {
  4777. self.__indicatorX.indicator.style[self.__transformProperty] = translate3dX;
  4778. self.__indicatorX.transformProp = translate3dX;
  4779. }
  4780. }
  4781. if (self.__indicatorY) {
  4782. y = Math.round(self.__indicatorY.sizeRatio * self.__scrollTop) || 0;
  4783. // Don't go all the way to the right if we have a vertical scrollbar as well
  4784. if (self.__indicatorX) ystop = 10;
  4785. heightDiff = self.__scrollTop - (self.__maxScrollTop - ystop);
  4786. if (self.__scrollTop < 0) {
  4787. heightScale = Math.max(self.__indicatorY.minScale, (self.__indicatorY.size - Math.abs(self.__scrollTop)) / self.__indicatorY.size);
  4788. // Stay at top
  4789. y = 0;
  4790. // Make sure scale is transformed from the center/top origin point
  4791. if (self.__indicatorY.originProp !== 'center top') {
  4792. self.__indicatorY.indicator.style[self.__transformOriginProperty] = 'center top';
  4793. self.__indicatorY.originProp = 'center top';
  4794. }
  4795. } else if (heightDiff > 0) {
  4796. heightScale = Math.max(self.__indicatorY.minScale, (self.__indicatorY.size - heightDiff) / self.__indicatorY.size);
  4797. // Stay at bottom of scrollable viewport
  4798. y = self.__indicatorY.maxPos - ystop;
  4799. // Make sure scale is transformed from the center/bottom origin point
  4800. if (self.__indicatorY.originProp !== 'center bottom') {
  4801. self.__indicatorY.indicator.style[self.__transformOriginProperty] = 'center bottom';
  4802. self.__indicatorY.originProp = 'center bottom';
  4803. }
  4804. } else {
  4805. // Normal motion
  4806. y = Math.min(self.__maxScrollTop, Math.max(0, y));
  4807. heightScale = 1;
  4808. }
  4809. var translate3dY = 'translate3d(0,' + y + 'px, 0) scaleY(' + heightScale + ')';
  4810. if (self.__indicatorY.transformProp !== translate3dY) {
  4811. self.__indicatorY.indicator.style[self.__transformProperty] = translate3dY;
  4812. self.__indicatorY.transformProp = translate3dY;
  4813. }
  4814. }
  4815. },
  4816. __fadeScrollbars: function(direction, delay) {
  4817. var self = this;
  4818. if (!self.options.scrollbarsFade) {
  4819. return;
  4820. }
  4821. var className = 'scroll-bar-fade-out';
  4822. if (self.options.scrollbarsFade === true) {
  4823. clearTimeout(self.__scrollbarFadeTimeout);
  4824. if (direction == 'in') {
  4825. if (self.__indicatorX) { self.__indicatorX.indicator.classList.remove(className); }
  4826. if (self.__indicatorY) { self.__indicatorY.indicator.classList.remove(className); }
  4827. } else {
  4828. self.__scrollbarFadeTimeout = setTimeout(function() {
  4829. if (self.__indicatorX) { self.__indicatorX.indicator.classList.add(className); }
  4830. if (self.__indicatorY) { self.__indicatorY.indicator.classList.add(className); }
  4831. }, delay || self.options.scrollbarFadeDelay);
  4832. }
  4833. }
  4834. },
  4835. __scrollingComplete: function() {
  4836. this.options.scrollingComplete();
  4837. ionic.tap.removeClonedInputs(this.__container, this);
  4838. this.__fadeScrollbars('out');
  4839. },
  4840. resize: function(continueScrolling) {
  4841. var self = this;
  4842. if (!self.__container || !self.options) return;
  4843. // Update Scroller dimensions for changed content
  4844. // Add padding to bottom of content
  4845. self.setDimensions(
  4846. self.__container.clientWidth,
  4847. self.__container.clientHeight,
  4848. self.options.getContentWidth(),
  4849. self.options.getContentHeight(),
  4850. continueScrolling
  4851. );
  4852. },
  4853. /*
  4854. ---------------------------------------------------------------------------
  4855. PUBLIC API
  4856. ---------------------------------------------------------------------------
  4857. */
  4858. getRenderFn: function() {
  4859. var self = this;
  4860. var content = self.__content;
  4861. var docStyle = document.documentElement.style;
  4862. var engine;
  4863. if ('MozAppearance' in docStyle) {
  4864. engine = 'gecko';
  4865. } else if ('WebkitAppearance' in docStyle) {
  4866. engine = 'webkit';
  4867. } else if (typeof navigator.cpuClass === 'string') {
  4868. engine = 'trident';
  4869. }
  4870. var vendorPrefix = {
  4871. trident: 'ms',
  4872. gecko: 'Moz',
  4873. webkit: 'Webkit',
  4874. presto: 'O'
  4875. }[engine];
  4876. var helperElem = document.createElement("div");
  4877. var undef;
  4878. var perspectiveProperty = vendorPrefix + "Perspective";
  4879. var transformProperty = vendorPrefix + "Transform";
  4880. var transformOriginProperty = vendorPrefix + 'TransformOrigin';
  4881. self.__perspectiveProperty = transformProperty;
  4882. self.__transformProperty = transformProperty;
  4883. self.__transformOriginProperty = transformOriginProperty;
  4884. if (helperElem.style[perspectiveProperty] !== undef) {
  4885. return function(left, top, zoom, wasResize) {
  4886. var translate3d = 'translate3d(' + (-left) + 'px,' + (-top) + 'px,0) scale(' + zoom + ')';
  4887. if (translate3d !== self.contentTransform) {
  4888. content.style[transformProperty] = translate3d;
  4889. self.contentTransform = translate3d;
  4890. }
  4891. self.__repositionScrollbars();
  4892. if (!wasResize) {
  4893. self.triggerScrollEvent();
  4894. }
  4895. };
  4896. } else if (helperElem.style[transformProperty] !== undef) {
  4897. return function(left, top, zoom, wasResize) {
  4898. content.style[transformProperty] = 'translate(' + (-left) + 'px,' + (-top) + 'px) scale(' + zoom + ')';
  4899. self.__repositionScrollbars();
  4900. if (!wasResize) {
  4901. self.triggerScrollEvent();
  4902. }
  4903. };
  4904. } else {
  4905. return function(left, top, zoom, wasResize) {
  4906. content.style.marginLeft = left ? (-left / zoom) + 'px' : '';
  4907. content.style.marginTop = top ? (-top / zoom) + 'px' : '';
  4908. content.style.zoom = zoom || '';
  4909. self.__repositionScrollbars();
  4910. if (!wasResize) {
  4911. self.triggerScrollEvent();
  4912. }
  4913. };
  4914. }
  4915. },
  4916. /**
  4917. * Configures the dimensions of the client (outer) and content (inner) elements.
  4918. * Requires the available space for the outer element and the outer size of the inner element.
  4919. * All values which are falsy (null or zero etc.) are ignored and the old value is kept.
  4920. *
  4921. * @param clientWidth {Integer} Inner width of outer element
  4922. * @param clientHeight {Integer} Inner height of outer element
  4923. * @param contentWidth {Integer} Outer width of inner element
  4924. * @param contentHeight {Integer} Outer height of inner element
  4925. */
  4926. setDimensions: function(clientWidth, clientHeight, contentWidth, contentHeight, continueScrolling) {
  4927. var self = this;
  4928. if (!clientWidth && !clientHeight && !contentWidth && !contentHeight) {
  4929. // this scrollview isn't rendered, don't bother
  4930. return;
  4931. }
  4932. // Only update values which are defined
  4933. if (clientWidth === +clientWidth) {
  4934. self.__clientWidth = clientWidth;
  4935. }
  4936. if (clientHeight === +clientHeight) {
  4937. self.__clientHeight = clientHeight;
  4938. }
  4939. if (contentWidth === +contentWidth) {
  4940. self.__contentWidth = contentWidth;
  4941. }
  4942. if (contentHeight === +contentHeight) {
  4943. self.__contentHeight = contentHeight;
  4944. }
  4945. // Refresh maximums
  4946. self.__computeScrollMax();
  4947. self.__resizeScrollbars();
  4948. // Refresh scroll position
  4949. if (!continueScrolling) {
  4950. self.scrollTo(self.__scrollLeft, self.__scrollTop, true, null, true);
  4951. }
  4952. },
  4953. /**
  4954. * Sets the client coordinates in relation to the document.
  4955. *
  4956. * @param left {Integer} Left position of outer element
  4957. * @param top {Integer} Top position of outer element
  4958. */
  4959. setPosition: function(left, top) {
  4960. this.__clientLeft = left || 0;
  4961. this.__clientTop = top || 0;
  4962. },
  4963. /**
  4964. * Configures the snapping (when snapping is active)
  4965. *
  4966. * @param width {Integer} Snapping width
  4967. * @param height {Integer} Snapping height
  4968. */
  4969. setSnapSize: function(width, height) {
  4970. this.__snapWidth = width;
  4971. this.__snapHeight = height;
  4972. },
  4973. /**
  4974. * Activates pull-to-refresh. A special zone on the top of the list to start a list refresh whenever
  4975. * the user event is released during visibility of this zone. This was introduced by some apps on iOS like
  4976. * the official Twitter client.
  4977. *
  4978. * @param height {Integer} Height of pull-to-refresh zone on top of rendered list
  4979. * @param activateCallback {Function} Callback to execute on activation. This is for signalling the user about a refresh is about to happen when he release.
  4980. * @param deactivateCallback {Function} Callback to execute on deactivation. This is for signalling the user about the refresh being cancelled.
  4981. * @param startCallback {Function} Callback to execute to start the real async refresh action. Call {@link #finishPullToRefresh} after finish of refresh.
  4982. * @param showCallback {Function} Callback to execute when the refresher should be shown. This is for showing the refresher during a negative scrollTop.
  4983. * @param hideCallback {Function} Callback to execute when the refresher should be hidden. This is for hiding the refresher when it's behind the nav bar.
  4984. * @param tailCallback {Function} Callback to execute just before the refresher returns to it's original state. This is for zooming out the refresher.
  4985. * @param pullProgressCallback Callback to state the progress while pulling to refresh
  4986. */
  4987. activatePullToRefresh: function(height, refresherMethods) {
  4988. var self = this;
  4989. self.__refreshHeight = height;
  4990. self.__refreshActivate = function() { ionic.requestAnimationFrame(refresherMethods.activate); };
  4991. self.__refreshDeactivate = function() { ionic.requestAnimationFrame(refresherMethods.deactivate); };
  4992. self.__refreshStart = function() { ionic.requestAnimationFrame(refresherMethods.start); };
  4993. self.__refreshShow = function() { ionic.requestAnimationFrame(refresherMethods.show); };
  4994. self.__refreshHide = function() { ionic.requestAnimationFrame(refresherMethods.hide); };
  4995. self.__refreshTail = function() { ionic.requestAnimationFrame(refresherMethods.tail); };
  4996. self.__refreshTailTime = 100;
  4997. self.__minSpinTime = 600;
  4998. },
  4999. /**
  5000. * Starts pull-to-refresh manually.
  5001. */
  5002. triggerPullToRefresh: function() {
  5003. // Use publish instead of scrollTo to allow scrolling to out of boundary position
  5004. // We don't need to normalize scrollLeft, zoomLevel, etc. here because we only y-scrolling when pull-to-refresh is enabled
  5005. this.__publish(this.__scrollLeft, -this.__refreshHeight, this.__zoomLevel, true);
  5006. var d = new Date();
  5007. this.refreshStartTime = d.getTime();
  5008. if (this.__refreshStart) {
  5009. this.__refreshStart();
  5010. }
  5011. },
  5012. /**
  5013. * Signalizes that pull-to-refresh is finished.
  5014. */
  5015. finishPullToRefresh: function() {
  5016. var self = this;
  5017. // delay to make sure the spinner has a chance to spin for a split second before it's dismissed
  5018. var d = new Date();
  5019. var delay = 0;
  5020. if (self.refreshStartTime + self.__minSpinTime > d.getTime()) {
  5021. delay = self.refreshStartTime + self.__minSpinTime - d.getTime();
  5022. }
  5023. setTimeout(function() {
  5024. if (self.__refreshTail) {
  5025. self.__refreshTail();
  5026. }
  5027. setTimeout(function() {
  5028. self.__refreshActive = false;
  5029. if (self.__refreshDeactivate) {
  5030. self.__refreshDeactivate();
  5031. }
  5032. if (self.__refreshHide) {
  5033. self.__refreshHide();
  5034. }
  5035. self.scrollTo(self.__scrollLeft, self.__scrollTop, true);
  5036. }, self.__refreshTailTime);
  5037. }, delay);
  5038. },
  5039. /**
  5040. * Returns the scroll position and zooming values
  5041. *
  5042. * @return {Map} `left` and `top` scroll position and `zoom` level
  5043. */
  5044. getValues: function() {
  5045. return {
  5046. left: this.__scrollLeft,
  5047. top: this.__scrollTop,
  5048. zoom: this.__zoomLevel
  5049. };
  5050. },
  5051. /**
  5052. * Returns the maximum scroll values
  5053. *
  5054. * @return {Map} `left` and `top` maximum scroll values
  5055. */
  5056. getScrollMax: function() {
  5057. return {
  5058. left: this.__maxScrollLeft,
  5059. top: this.__maxScrollTop
  5060. };
  5061. },
  5062. /**
  5063. * Zooms to the given level. Supports optional animation. Zooms
  5064. * the center when no coordinates are given.
  5065. *
  5066. * @param level {Number} Level to zoom to
  5067. * @param animate {Boolean} Whether to use animation
  5068. * @param originLeft {Number} Zoom in at given left coordinate
  5069. * @param originTop {Number} Zoom in at given top coordinate
  5070. */
  5071. zoomTo: function(level, animate, originLeft, originTop) {
  5072. var self = this;
  5073. if (!self.options.zooming) {
  5074. throw new Error("Zooming is not enabled!");
  5075. }
  5076. // Stop deceleration
  5077. if (self.__isDecelerating) {
  5078. zyngaCore.effect.Animate.stop(self.__isDecelerating);
  5079. self.__isDecelerating = false;
  5080. }
  5081. var oldLevel = self.__zoomLevel;
  5082. // Normalize input origin to center of viewport if not defined
  5083. if (originLeft == null) {
  5084. originLeft = self.__clientWidth / 2;
  5085. }
  5086. if (originTop == null) {
  5087. originTop = self.__clientHeight / 2;
  5088. }
  5089. // Limit level according to configuration
  5090. level = Math.max(Math.min(level, self.options.maxZoom), self.options.minZoom);
  5091. // Recompute maximum values while temporary tweaking maximum scroll ranges
  5092. self.__computeScrollMax(level);
  5093. // Recompute left and top coordinates based on new zoom level
  5094. var left = ((originLeft + self.__scrollLeft) * level / oldLevel) - originLeft;
  5095. var top = ((originTop + self.__scrollTop) * level / oldLevel) - originTop;
  5096. // Limit x-axis
  5097. if (left > self.__maxScrollLeft) {
  5098. left = self.__maxScrollLeft;
  5099. } else if (left < 0) {
  5100. left = 0;
  5101. }
  5102. // Limit y-axis
  5103. if (top > self.__maxScrollTop) {
  5104. top = self.__maxScrollTop;
  5105. } else if (top < 0) {
  5106. top = 0;
  5107. }
  5108. // Push values out
  5109. self.__publish(left, top, level, animate);
  5110. },
  5111. /**
  5112. * Zooms the content by the given factor.
  5113. *
  5114. * @param factor {Number} Zoom by given factor
  5115. * @param animate {Boolean} Whether to use animation
  5116. * @param originLeft {Number} Zoom in at given left coordinate
  5117. * @param originTop {Number} Zoom in at given top coordinate
  5118. */
  5119. zoomBy: function(factor, animate, originLeft, originTop) {
  5120. this.zoomTo(this.__zoomLevel * factor, animate, originLeft, originTop);
  5121. },
  5122. /**
  5123. * Scrolls to the given position. Respect limitations and snapping automatically.
  5124. *
  5125. * @param left {Number} Horizontal scroll position, keeps current if value is <code>null</code>
  5126. * @param top {Number} Vertical scroll position, keeps current if value is <code>null</code>
  5127. * @param animate {Boolean} Whether the scrolling should happen using an animation
  5128. * @param zoom {Number} Zoom level to go to
  5129. */
  5130. scrollTo: function(left, top, animate, zoom, wasResize) {
  5131. var self = this;
  5132. // Stop deceleration
  5133. if (self.__isDecelerating) {
  5134. zyngaCore.effect.Animate.stop(self.__isDecelerating);
  5135. self.__isDecelerating = false;
  5136. }
  5137. // Correct coordinates based on new zoom level
  5138. if (zoom != null && zoom !== self.__zoomLevel) {
  5139. if (!self.options.zooming) {
  5140. throw new Error("Zooming is not enabled!");
  5141. }
  5142. left *= zoom;
  5143. top *= zoom;
  5144. // Recompute maximum values while temporary tweaking maximum scroll ranges
  5145. self.__computeScrollMax(zoom);
  5146. } else {
  5147. // Keep zoom when not defined
  5148. zoom = self.__zoomLevel;
  5149. }
  5150. if (!self.options.scrollingX) {
  5151. left = self.__scrollLeft;
  5152. } else {
  5153. if (self.options.paging) {
  5154. left = Math.round(left / self.__clientWidth) * self.__clientWidth;
  5155. } else if (self.options.snapping) {
  5156. left = Math.round(left / self.__snapWidth) * self.__snapWidth;
  5157. }
  5158. }
  5159. if (!self.options.scrollingY) {
  5160. top = self.__scrollTop;
  5161. } else {
  5162. if (self.options.paging) {
  5163. top = Math.round(top / self.__clientHeight) * self.__clientHeight;
  5164. } else if (self.options.snapping) {
  5165. top = Math.round(top / self.__snapHeight) * self.__snapHeight;
  5166. }
  5167. }
  5168. // Limit for allowed ranges
  5169. left = Math.max(Math.min(self.__maxScrollLeft, left), 0);
  5170. top = Math.max(Math.min(self.__maxScrollTop, top), 0);
  5171. // Don't animate when no change detected, still call publish to make sure
  5172. // that rendered position is really in-sync with internal data
  5173. if (left === self.__scrollLeft && top === self.__scrollTop) {
  5174. animate = false;
  5175. }
  5176. // Publish new values
  5177. self.__publish(left, top, zoom, animate, wasResize);
  5178. },
  5179. /**
  5180. * Scroll by the given offset
  5181. *
  5182. * @param left {Number} Scroll x-axis by given offset
  5183. * @param top {Number} Scroll y-axis by given offset
  5184. * @param animate {Boolean} Whether to animate the given change
  5185. */
  5186. scrollBy: function(left, top, animate) {
  5187. var self = this;
  5188. var startLeft = self.__isAnimating ? self.__scheduledLeft : self.__scrollLeft;
  5189. var startTop = self.__isAnimating ? self.__scheduledTop : self.__scrollTop;
  5190. self.scrollTo(startLeft + (left || 0), startTop + (top || 0), animate);
  5191. },
  5192. /*
  5193. ---------------------------------------------------------------------------
  5194. EVENT CALLBACKS
  5195. ---------------------------------------------------------------------------
  5196. */
  5197. /**
  5198. * Mouse wheel handler for zooming support
  5199. */
  5200. doMouseZoom: function(wheelDelta, timeStamp, pageX, pageY) {
  5201. var change = wheelDelta > 0 ? 0.97 : 1.03;
  5202. return this.zoomTo(this.__zoomLevel * change, false, pageX - this.__clientLeft, pageY - this.__clientTop);
  5203. },
  5204. /**
  5205. * Touch start handler for scrolling support
  5206. */
  5207. doTouchStart: function(touches, timeStamp) {
  5208. var self = this;
  5209. // remember if the deceleration was just stopped
  5210. self.__decStopped = !!(self.__isDecelerating || self.__isAnimating);
  5211. self.hintResize();
  5212. if (timeStamp instanceof Date) {
  5213. timeStamp = timeStamp.valueOf();
  5214. }
  5215. if (typeof timeStamp !== "number") {
  5216. timeStamp = Date.now();
  5217. }
  5218. // Reset interruptedAnimation flag
  5219. self.__interruptedAnimation = true;
  5220. // Stop deceleration
  5221. if (self.__isDecelerating) {
  5222. zyngaCore.effect.Animate.stop(self.__isDecelerating);
  5223. self.__isDecelerating = false;
  5224. self.__interruptedAnimation = true;
  5225. }
  5226. // Stop animation
  5227. if (self.__isAnimating) {
  5228. zyngaCore.effect.Animate.stop(self.__isAnimating);
  5229. self.__isAnimating = false;
  5230. self.__interruptedAnimation = true;
  5231. }
  5232. // Use center point when dealing with two fingers
  5233. var currentTouchLeft, currentTouchTop;
  5234. var isSingleTouch = touches.length === 1;
  5235. if (isSingleTouch) {
  5236. currentTouchLeft = touches[0].pageX;
  5237. currentTouchTop = touches[0].pageY;
  5238. } else {
  5239. currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2;
  5240. currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2;
  5241. }
  5242. // Store initial positions
  5243. self.__initialTouchLeft = currentTouchLeft;
  5244. self.__initialTouchTop = currentTouchTop;
  5245. // Store initial touchList for scale calculation
  5246. self.__initialTouches = touches;
  5247. // Store current zoom level
  5248. self.__zoomLevelStart = self.__zoomLevel;
  5249. // Store initial touch positions
  5250. self.__lastTouchLeft = currentTouchLeft;
  5251. self.__lastTouchTop = currentTouchTop;
  5252. // Store initial move time stamp
  5253. self.__lastTouchMove = timeStamp;
  5254. // Reset initial scale
  5255. self.__lastScale = 1;
  5256. // Reset locking flags
  5257. self.__enableScrollX = !isSingleTouch && self.options.scrollingX;
  5258. self.__enableScrollY = !isSingleTouch && self.options.scrollingY;
  5259. // Reset tracking flag
  5260. self.__isTracking = true;
  5261. // Reset deceleration complete flag
  5262. self.__didDecelerationComplete = false;
  5263. // Dragging starts directly with two fingers, otherwise lazy with an offset
  5264. self.__isDragging = !isSingleTouch;
  5265. // Some features are disabled in multi touch scenarios
  5266. self.__isSingleTouch = isSingleTouch;
  5267. // Clearing data structure
  5268. self.__positions = [];
  5269. },
  5270. /**
  5271. * Touch move handler for scrolling support
  5272. */
  5273. doTouchMove: function(touches, timeStamp, scale) {
  5274. if (timeStamp instanceof Date) {
  5275. timeStamp = timeStamp.valueOf();
  5276. }
  5277. if (typeof timeStamp !== "number") {
  5278. timeStamp = Date.now();
  5279. }
  5280. var self = this;
  5281. // Ignore event when tracking is not enabled (event might be outside of element)
  5282. if (!self.__isTracking) {
  5283. return;
  5284. }
  5285. var currentTouchLeft, currentTouchTop;
  5286. // Compute move based around of center of fingers
  5287. if (touches.length === 2) {
  5288. currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2;
  5289. currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2;
  5290. // Calculate scale when not present and only when touches are used
  5291. if (!scale && self.options.zooming) {
  5292. scale = self.__getScale(self.__initialTouches, touches);
  5293. }
  5294. } else {
  5295. currentTouchLeft = touches[0].pageX;
  5296. currentTouchTop = touches[0].pageY;
  5297. }
  5298. var positions = self.__positions;
  5299. // Are we already is dragging mode?
  5300. if (self.__isDragging) {
  5301. self.__decStopped = false;
  5302. // Compute move distance
  5303. var moveX = currentTouchLeft - self.__lastTouchLeft;
  5304. var moveY = currentTouchTop - self.__lastTouchTop;
  5305. // Read previous scroll position and zooming
  5306. var scrollLeft = self.__scrollLeft;
  5307. var scrollTop = self.__scrollTop;
  5308. var level = self.__zoomLevel;
  5309. // Work with scaling
  5310. if (scale != null && self.options.zooming) {
  5311. var oldLevel = level;
  5312. // Recompute level based on previous scale and new scale
  5313. level = level / self.__lastScale * scale;
  5314. // Limit level according to configuration
  5315. level = Math.max(Math.min(level, self.options.maxZoom), self.options.minZoom);
  5316. // Only do further compution when change happened
  5317. if (oldLevel !== level) {
  5318. // Compute relative event position to container
  5319. var currentTouchLeftRel = currentTouchLeft - self.__clientLeft;
  5320. var currentTouchTopRel = currentTouchTop - self.__clientTop;
  5321. // Recompute left and top coordinates based on new zoom level
  5322. scrollLeft = ((currentTouchLeftRel + scrollLeft) * level / oldLevel) - currentTouchLeftRel;
  5323. scrollTop = ((currentTouchTopRel + scrollTop) * level / oldLevel) - currentTouchTopRel;
  5324. // Recompute max scroll values
  5325. self.__computeScrollMax(level);
  5326. }
  5327. }
  5328. if (self.__enableScrollX) {
  5329. scrollLeft -= moveX * self.options.speedMultiplier;
  5330. var maxScrollLeft = self.__maxScrollLeft;
  5331. if (scrollLeft > maxScrollLeft || scrollLeft < 0) {
  5332. // Slow down on the edges
  5333. if (self.options.bouncing) {
  5334. scrollLeft += (moveX / 2 * self.options.speedMultiplier);
  5335. } else if (scrollLeft > maxScrollLeft) {
  5336. scrollLeft = maxScrollLeft;
  5337. } else {
  5338. scrollLeft = 0;
  5339. }
  5340. }
  5341. }
  5342. // Compute new vertical scroll position
  5343. if (self.__enableScrollY) {
  5344. scrollTop -= moveY * self.options.speedMultiplier;
  5345. var maxScrollTop = self.__maxScrollTop;
  5346. if (scrollTop > maxScrollTop || scrollTop < 0) {
  5347. // Slow down on the edges
  5348. if (self.options.bouncing || (self.__refreshHeight && scrollTop < 0)) {
  5349. scrollTop += (moveY / 2 * self.options.speedMultiplier);
  5350. // Support pull-to-refresh (only when only y is scrollable)
  5351. if (!self.__enableScrollX && self.__refreshHeight != null) {
  5352. // hide the refresher when it's behind the header bar in case of header transparency
  5353. if (scrollTop < 0) {
  5354. self.__refreshHidden = false;
  5355. self.__refreshShow();
  5356. } else {
  5357. self.__refreshHide();
  5358. self.__refreshHidden = true;
  5359. }
  5360. if (!self.__refreshActive && scrollTop <= -self.__refreshHeight) {
  5361. self.__refreshActive = true;
  5362. if (self.__refreshActivate) {
  5363. self.__refreshActivate();
  5364. }
  5365. } else if (self.__refreshActive && scrollTop > -self.__refreshHeight) {
  5366. self.__refreshActive = false;
  5367. if (self.__refreshDeactivate) {
  5368. self.__refreshDeactivate();
  5369. }
  5370. }
  5371. }
  5372. } else if (scrollTop > maxScrollTop) {
  5373. scrollTop = maxScrollTop;
  5374. } else {
  5375. scrollTop = 0;
  5376. }
  5377. } else if (self.__refreshHeight && !self.__refreshHidden) {
  5378. // if a positive scroll value and the refresher is still not hidden, hide it
  5379. self.__refreshHide();
  5380. self.__refreshHidden = true;
  5381. }
  5382. }
  5383. // Keep list from growing infinitely (holding min 10, max 20 measure points)
  5384. if (positions.length > 60) {
  5385. positions.splice(0, 30);
  5386. }
  5387. // Track scroll movement for decleration
  5388. positions.push(scrollLeft, scrollTop, timeStamp);
  5389. // Sync scroll position
  5390. self.__publish(scrollLeft, scrollTop, level);
  5391. // Otherwise figure out whether we are switching into dragging mode now.
  5392. } else {
  5393. var minimumTrackingForScroll = self.options.locking ? 3 : 0;
  5394. var minimumTrackingForDrag = 5;
  5395. var distanceX = Math.abs(currentTouchLeft - self.__initialTouchLeft);
  5396. var distanceY = Math.abs(currentTouchTop - self.__initialTouchTop);
  5397. self.__enableScrollX = self.options.scrollingX && distanceX >= minimumTrackingForScroll;
  5398. self.__enableScrollY = self.options.scrollingY && distanceY >= minimumTrackingForScroll;
  5399. positions.push(self.__scrollLeft, self.__scrollTop, timeStamp);
  5400. self.__isDragging = (self.__enableScrollX || self.__enableScrollY) && (distanceX >= minimumTrackingForDrag || distanceY >= minimumTrackingForDrag);
  5401. if (self.__isDragging) {
  5402. self.__interruptedAnimation = false;
  5403. self.__fadeScrollbars('in');
  5404. }
  5405. }
  5406. // Update last touch positions and time stamp for next event
  5407. self.__lastTouchLeft = currentTouchLeft;
  5408. self.__lastTouchTop = currentTouchTop;
  5409. self.__lastTouchMove = timeStamp;
  5410. self.__lastScale = scale;
  5411. },
  5412. /**
  5413. * Touch end handler for scrolling support
  5414. */
  5415. doTouchEnd: function(e, timeStamp) {
  5416. if (timeStamp instanceof Date) {
  5417. timeStamp = timeStamp.valueOf();
  5418. }
  5419. if (typeof timeStamp !== "number") {
  5420. timeStamp = Date.now();
  5421. }
  5422. var self = this;
  5423. // Ignore event when tracking is not enabled (no touchstart event on element)
  5424. // This is required as this listener ('touchmove') sits on the document and not on the element itself.
  5425. if (!self.__isTracking) {
  5426. return;
  5427. }
  5428. // Not touching anymore (when two finger hit the screen there are two touch end events)
  5429. self.__isTracking = false;
  5430. // Be sure to reset the dragging flag now. Here we also detect whether
  5431. // the finger has moved fast enough to switch into a deceleration animation.
  5432. if (self.__isDragging) {
  5433. // Reset dragging flag
  5434. self.__isDragging = false;
  5435. // Start deceleration
  5436. // Verify that the last move detected was in some relevant time frame
  5437. if (self.__isSingleTouch && self.options.animating && (timeStamp - self.__lastTouchMove) <= 100) {
  5438. // Then figure out what the scroll position was about 100ms ago
  5439. var positions = self.__positions;
  5440. var endPos = positions.length - 1;
  5441. var startPos = endPos;
  5442. // Move pointer to position measured 100ms ago
  5443. for (var i = endPos; i > 0 && positions[i] > (self.__lastTouchMove - 100); i -= 3) {
  5444. startPos = i;
  5445. }
  5446. // If start and stop position is identical in a 100ms timeframe,
  5447. // we cannot compute any useful deceleration.
  5448. if (startPos !== endPos) {
  5449. // Compute relative movement between these two points
  5450. var timeOffset = positions[endPos] - positions[startPos];
  5451. var movedLeft = self.__scrollLeft - positions[startPos - 2];
  5452. var movedTop = self.__scrollTop - positions[startPos - 1];
  5453. // Based on 50ms compute the movement to apply for each render step
  5454. self.__decelerationVelocityX = movedLeft / timeOffset * (1000 / 60);
  5455. self.__decelerationVelocityY = movedTop / timeOffset * (1000 / 60);
  5456. // How much velocity is required to start the deceleration
  5457. var minVelocityToStartDeceleration = self.options.paging || self.options.snapping ? self.options.decelVelocityThresholdPaging : self.options.decelVelocityThreshold;
  5458. // Verify that we have enough velocity to start deceleration
  5459. if (Math.abs(self.__decelerationVelocityX) > minVelocityToStartDeceleration || Math.abs(self.__decelerationVelocityY) > minVelocityToStartDeceleration) {
  5460. // Deactivate pull-to-refresh when decelerating
  5461. if (!self.__refreshActive) {
  5462. self.__startDeceleration(timeStamp);
  5463. }
  5464. }
  5465. } else {
  5466. self.__scrollingComplete();
  5467. }
  5468. } else if ((timeStamp - self.__lastTouchMove) > 100) {
  5469. self.__scrollingComplete();
  5470. }
  5471. } else if (self.__decStopped) {
  5472. // the deceleration was stopped
  5473. // user flicked the scroll fast, and stop dragging, then did a touchstart to stop the srolling
  5474. // tell the touchend event code to do nothing, we don't want to actually send a click
  5475. e.isTapHandled = true;
  5476. self.__decStopped = false;
  5477. }
  5478. // If this was a slower move it is per default non decelerated, but this
  5479. // still means that we want snap back to the bounds which is done here.
  5480. // This is placed outside the condition above to improve edge case stability
  5481. // e.g. touchend fired without enabled dragging. This should normally do not
  5482. // have modified the scroll positions or even showed the scrollbars though.
  5483. if (!self.__isDecelerating) {
  5484. if (self.__refreshActive && self.__refreshStart) {
  5485. // Use publish instead of scrollTo to allow scrolling to out of boundary position
  5486. // We don't need to normalize scrollLeft, zoomLevel, etc. here because we only y-scrolling when pull-to-refresh is enabled
  5487. self.__publish(self.__scrollLeft, -self.__refreshHeight, self.__zoomLevel, true);
  5488. var d = new Date();
  5489. self.refreshStartTime = d.getTime();
  5490. if (self.__refreshStart) {
  5491. self.__refreshStart();
  5492. }
  5493. // for iOS-ey style scrolling
  5494. if (!ionic.Platform.isAndroid())self.__startDeceleration();
  5495. } else {
  5496. if (self.__interruptedAnimation || self.__isDragging) {
  5497. self.__scrollingComplete();
  5498. }
  5499. self.scrollTo(self.__scrollLeft, self.__scrollTop, true, self.__zoomLevel);
  5500. // Directly signalize deactivation (nothing todo on refresh?)
  5501. if (self.__refreshActive) {
  5502. self.__refreshActive = false;
  5503. if (self.__refreshDeactivate) {
  5504. self.__refreshDeactivate();
  5505. }
  5506. }
  5507. }
  5508. }
  5509. // Fully cleanup list
  5510. self.__positions.length = 0;
  5511. },
  5512. /*
  5513. ---------------------------------------------------------------------------
  5514. PRIVATE API
  5515. ---------------------------------------------------------------------------
  5516. */
  5517. /**
  5518. * Applies the scroll position to the content element
  5519. *
  5520. * @param left {Number} Left scroll position
  5521. * @param top {Number} Top scroll position
  5522. * @param animate {Boolean} Whether animation should be used to move to the new coordinates
  5523. */
  5524. __publish: function(left, top, zoom, animate, wasResize) {
  5525. var self = this;
  5526. // Remember whether we had an animation, then we try to continue based on the current "drive" of the animation
  5527. var wasAnimating = self.__isAnimating;
  5528. if (wasAnimating) {
  5529. zyngaCore.effect.Animate.stop(wasAnimating);
  5530. self.__isAnimating = false;
  5531. }
  5532. if (animate && self.options.animating) {
  5533. // Keep scheduled positions for scrollBy/zoomBy functionality
  5534. self.__scheduledLeft = left;
  5535. self.__scheduledTop = top;
  5536. self.__scheduledZoom = zoom;
  5537. var oldLeft = self.__scrollLeft;
  5538. var oldTop = self.__scrollTop;
  5539. var oldZoom = self.__zoomLevel;
  5540. var diffLeft = left - oldLeft;
  5541. var diffTop = top - oldTop;
  5542. var diffZoom = zoom - oldZoom;
  5543. var step = function(percent, now, render) {
  5544. if (render) {
  5545. self.__scrollLeft = oldLeft + (diffLeft * percent);
  5546. self.__scrollTop = oldTop + (diffTop * percent);
  5547. self.__zoomLevel = oldZoom + (diffZoom * percent);
  5548. // Push values out
  5549. if (self.__callback) {
  5550. self.__callback(self.__scrollLeft, self.__scrollTop, self.__zoomLevel, wasResize);
  5551. }
  5552. }
  5553. };
  5554. var verify = function(id) {
  5555. return self.__isAnimating === id;
  5556. };
  5557. var completed = function(renderedFramesPerSecond, animationId, wasFinished) {
  5558. if (animationId === self.__isAnimating) {
  5559. self.__isAnimating = false;
  5560. }
  5561. if (self.__didDecelerationComplete || wasFinished) {
  5562. self.__scrollingComplete();
  5563. }
  5564. if (self.options.zooming) {
  5565. self.__computeScrollMax();
  5566. }
  5567. };
  5568. // When continuing based on previous animation we choose an ease-out animation instead of ease-in-out
  5569. self.__isAnimating = zyngaCore.effect.Animate.start(step, verify, completed, self.options.animationDuration, wasAnimating ? easeOutCubic : easeInOutCubic);
  5570. } else {
  5571. self.__scheduledLeft = self.__scrollLeft = left;
  5572. self.__scheduledTop = self.__scrollTop = top;
  5573. self.__scheduledZoom = self.__zoomLevel = zoom;
  5574. // Push values out
  5575. if (self.__callback) {
  5576. self.__callback(left, top, zoom, wasResize);
  5577. }
  5578. // Fix max scroll ranges
  5579. if (self.options.zooming) {
  5580. self.__computeScrollMax();
  5581. }
  5582. }
  5583. },
  5584. /**
  5585. * Recomputes scroll minimum values based on client dimensions and content dimensions.
  5586. */
  5587. __computeScrollMax: function(zoomLevel) {
  5588. var self = this;
  5589. if (zoomLevel == null) {
  5590. zoomLevel = self.__zoomLevel;
  5591. }
  5592. self.__maxScrollLeft = Math.max((self.__contentWidth * zoomLevel) - self.__clientWidth, 0);
  5593. self.__maxScrollTop = Math.max((self.__contentHeight * zoomLevel) - self.__clientHeight, 0);
  5594. if (!self.__didWaitForSize && !self.__maxScrollLeft && !self.__maxScrollTop) {
  5595. self.__didWaitForSize = true;
  5596. self.__waitForSize();
  5597. }
  5598. },
  5599. /**
  5600. * If the scroll view isn't sized correctly on start, wait until we have at least some size
  5601. */
  5602. __waitForSize: function() {
  5603. var self = this;
  5604. clearTimeout(self.__sizerTimeout);
  5605. var sizer = function() {
  5606. self.resize(true);
  5607. };
  5608. sizer();
  5609. self.__sizerTimeout = setTimeout(sizer, 500);
  5610. },
  5611. /*
  5612. ---------------------------------------------------------------------------
  5613. ANIMATION (DECELERATION) SUPPORT
  5614. ---------------------------------------------------------------------------
  5615. */
  5616. /**
  5617. * Called when a touch sequence end and the speed of the finger was high enough
  5618. * to switch into deceleration mode.
  5619. */
  5620. __startDeceleration: function() {
  5621. var self = this;
  5622. if (self.options.paging) {
  5623. var scrollLeft = Math.max(Math.min(self.__scrollLeft, self.__maxScrollLeft), 0);
  5624. var scrollTop = Math.max(Math.min(self.__scrollTop, self.__maxScrollTop), 0);
  5625. var clientWidth = self.__clientWidth;
  5626. var clientHeight = self.__clientHeight;
  5627. // We limit deceleration not to the min/max values of the allowed range, but to the size of the visible client area.
  5628. // Each page should have exactly the size of the client area.
  5629. self.__minDecelerationScrollLeft = Math.floor(scrollLeft / clientWidth) * clientWidth;
  5630. self.__minDecelerationScrollTop = Math.floor(scrollTop / clientHeight) * clientHeight;
  5631. self.__maxDecelerationScrollLeft = Math.ceil(scrollLeft / clientWidth) * clientWidth;
  5632. self.__maxDecelerationScrollTop = Math.ceil(scrollTop / clientHeight) * clientHeight;
  5633. } else {
  5634. self.__minDecelerationScrollLeft = 0;
  5635. self.__minDecelerationScrollTop = 0;
  5636. self.__maxDecelerationScrollLeft = self.__maxScrollLeft;
  5637. self.__maxDecelerationScrollTop = self.__maxScrollTop;
  5638. if (self.__refreshActive) self.__minDecelerationScrollTop = self.__refreshHeight * -1;
  5639. }
  5640. // Wrap class method
  5641. var step = function(percent, now, render) {
  5642. self.__stepThroughDeceleration(render);
  5643. };
  5644. // How much velocity is required to keep the deceleration running
  5645. self.__minVelocityToKeepDecelerating = self.options.snapping ? 4 : 0.1;
  5646. // Detect whether it's still worth to continue animating steps
  5647. // If we are already slow enough to not being user perceivable anymore, we stop the whole process here.
  5648. var verify = function() {
  5649. var shouldContinue = Math.abs(self.__decelerationVelocityX) >= self.__minVelocityToKeepDecelerating ||
  5650. Math.abs(self.__decelerationVelocityY) >= self.__minVelocityToKeepDecelerating;
  5651. if (!shouldContinue) {
  5652. self.__didDecelerationComplete = true;
  5653. //Make sure the scroll values are within the boundaries after a bounce,
  5654. //not below 0 or above maximum
  5655. if (self.options.bouncing && !self.__refreshActive) {
  5656. self.scrollTo(
  5657. Math.min( Math.max(self.__scrollLeft, 0), self.__maxScrollLeft ),
  5658. Math.min( Math.max(self.__scrollTop, 0), self.__maxScrollTop ),
  5659. self.__refreshActive
  5660. );
  5661. }
  5662. }
  5663. return shouldContinue;
  5664. };
  5665. var completed = function() {
  5666. self.__isDecelerating = false;
  5667. if (self.__didDecelerationComplete) {
  5668. self.__scrollingComplete();
  5669. }
  5670. // Animate to grid when snapping is active, otherwise just fix out-of-boundary positions
  5671. if (self.options.paging) {
  5672. self.scrollTo(self.__scrollLeft, self.__scrollTop, self.options.snapping);
  5673. }
  5674. };
  5675. // Start animation and switch on flag
  5676. self.__isDecelerating = zyngaCore.effect.Animate.start(step, verify, completed);
  5677. },
  5678. /**
  5679. * Called on every step of the animation
  5680. *
  5681. * @param inMemory {Boolean} Whether to not render the current step, but keep it in memory only. Used internally only!
  5682. */
  5683. __stepThroughDeceleration: function(render) {
  5684. var self = this;
  5685. //
  5686. // COMPUTE NEXT SCROLL POSITION
  5687. //
  5688. // Add deceleration to scroll position
  5689. var scrollLeft = self.__scrollLeft + self.__decelerationVelocityX;// * self.options.deceleration);
  5690. var scrollTop = self.__scrollTop + self.__decelerationVelocityY;// * self.options.deceleration);
  5691. //
  5692. // HARD LIMIT SCROLL POSITION FOR NON BOUNCING MODE
  5693. //
  5694. if (!self.options.bouncing) {
  5695. var scrollLeftFixed = Math.max(Math.min(self.__maxDecelerationScrollLeft, scrollLeft), self.__minDecelerationScrollLeft);
  5696. if (scrollLeftFixed !== scrollLeft) {
  5697. scrollLeft = scrollLeftFixed;
  5698. self.__decelerationVelocityX = 0;
  5699. }
  5700. var scrollTopFixed = Math.max(Math.min(self.__maxDecelerationScrollTop, scrollTop), self.__minDecelerationScrollTop);
  5701. if (scrollTopFixed !== scrollTop) {
  5702. scrollTop = scrollTopFixed;
  5703. self.__decelerationVelocityY = 0;
  5704. }
  5705. }
  5706. //
  5707. // UPDATE SCROLL POSITION
  5708. //
  5709. if (render) {
  5710. self.__publish(scrollLeft, scrollTop, self.__zoomLevel);
  5711. } else {
  5712. self.__scrollLeft = scrollLeft;
  5713. self.__scrollTop = scrollTop;
  5714. }
  5715. //
  5716. // SLOW DOWN
  5717. //
  5718. // Slow down velocity on every iteration
  5719. if (!self.options.paging) {
  5720. // This is the factor applied to every iteration of the animation
  5721. // to slow down the process. This should emulate natural behavior where
  5722. // objects slow down when the initiator of the movement is removed
  5723. var frictionFactor = self.options.deceleration;
  5724. self.__decelerationVelocityX *= frictionFactor;
  5725. self.__decelerationVelocityY *= frictionFactor;
  5726. }
  5727. //
  5728. // BOUNCING SUPPORT
  5729. //
  5730. if (self.options.bouncing) {
  5731. var scrollOutsideX = 0;
  5732. var scrollOutsideY = 0;
  5733. // This configures the amount of change applied to deceleration/acceleration when reaching boundaries
  5734. var penetrationDeceleration = self.options.penetrationDeceleration;
  5735. var penetrationAcceleration = self.options.penetrationAcceleration;
  5736. // Check limits
  5737. if (scrollLeft < self.__minDecelerationScrollLeft) {
  5738. scrollOutsideX = self.__minDecelerationScrollLeft - scrollLeft;
  5739. } else if (scrollLeft > self.__maxDecelerationScrollLeft) {
  5740. scrollOutsideX = self.__maxDecelerationScrollLeft - scrollLeft;
  5741. }
  5742. if (scrollTop < self.__minDecelerationScrollTop) {
  5743. scrollOutsideY = self.__minDecelerationScrollTop - scrollTop;
  5744. } else if (scrollTop > self.__maxDecelerationScrollTop) {
  5745. scrollOutsideY = self.__maxDecelerationScrollTop - scrollTop;
  5746. }
  5747. // Slow down until slow enough, then flip back to snap position
  5748. if (scrollOutsideX !== 0) {
  5749. var isHeadingOutwardsX = scrollOutsideX * self.__decelerationVelocityX <= self.__minDecelerationScrollLeft;
  5750. if (isHeadingOutwardsX) {
  5751. self.__decelerationVelocityX += scrollOutsideX * penetrationDeceleration;
  5752. }
  5753. var isStoppedX = Math.abs(self.__decelerationVelocityX) <= self.__minVelocityToKeepDecelerating;
  5754. //If we're not heading outwards, or if the above statement got us below minDeceleration, go back towards bounds
  5755. if (!isHeadingOutwardsX || isStoppedX) {
  5756. self.__decelerationVelocityX = scrollOutsideX * penetrationAcceleration;
  5757. }
  5758. }
  5759. if (scrollOutsideY !== 0) {
  5760. var isHeadingOutwardsY = scrollOutsideY * self.__decelerationVelocityY <= self.__minDecelerationScrollTop;
  5761. if (isHeadingOutwardsY) {
  5762. self.__decelerationVelocityY += scrollOutsideY * penetrationDeceleration;
  5763. }
  5764. var isStoppedY = Math.abs(self.__decelerationVelocityY) <= self.__minVelocityToKeepDecelerating;
  5765. //If we're not heading outwards, or if the above statement got us below minDeceleration, go back towards bounds
  5766. if (!isHeadingOutwardsY || isStoppedY) {
  5767. self.__decelerationVelocityY = scrollOutsideY * penetrationAcceleration;
  5768. }
  5769. }
  5770. }
  5771. },
  5772. /**
  5773. * calculate the distance between two touches
  5774. * @param {Touch} touch1
  5775. * @param {Touch} touch2
  5776. * @returns {Number} distance
  5777. */
  5778. __getDistance: function getDistance(touch1, touch2) {
  5779. var x = touch2.pageX - touch1.pageX,
  5780. y = touch2.pageY - touch1.pageY;
  5781. return Math.sqrt((x * x) + (y * y));
  5782. },
  5783. /**
  5784. * calculate the scale factor between two touchLists (fingers)
  5785. * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
  5786. * @param {Array} start
  5787. * @param {Array} end
  5788. * @returns {Number} scale
  5789. */
  5790. __getScale: function getScale(start, end) {
  5791. // need two fingers...
  5792. if (start.length >= 2 && end.length >= 2) {
  5793. return this.__getDistance(end[0], end[1]) /
  5794. this.__getDistance(start[0], start[1]);
  5795. }
  5796. return 1;
  5797. }
  5798. });
  5799. ionic.scroll = {
  5800. isScrolling: false,
  5801. lastTop: 0
  5802. };
  5803. })(ionic);
  5804. (function(ionic) {
  5805. var NOOP = function() {};
  5806. var deprecated = function(name) {
  5807. void 0;
  5808. };
  5809. ionic.views.ScrollNative = ionic.views.View.inherit({
  5810. initialize: function(options) {
  5811. var self = this;
  5812. self.__container = self.el = options.el;
  5813. self.__content = options.el.firstElementChild;
  5814. // Whether scrolling is frozen or not
  5815. self.__frozen = false;
  5816. self.isNative = true;
  5817. self.__scrollTop = self.el.scrollTop;
  5818. self.__scrollLeft = self.el.scrollLeft;
  5819. self.__clientHeight = self.__content.clientHeight;
  5820. self.__clientWidth = self.__content.clientWidth;
  5821. self.__maxScrollTop = Math.max((self.__contentHeight) - self.__clientHeight, 0);
  5822. self.__maxScrollLeft = Math.max((self.__contentWidth) - self.__clientWidth, 0);
  5823. if(options.startY >= 0 || options.startX >= 0) {
  5824. ionic.requestAnimationFrame(function() {
  5825. self.el.scrollTop = options.startY || 0;
  5826. self.el.scrollLeft = options.startX || 0;
  5827. self.__scrollTop = self.el.scrollTop;
  5828. self.__scrollLeft = self.el.scrollLeft;
  5829. });
  5830. }
  5831. self.options = {
  5832. freeze: false,
  5833. getContentWidth: function() {
  5834. return Math.max(self.__content.scrollWidth, self.__content.offsetWidth);
  5835. },
  5836. getContentHeight: function() {
  5837. return Math.max(self.__content.scrollHeight, self.__content.offsetHeight + (self.__content.offsetTop * 2));
  5838. }
  5839. };
  5840. for (var key in options) {
  5841. self.options[key] = options[key];
  5842. }
  5843. /**
  5844. * Sets isScrolling to true, and automatically deactivates if not called again in 80ms.
  5845. */
  5846. self.onScroll = function() {
  5847. if (!ionic.scroll.isScrolling) {
  5848. ionic.scroll.isScrolling = true;
  5849. }
  5850. clearTimeout(self.scrollTimer);
  5851. self.scrollTimer = setTimeout(function() {
  5852. ionic.scroll.isScrolling = false;
  5853. }, 80);
  5854. };
  5855. self.freeze = function(shouldFreeze) {
  5856. self.__frozen = shouldFreeze;
  5857. };
  5858. // A more powerful freeze pop that dominates all other freeze pops
  5859. self.freezeShut = function(shouldFreezeShut) {
  5860. self.__frozenShut = shouldFreezeShut;
  5861. };
  5862. self.__initEventHandlers();
  5863. },
  5864. /** Methods not used in native scrolling */
  5865. __callback: function() { deprecated('__callback'); },
  5866. zoomTo: function() { deprecated('zoomTo'); },
  5867. zoomBy: function() { deprecated('zoomBy'); },
  5868. activatePullToRefresh: function() { deprecated('activatePullToRefresh'); },
  5869. /**
  5870. * Returns the scroll position and zooming values
  5871. *
  5872. * @return {Map} `left` and `top` scroll position and `zoom` level
  5873. */
  5874. resize: function(continueScrolling) {
  5875. var self = this;
  5876. if (!self.__container || !self.options) return;
  5877. // Update Scroller dimensions for changed content
  5878. // Add padding to bottom of content
  5879. self.setDimensions(
  5880. self.__container.clientWidth,
  5881. self.__container.clientHeight,
  5882. self.options.getContentWidth(),
  5883. self.options.getContentHeight(),
  5884. continueScrolling
  5885. );
  5886. },
  5887. /**
  5888. * Initialize the scrollview
  5889. * In native scrolling, this only means we need to gather size information
  5890. */
  5891. run: function() {
  5892. this.resize();
  5893. },
  5894. /**
  5895. * Returns the scroll position and zooming values
  5896. *
  5897. * @return {Map} `left` and `top` scroll position and `zoom` level
  5898. */
  5899. getValues: function() {
  5900. var self = this;
  5901. self.update();
  5902. return {
  5903. left: self.__scrollLeft,
  5904. top: self.__scrollTop,
  5905. zoom: 1
  5906. };
  5907. },
  5908. /**
  5909. * Updates the __scrollLeft and __scrollTop values to el's current value
  5910. */
  5911. update: function() {
  5912. var self = this;
  5913. self.__scrollLeft = self.el.scrollLeft;
  5914. self.__scrollTop = self.el.scrollTop;
  5915. },
  5916. /**
  5917. * Configures the dimensions of the client (outer) and content (inner) elements.
  5918. * Requires the available space for the outer element and the outer size of the inner element.
  5919. * All values which are falsy (null or zero etc.) are ignored and the old value is kept.
  5920. *
  5921. * @param clientWidth {Integer} Inner width of outer element
  5922. * @param clientHeight {Integer} Inner height of outer element
  5923. * @param contentWidth {Integer} Outer width of inner element
  5924. * @param contentHeight {Integer} Outer height of inner element
  5925. */
  5926. setDimensions: function(clientWidth, clientHeight, contentWidth, contentHeight) {
  5927. var self = this;
  5928. if (!clientWidth && !clientHeight && !contentWidth && !contentHeight) {
  5929. // this scrollview isn't rendered, don't bother
  5930. return;
  5931. }
  5932. // Only update values which are defined
  5933. if (clientWidth === +clientWidth) {
  5934. self.__clientWidth = clientWidth;
  5935. }
  5936. if (clientHeight === +clientHeight) {
  5937. self.__clientHeight = clientHeight;
  5938. }
  5939. if (contentWidth === +contentWidth) {
  5940. self.__contentWidth = contentWidth;
  5941. }
  5942. if (contentHeight === +contentHeight) {
  5943. self.__contentHeight = contentHeight;
  5944. }
  5945. // Refresh maximums
  5946. self.__computeScrollMax();
  5947. },
  5948. /**
  5949. * Returns the maximum scroll values
  5950. *
  5951. * @return {Map} `left` and `top` maximum scroll values
  5952. */
  5953. getScrollMax: function() {
  5954. return {
  5955. left: this.__maxScrollLeft,
  5956. top: this.__maxScrollTop
  5957. };
  5958. },
  5959. /**
  5960. * Scrolls by the given amount in px.
  5961. *
  5962. * @param left {Number} Horizontal scroll position, keeps current if value is <code>null</code>
  5963. * @param top {Number} Vertical scroll position, keeps current if value is <code>null</code>
  5964. * @param animate {Boolean} Whether the scrolling should happen using an animation
  5965. */
  5966. scrollBy: function(left, top, animate) {
  5967. var self = this;
  5968. // update scroll vars before refferencing them
  5969. self.update();
  5970. var startLeft = self.__isAnimating ? self.__scheduledLeft : self.__scrollLeft;
  5971. var startTop = self.__isAnimating ? self.__scheduledTop : self.__scrollTop;
  5972. self.scrollTo(startLeft + (left || 0), startTop + (top || 0), animate);
  5973. },
  5974. /**
  5975. * Scrolls to the given position in px.
  5976. *
  5977. * @param left {Number} Horizontal scroll position, keeps current if value is <code>null</code>
  5978. * @param top {Number} Vertical scroll position, keeps current if value is <code>null</code>
  5979. * @param animate {Boolean} Whether the scrolling should happen using an animation
  5980. */
  5981. scrollTo: function(left, top, animate) {
  5982. var self = this;
  5983. if (!animate) {
  5984. self.el.scrollTop = top;
  5985. self.el.scrollLeft = left;
  5986. self.resize();
  5987. return;
  5988. }
  5989. var oldOverflowX = self.el.style.overflowX;
  5990. var oldOverflowY = self.el.style.overflowY;
  5991. clearTimeout(self.__scrollToCleanupTimeout);
  5992. self.__scrollToCleanupTimeout = setTimeout(function() {
  5993. self.el.style.overflowX = oldOverflowX;
  5994. self.el.style.overflowY = oldOverflowY;
  5995. }, 500);
  5996. self.el.style.overflowY = 'hidden';
  5997. self.el.style.overflowX = 'hidden';
  5998. animateScroll(top, left);
  5999. function animateScroll(Y, X) {
  6000. // scroll animation loop w/ easing
  6001. // credit https://gist.github.com/dezinezync/5487119
  6002. var start = Date.now(),
  6003. duration = 250, //milliseconds
  6004. fromY = self.el.scrollTop,
  6005. fromX = self.el.scrollLeft;
  6006. if (fromY === Y && fromX === X) {
  6007. self.el.style.overflowX = oldOverflowX;
  6008. self.el.style.overflowY = oldOverflowY;
  6009. self.resize();
  6010. return; /* Prevent scrolling to the Y point if already there */
  6011. }
  6012. // decelerating to zero velocity
  6013. function easeOutCubic(t) {
  6014. return (--t) * t * t + 1;
  6015. }
  6016. // scroll loop
  6017. function animateScrollStep() {
  6018. var currentTime = Date.now(),
  6019. time = Math.min(1, ((currentTime - start) / duration)),
  6020. // where .5 would be 50% of time on a linear scale easedT gives a
  6021. // fraction based on the easing method
  6022. easedT = easeOutCubic(time);
  6023. if (fromY != Y) {
  6024. self.el.scrollTop = parseInt((easedT * (Y - fromY)) + fromY, 10);
  6025. }
  6026. if (fromX != X) {
  6027. self.el.scrollLeft = parseInt((easedT * (X - fromX)) + fromX, 10);
  6028. }
  6029. if (time < 1) {
  6030. ionic.requestAnimationFrame(animateScrollStep);
  6031. } else {
  6032. // done
  6033. ionic.tap.removeClonedInputs(self.__container, self);
  6034. self.el.style.overflowX = oldOverflowX;
  6035. self.el.style.overflowY = oldOverflowY;
  6036. self.resize();
  6037. }
  6038. }
  6039. // start scroll loop
  6040. ionic.requestAnimationFrame(animateScrollStep);
  6041. }
  6042. },
  6043. /*
  6044. ---------------------------------------------------------------------------
  6045. PRIVATE API
  6046. ---------------------------------------------------------------------------
  6047. */
  6048. /**
  6049. * If the scroll view isn't sized correctly on start, wait until we have at least some size
  6050. */
  6051. __waitForSize: function() {
  6052. var self = this;
  6053. clearTimeout(self.__sizerTimeout);
  6054. var sizer = function() {
  6055. self.resize(true);
  6056. };
  6057. sizer();
  6058. self.__sizerTimeout = setTimeout(sizer, 500);
  6059. },
  6060. /**
  6061. * Recomputes scroll minimum values based on client dimensions and content dimensions.
  6062. */
  6063. __computeScrollMax: function() {
  6064. var self = this;
  6065. self.__maxScrollLeft = Math.max((self.__contentWidth) - self.__clientWidth, 0);
  6066. self.__maxScrollTop = Math.max((self.__contentHeight) - self.__clientHeight, 0);
  6067. if (!self.__didWaitForSize && !self.__maxScrollLeft && !self.__maxScrollTop) {
  6068. self.__didWaitForSize = true;
  6069. self.__waitForSize();
  6070. }
  6071. },
  6072. __initEventHandlers: function() {
  6073. var self = this;
  6074. // Event Handler
  6075. var container = self.__container;
  6076. // save height when scroll view is shrunk so we don't need to reflow
  6077. var scrollViewOffsetHeight;
  6078. var lastKeyboardHeight;
  6079. /**
  6080. * Shrink the scroll view when the keyboard is up if necessary and if the
  6081. * focused input is below the bottom of the shrunk scroll view, scroll it
  6082. * into view.
  6083. */
  6084. self.scrollChildIntoView = function(e) {
  6085. var rect = container.getBoundingClientRect();
  6086. if(!self.__originalContainerHeight) {
  6087. self.__originalContainerHeight = rect.height;
  6088. }
  6089. // D
  6090. //var scrollBottomOffsetToTop = rect.bottom;
  6091. // D - A
  6092. scrollViewOffsetHeight = self.__originalContainerHeight;
  6093. //console.log('Scroll view offset height', scrollViewOffsetHeight);
  6094. //console.dir(container);
  6095. var alreadyShrunk = self.isShrunkForKeyboard;
  6096. var isModal = container.parentNode.classList.contains('modal');
  6097. var isPopover = container.parentNode.classList.contains('popover');
  6098. // 680px is when the media query for 60% modal width kicks in
  6099. var isInsetModal = isModal && window.innerWidth >= 680;
  6100. /*
  6101. * _______
  6102. * |---A---| <- top of scroll view
  6103. * | |
  6104. * |---B---| <- keyboard
  6105. * | C | <- input
  6106. * |---D---| <- initial bottom of scroll view
  6107. * |___E___| <- bottom of viewport
  6108. *
  6109. * All commented calculations relative to the top of the viewport (ie E
  6110. * is the viewport height, not 0)
  6111. */
  6112. var changedKeyboardHeight = lastKeyboardHeight && (lastKeyboardHeight !== e.detail.keyboardHeight);
  6113. if (!alreadyShrunk || changedKeyboardHeight) {
  6114. // shrink scrollview so we can actually scroll if the input is hidden
  6115. // if it isn't shrink so we can scroll to inputs under the keyboard
  6116. // inset modals won't shrink on Android on their own when the keyboard appears
  6117. if ( !isPopover && (ionic.Platform.isIOS() || ionic.Platform.isFullScreen || isInsetModal) ) {
  6118. // if there are things below the scroll view account for them and
  6119. // subtract them from the keyboard height when resizing
  6120. // E - D E D
  6121. //var scrollBottomOffsetToBottom = e.detail.viewportHeight - scrollBottomOffsetToTop;
  6122. // 0 or D - B if D > B E - B E - D
  6123. //var keyboardOffset = e.detail.keyboardHeight - scrollBottomOffsetToBottom;
  6124. ionic.requestAnimationFrame(function(){
  6125. // D - A or B - A if D > B D - A max(0, D - B)
  6126. scrollViewOffsetHeight = Math.max(0, Math.min(self.__originalContainerHeight, self.__originalContainerHeight - (e.detail.keyboardHeight - 43)));//keyboardOffset >= 0 ? scrollViewOffsetHeight - keyboardOffset : scrollViewOffsetHeight + keyboardOffset;
  6127. //console.log('Old container height', self.__originalContainerHeight, 'New container height', scrollViewOffsetHeight, 'Keyboard height', e.detail.keyboardHeight);
  6128. container.style.height = scrollViewOffsetHeight + "px";
  6129. /*
  6130. if (ionic.Platform.isIOS()) {
  6131. // Force redraw to avoid disappearing content
  6132. var disp = container.style.display;
  6133. container.style.display = 'none';
  6134. var trick = container.offsetHeight;
  6135. container.style.display = disp;
  6136. }
  6137. */
  6138. container.classList.add('keyboard-up');
  6139. //update scroll view
  6140. self.resize();
  6141. });
  6142. }
  6143. self.isShrunkForKeyboard = true;
  6144. }
  6145. lastKeyboardHeight = e.detail.keyboardHeight;
  6146. /*
  6147. * _______
  6148. * |---A---| <- top of scroll view
  6149. * | * | <- where we want to scroll to
  6150. * |--B-D--| <- keyboard, bottom of scroll view
  6151. * | C | <- input
  6152. * | |
  6153. * |___E___| <- bottom of viewport
  6154. *
  6155. * All commented calculations relative to the top of the viewport (ie E
  6156. * is the viewport height, not 0)
  6157. */
  6158. // if the element is positioned under the keyboard scroll it into view
  6159. if (e.detail.isElementUnderKeyboard) {
  6160. ionic.requestAnimationFrame(function(){
  6161. var pos = ionic.DomUtil.getOffsetTop(e.detail.target);
  6162. setTimeout(function() {
  6163. if (ionic.Platform.isIOS()) {
  6164. ionic.tap.cloneFocusedInput(container, self);
  6165. }
  6166. // Scroll the input into view, with a 100px buffer
  6167. self.scrollTo(0, pos - (rect.top + 100), true);
  6168. self.onScroll();
  6169. }, 32);
  6170. /*
  6171. // update D if we shrunk
  6172. if (self.isShrunkForKeyboard && !alreadyShrunk) {
  6173. scrollBottomOffsetToTop = container.getBoundingClientRect().bottom;
  6174. console.log('Scroll bottom', scrollBottomOffsetToTop);
  6175. }
  6176. // middle of the scrollview, this is where we want to scroll to
  6177. // (D - A) / 2
  6178. var scrollMidpointOffset = scrollViewOffsetHeight * 0.5;
  6179. console.log('Midpoint', scrollMidpointOffset);
  6180. //console.log("container.offsetHeight: " + scrollViewOffsetHeight);
  6181. // middle of the input we want to scroll into view
  6182. // C
  6183. var inputMidpoint = ((e.detail.elementBottom + e.detail.elementTop) / 2);
  6184. console.log('Input midpoint');
  6185. // distance from middle of input to the bottom of the scroll view
  6186. // C - D C D
  6187. var inputMidpointOffsetToScrollBottom = inputMidpoint - scrollBottomOffsetToTop;
  6188. console.log('Input midpoint offset', inputMidpointOffsetToScrollBottom);
  6189. //C - D + (D - A)/2 C - D (D - A)/ 2
  6190. var scrollTop = inputMidpointOffsetToScrollBottom + scrollMidpointOffset;
  6191. console.log('Scroll top', scrollTop);
  6192. if ( scrollTop > 0) {
  6193. if (ionic.Platform.isIOS()) {
  6194. //just shrank scroll view, give it some breathing room before scrolling
  6195. setTimeout(function(){
  6196. ionic.tap.cloneFocusedInput(container, self);
  6197. self.scrollBy(0, scrollTop, true);
  6198. self.onScroll();
  6199. }, 32);
  6200. } else {
  6201. self.scrollBy(0, scrollTop, true);
  6202. self.onScroll();
  6203. }
  6204. }
  6205. */
  6206. });
  6207. }
  6208. // Only the first scrollView parent of the element that broadcasted this event
  6209. // (the active element that needs to be shown) should receive this event
  6210. e.stopPropagation();
  6211. };
  6212. self.resetScrollView = function() {
  6213. //return scrollview to original height once keyboard has hidden
  6214. if (self.isShrunkForKeyboard) {
  6215. self.isShrunkForKeyboard = false;
  6216. container.style.height = "";
  6217. /*
  6218. if (ionic.Platform.isIOS()) {
  6219. // Force redraw to avoid disappearing content
  6220. var disp = container.style.display;
  6221. container.style.display = 'none';
  6222. var trick = container.offsetHeight;
  6223. container.style.display = disp;
  6224. }
  6225. */
  6226. self.__originalContainerHeight = container.getBoundingClientRect().height;
  6227. if (ionic.Platform.isIOS()) {
  6228. ionic.requestAnimationFrame(function() {
  6229. container.classList.remove('keyboard-up');
  6230. });
  6231. }
  6232. }
  6233. self.resize();
  6234. };
  6235. self.handleTouchMove = function(e) {
  6236. if (self.__frozenShut) {
  6237. e.preventDefault();
  6238. e.stopPropagation();
  6239. return false;
  6240. } else if ( self.__frozen ){
  6241. e.preventDefault();
  6242. // let it propagate so other events such as drag events can happen,
  6243. // but don't let it actually scroll
  6244. return false;
  6245. }
  6246. return true;
  6247. };
  6248. container.addEventListener('scroll', self.onScroll);
  6249. //Broadcasted when keyboard is shown on some platforms.
  6250. //See js/utils/keyboard.js
  6251. container.addEventListener('scrollChildIntoView', self.scrollChildIntoView);
  6252. container.addEventListener(ionic.EVENTS.touchstart, self.handleTouchMove);
  6253. container.addEventListener(ionic.EVENTS.touchmove, self.handleTouchMove);
  6254. // Listen on document because container may not have had the last
  6255. // keyboardActiveElement, for example after closing a modal with a focused
  6256. // input and returning to a previously resized scroll view in an ion-content.
  6257. // Since we can only resize scroll views that are currently visible, just resize
  6258. // the current scroll view when the keyboard is closed.
  6259. document.addEventListener('resetScrollView', self.resetScrollView);
  6260. },
  6261. __cleanup: function() {
  6262. var self = this;
  6263. var container = self.__container;
  6264. container.removeEventListener('resetScrollView', self.resetScrollView);
  6265. container.removeEventListener('scroll', self.onScroll);
  6266. container.removeEventListener('scrollChildIntoView', self.scrollChildIntoView);
  6267. container.removeEventListener('resetScrollView', self.resetScrollView);
  6268. container.removeEventListener(ionic.EVENTS.touchstart, self.handleTouchMove);
  6269. container.removeEventListener(ionic.EVENTS.touchmove, self.handleTouchMove);
  6270. ionic.tap.removeClonedInputs(container, self);
  6271. delete self.__container;
  6272. delete self.__content;
  6273. delete self.__indicatorX;
  6274. delete self.__indicatorY;
  6275. delete self.options.el;
  6276. self.resize = self.scrollTo = self.onScroll = self.resetScrollView = NOOP;
  6277. self.scrollChildIntoView = NOOP;
  6278. container = null;
  6279. }
  6280. });
  6281. })(ionic);
  6282. (function(ionic) {
  6283. 'use strict';
  6284. var ITEM_CLASS = 'item';
  6285. var ITEM_CONTENT_CLASS = 'item-content';
  6286. var ITEM_SLIDING_CLASS = 'item-sliding';
  6287. var ITEM_OPTIONS_CLASS = 'item-options';
  6288. var ITEM_PLACEHOLDER_CLASS = 'item-placeholder';
  6289. var ITEM_REORDERING_CLASS = 'item-reordering';
  6290. var ITEM_REORDER_BTN_CLASS = 'item-reorder';
  6291. var DragOp = function() {};
  6292. DragOp.prototype = {
  6293. start: function(){},
  6294. drag: function(){},
  6295. end: function(){},
  6296. isSameItem: function() {
  6297. return false;
  6298. }
  6299. };
  6300. var SlideDrag = function(opts) {
  6301. this.dragThresholdX = opts.dragThresholdX || 10;
  6302. this.el = opts.el;
  6303. this.item = opts.item;
  6304. this.canSwipe = opts.canSwipe;
  6305. };
  6306. SlideDrag.prototype = new DragOp();
  6307. SlideDrag.prototype.start = function(e) {
  6308. var content, buttons, offsetX, buttonsWidth;
  6309. if (!this.canSwipe()) {
  6310. return;
  6311. }
  6312. if (e.target.classList.contains(ITEM_CONTENT_CLASS)) {
  6313. content = e.target;
  6314. } else if (e.target.classList.contains(ITEM_CLASS)) {
  6315. content = e.target.querySelector('.' + ITEM_CONTENT_CLASS);
  6316. } else {
  6317. content = ionic.DomUtil.getParentWithClass(e.target, ITEM_CONTENT_CLASS);
  6318. }
  6319. // If we don't have a content area as one of our children (or ourselves), skip
  6320. if (!content) {
  6321. return;
  6322. }
  6323. // Make sure we aren't animating as we slide
  6324. content.classList.remove(ITEM_SLIDING_CLASS);
  6325. // Grab the starting X point for the item (for example, so we can tell whether it is open or closed to start)
  6326. offsetX = parseFloat(content.style[ionic.CSS.TRANSFORM].replace('translate3d(', '').split(',')[0]) || 0;
  6327. // Grab the buttons
  6328. buttons = content.parentNode.querySelector('.' + ITEM_OPTIONS_CLASS);
  6329. if (!buttons) {
  6330. return;
  6331. }
  6332. buttons.classList.remove('invisible');
  6333. buttonsWidth = buttons.offsetWidth;
  6334. this._currentDrag = {
  6335. buttons: buttons,
  6336. buttonsWidth: buttonsWidth,
  6337. content: content,
  6338. startOffsetX: offsetX
  6339. };
  6340. };
  6341. /**
  6342. * Check if this is the same item that was previously dragged.
  6343. */
  6344. SlideDrag.prototype.isSameItem = function(op) {
  6345. if (op._lastDrag && this._currentDrag) {
  6346. return this._currentDrag.content == op._lastDrag.content;
  6347. }
  6348. return false;
  6349. };
  6350. SlideDrag.prototype.clean = function(isInstant) {
  6351. var lastDrag = this._lastDrag;
  6352. if (!lastDrag || !lastDrag.content) return;
  6353. lastDrag.content.style[ionic.CSS.TRANSITION] = '';
  6354. lastDrag.content.style[ionic.CSS.TRANSFORM] = '';
  6355. if (isInstant) {
  6356. lastDrag.content.style[ionic.CSS.TRANSITION] = 'none';
  6357. makeInvisible();
  6358. ionic.requestAnimationFrame(function() {
  6359. lastDrag.content.style[ionic.CSS.TRANSITION] = '';
  6360. });
  6361. } else {
  6362. ionic.requestAnimationFrame(function() {
  6363. setTimeout(makeInvisible, 250);
  6364. });
  6365. }
  6366. function makeInvisible() {
  6367. lastDrag.buttons && lastDrag.buttons.classList.add('invisible');
  6368. }
  6369. };
  6370. SlideDrag.prototype.drag = ionic.animationFrameThrottle(function(e) {
  6371. var buttonsWidth;
  6372. // We really aren't dragging
  6373. if (!this._currentDrag) {
  6374. return;
  6375. }
  6376. // Check if we should start dragging. Check if we've dragged past the threshold,
  6377. // or we are starting from the open state.
  6378. if (!this._isDragging &&
  6379. ((Math.abs(e.gesture.deltaX) > this.dragThresholdX) ||
  6380. (Math.abs(this._currentDrag.startOffsetX) > 0))) {
  6381. this._isDragging = true;
  6382. }
  6383. if (this._isDragging) {
  6384. buttonsWidth = this._currentDrag.buttonsWidth;
  6385. // Grab the new X point, capping it at zero
  6386. var newX = Math.min(0, this._currentDrag.startOffsetX + e.gesture.deltaX);
  6387. // If the new X position is past the buttons, we need to slow down the drag (rubber band style)
  6388. if (newX < -buttonsWidth) {
  6389. // Calculate the new X position, capped at the top of the buttons
  6390. newX = Math.min(-buttonsWidth, -buttonsWidth + (((e.gesture.deltaX + buttonsWidth) * 0.4)));
  6391. }
  6392. this._currentDrag.content.$$ionicOptionsOpen = newX !== 0;
  6393. this._currentDrag.content.style[ionic.CSS.TRANSFORM] = 'translate3d(' + newX + 'px, 0, 0)';
  6394. this._currentDrag.content.style[ionic.CSS.TRANSITION] = 'none';
  6395. }
  6396. });
  6397. SlideDrag.prototype.end = function(e, doneCallback) {
  6398. var self = this;
  6399. // There is no drag, just end immediately
  6400. if (!self._currentDrag) {
  6401. doneCallback && doneCallback();
  6402. return;
  6403. }
  6404. // If we are currently dragging, we want to snap back into place
  6405. // The final resting point X will be the width of the exposed buttons
  6406. var restingPoint = -self._currentDrag.buttonsWidth;
  6407. // Check if the drag didn't clear the buttons mid-point
  6408. // and we aren't moving fast enough to swipe open
  6409. if (e.gesture.deltaX > -(self._currentDrag.buttonsWidth / 2)) {
  6410. // If we are going left but too slow, or going right, go back to resting
  6411. if (e.gesture.direction == "left" && Math.abs(e.gesture.velocityX) < 0.3) {
  6412. restingPoint = 0;
  6413. } else if (e.gesture.direction == "right") {
  6414. restingPoint = 0;
  6415. }
  6416. }
  6417. ionic.requestAnimationFrame(function() {
  6418. if (restingPoint === 0) {
  6419. self._currentDrag.content.style[ionic.CSS.TRANSFORM] = '';
  6420. var buttons = self._currentDrag.buttons;
  6421. setTimeout(function() {
  6422. buttons && buttons.classList.add('invisible');
  6423. }, 250);
  6424. } else {
  6425. self._currentDrag.content.style[ionic.CSS.TRANSFORM] = 'translate3d(' + restingPoint + 'px,0,0)';
  6426. }
  6427. self._currentDrag.content.style[ionic.CSS.TRANSITION] = '';
  6428. // Kill the current drag
  6429. if (!self._lastDrag) {
  6430. self._lastDrag = {};
  6431. }
  6432. ionic.extend(self._lastDrag, self._currentDrag);
  6433. if (self._currentDrag) {
  6434. self._currentDrag.buttons = null;
  6435. self._currentDrag.content = null;
  6436. }
  6437. self._currentDrag = null;
  6438. // We are done, notify caller
  6439. doneCallback && doneCallback();
  6440. });
  6441. };
  6442. var ReorderDrag = function(opts) {
  6443. var self = this;
  6444. self.dragThresholdY = opts.dragThresholdY || 0;
  6445. self.onReorder = opts.onReorder;
  6446. self.listEl = opts.listEl;
  6447. self.el = self.item = opts.el;
  6448. self.scrollEl = opts.scrollEl;
  6449. self.scrollView = opts.scrollView;
  6450. // Get the True Top of the list el http://www.quirksmode.org/js/findpos.html
  6451. self.listElTrueTop = 0;
  6452. if (self.listEl.offsetParent) {
  6453. var obj = self.listEl;
  6454. do {
  6455. self.listElTrueTop += obj.offsetTop;
  6456. obj = obj.offsetParent;
  6457. } while (obj);
  6458. }
  6459. };
  6460. ReorderDrag.prototype = new DragOp();
  6461. ReorderDrag.prototype._moveElement = function(e) {
  6462. var y = e.gesture.center.pageY +
  6463. this.scrollView.getValues().top -
  6464. (this._currentDrag.elementHeight / 2) -
  6465. this.listElTrueTop;
  6466. this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, ' + y + 'px, 0)';
  6467. };
  6468. ReorderDrag.prototype.deregister = function() {
  6469. this.listEl = this.el = this.scrollEl = this.scrollView = null;
  6470. };
  6471. ReorderDrag.prototype.start = function(e) {
  6472. var startIndex = ionic.DomUtil.getChildIndex(this.el, this.el.nodeName.toLowerCase());
  6473. var elementHeight = this.el.scrollHeight;
  6474. var placeholder = this.el.cloneNode(true);
  6475. placeholder.classList.add(ITEM_PLACEHOLDER_CLASS);
  6476. this.el.parentNode.insertBefore(placeholder, this.el);
  6477. this.el.classList.add(ITEM_REORDERING_CLASS);
  6478. this._currentDrag = {
  6479. elementHeight: elementHeight,
  6480. startIndex: startIndex,
  6481. placeholder: placeholder,
  6482. scrollHeight: scroll,
  6483. list: placeholder.parentNode
  6484. };
  6485. this._moveElement(e);
  6486. };
  6487. ReorderDrag.prototype.drag = ionic.animationFrameThrottle(function(e) {
  6488. // We really aren't dragging
  6489. var self = this;
  6490. if (!this._currentDrag) {
  6491. return;
  6492. }
  6493. var scrollY = 0;
  6494. var pageY = e.gesture.center.pageY;
  6495. var offset = this.listElTrueTop;
  6496. //If we have a scrollView, check scroll boundaries for dragged element and scroll if necessary
  6497. if (this.scrollView) {
  6498. var container = this.scrollView.__container;
  6499. scrollY = this.scrollView.getValues().top;
  6500. var containerTop = container.offsetTop;
  6501. var pixelsPastTop = containerTop - pageY + this._currentDrag.elementHeight / 2;
  6502. var pixelsPastBottom = pageY + this._currentDrag.elementHeight / 2 - containerTop - container.offsetHeight;
  6503. if (e.gesture.deltaY < 0 && pixelsPastTop > 0 && scrollY > 0) {
  6504. this.scrollView.scrollBy(null, -pixelsPastTop);
  6505. //Trigger another drag so the scrolling keeps going
  6506. ionic.requestAnimationFrame(function() {
  6507. self.drag(e);
  6508. });
  6509. }
  6510. if (e.gesture.deltaY > 0 && pixelsPastBottom > 0) {
  6511. if (scrollY < this.scrollView.getScrollMax().top) {
  6512. this.scrollView.scrollBy(null, pixelsPastBottom);
  6513. //Trigger another drag so the scrolling keeps going
  6514. ionic.requestAnimationFrame(function() {
  6515. self.drag(e);
  6516. });
  6517. }
  6518. }
  6519. }
  6520. // Check if we should start dragging. Check if we've dragged past the threshold,
  6521. // or we are starting from the open state.
  6522. if (!this._isDragging && Math.abs(e.gesture.deltaY) > this.dragThresholdY) {
  6523. this._isDragging = true;
  6524. }
  6525. if (this._isDragging) {
  6526. this._moveElement(e);
  6527. this._currentDrag.currentY = scrollY + pageY - offset;
  6528. // this._reorderItems();
  6529. }
  6530. });
  6531. // When an item is dragged, we need to reorder any items for sorting purposes
  6532. ReorderDrag.prototype._getReorderIndex = function() {
  6533. var self = this;
  6534. var siblings = Array.prototype.slice.call(self._currentDrag.placeholder.parentNode.children)
  6535. .filter(function(el) {
  6536. return el.nodeName === self.el.nodeName && el !== self.el;
  6537. });
  6538. var dragOffsetTop = self._currentDrag.currentY;
  6539. var el;
  6540. for (var i = 0, len = siblings.length; i < len; i++) {
  6541. el = siblings[i];
  6542. if (i === len - 1) {
  6543. if (dragOffsetTop > el.offsetTop) {
  6544. return i;
  6545. }
  6546. } else if (i === 0) {
  6547. if (dragOffsetTop < el.offsetTop + el.offsetHeight) {
  6548. return i;
  6549. }
  6550. } else if (dragOffsetTop > el.offsetTop - el.offsetHeight / 2 &&
  6551. dragOffsetTop < el.offsetTop + el.offsetHeight) {
  6552. return i;
  6553. }
  6554. }
  6555. return self._currentDrag.startIndex;
  6556. };
  6557. ReorderDrag.prototype.end = function(e, doneCallback) {
  6558. if (!this._currentDrag) {
  6559. doneCallback && doneCallback();
  6560. return;
  6561. }
  6562. var placeholder = this._currentDrag.placeholder;
  6563. var finalIndex = this._getReorderIndex();
  6564. // Reposition the element
  6565. this.el.classList.remove(ITEM_REORDERING_CLASS);
  6566. this.el.style[ionic.CSS.TRANSFORM] = '';
  6567. placeholder.parentNode.insertBefore(this.el, placeholder);
  6568. placeholder.parentNode.removeChild(placeholder);
  6569. this.onReorder && this.onReorder(this.el, this._currentDrag.startIndex, finalIndex);
  6570. this._currentDrag = {
  6571. placeholder: null,
  6572. content: null
  6573. };
  6574. this._currentDrag = null;
  6575. doneCallback && doneCallback();
  6576. };
  6577. /**
  6578. * The ListView handles a list of items. It will process drag animations, edit mode,
  6579. * and other operations that are common on mobile lists or table views.
  6580. */
  6581. ionic.views.ListView = ionic.views.View.inherit({
  6582. initialize: function(opts) {
  6583. var self = this;
  6584. opts = ionic.extend({
  6585. onReorder: function() {},
  6586. virtualRemoveThreshold: -200,
  6587. virtualAddThreshold: 200,
  6588. canSwipe: function() {
  6589. return true;
  6590. }
  6591. }, opts);
  6592. ionic.extend(self, opts);
  6593. if (!self.itemHeight && self.listEl) {
  6594. self.itemHeight = self.listEl.children[0] && parseInt(self.listEl.children[0].style.height, 10);
  6595. }
  6596. self.onRefresh = opts.onRefresh || function() {};
  6597. self.onRefreshOpening = opts.onRefreshOpening || function() {};
  6598. self.onRefreshHolding = opts.onRefreshHolding || function() {};
  6599. var gestureOpts = {};
  6600. // don't prevent native scrolling
  6601. if (ionic.DomUtil.getParentOrSelfWithClass(self.el, 'overflow-scroll')) {
  6602. gestureOpts.prevent_default_directions = ['left', 'right'];
  6603. }
  6604. window.ionic.onGesture('release', function(e) {
  6605. self._handleEndDrag(e);
  6606. }, self.el, gestureOpts);
  6607. window.ionic.onGesture('drag', function(e) {
  6608. self._handleDrag(e);
  6609. }, self.el, gestureOpts);
  6610. // Start the drag states
  6611. self._initDrag();
  6612. },
  6613. /**
  6614. * Be sure to cleanup references.
  6615. */
  6616. deregister: function() {
  6617. this.el = this.listEl = this.scrollEl = this.scrollView = null;
  6618. // ensure no scrolls have been left frozen
  6619. if (this.isScrollFreeze) {
  6620. self.scrollView.freeze(false);
  6621. }
  6622. },
  6623. /**
  6624. * Called to tell the list to stop refreshing. This is useful
  6625. * if you are refreshing the list and are done with refreshing.
  6626. */
  6627. stopRefreshing: function() {
  6628. var refresher = this.el.querySelector('.list-refresher');
  6629. refresher.style.height = '0';
  6630. },
  6631. /**
  6632. * If we scrolled and have virtual mode enabled, compute the window
  6633. * of active elements in order to figure out the viewport to render.
  6634. */
  6635. didScroll: function(e) {
  6636. var self = this;
  6637. if (self.isVirtual) {
  6638. var itemHeight = self.itemHeight;
  6639. // Grab the total height of the list
  6640. var scrollHeight = e.target.scrollHeight;
  6641. // Get the viewport height
  6642. var viewportHeight = self.el.parentNode.offsetHeight;
  6643. // High water is the pixel position of the first element to include (everything before
  6644. // that will be removed)
  6645. var highWater = Math.max(0, e.scrollTop + self.virtualRemoveThreshold);
  6646. // Low water is the pixel position of the last element to include (everything after
  6647. // that will be removed)
  6648. var lowWater = Math.min(scrollHeight, Math.abs(e.scrollTop) + viewportHeight + self.virtualAddThreshold);
  6649. // Get the first and last elements in the list based on how many can fit
  6650. // between the pixel range of lowWater and highWater
  6651. var first = parseInt(Math.abs(highWater / itemHeight), 10);
  6652. var last = parseInt(Math.abs(lowWater / itemHeight), 10);
  6653. // Get the items we need to remove
  6654. self._virtualItemsToRemove = Array.prototype.slice.call(self.listEl.children, 0, first);
  6655. self.renderViewport && self.renderViewport(highWater, lowWater, first, last);
  6656. }
  6657. },
  6658. didStopScrolling: function() {
  6659. if (this.isVirtual) {
  6660. for (var i = 0; i < this._virtualItemsToRemove.length; i++) {
  6661. //el.parentNode.removeChild(el);
  6662. this.didHideItem && this.didHideItem(i);
  6663. }
  6664. // Once scrolling stops, check if we need to remove old items
  6665. }
  6666. },
  6667. /**
  6668. * Clear any active drag effects on the list.
  6669. */
  6670. clearDragEffects: function(isInstant) {
  6671. if (this._lastDragOp) {
  6672. this._lastDragOp.clean && this._lastDragOp.clean(isInstant);
  6673. this._lastDragOp.deregister && this._lastDragOp.deregister();
  6674. this._lastDragOp = null;
  6675. }
  6676. },
  6677. _initDrag: function() {
  6678. // Store the last one
  6679. if (this._lastDragOp) {
  6680. this._lastDragOp.deregister && this._lastDragOp.deregister();
  6681. }
  6682. this._lastDragOp = this._dragOp;
  6683. this._dragOp = null;
  6684. },
  6685. // Return the list item from the given target
  6686. _getItem: function(target) {
  6687. while (target) {
  6688. if (target.classList && target.classList.contains(ITEM_CLASS)) {
  6689. return target;
  6690. }
  6691. target = target.parentNode;
  6692. }
  6693. return null;
  6694. },
  6695. _startDrag: function(e) {
  6696. var self = this;
  6697. self._isDragging = false;
  6698. var lastDragOp = self._lastDragOp;
  6699. var item;
  6700. // If we have an open SlideDrag and we're scrolling the list. Clear it.
  6701. if (self._didDragUpOrDown && lastDragOp instanceof SlideDrag) {
  6702. lastDragOp.clean && lastDragOp.clean();
  6703. }
  6704. // Check if this is a reorder drag
  6705. if (ionic.DomUtil.getParentOrSelfWithClass(e.target, ITEM_REORDER_BTN_CLASS) && (e.gesture.direction == 'up' || e.gesture.direction == 'down')) {
  6706. item = self._getItem(e.target);
  6707. if (item) {
  6708. self._dragOp = new ReorderDrag({
  6709. listEl: self.el,
  6710. el: item,
  6711. scrollEl: self.scrollEl,
  6712. scrollView: self.scrollView,
  6713. onReorder: function(el, start, end) {
  6714. self.onReorder && self.onReorder(el, start, end);
  6715. }
  6716. });
  6717. self._dragOp.start(e);
  6718. e.preventDefault();
  6719. }
  6720. }
  6721. // Or check if this is a swipe to the side drag
  6722. else if (!self._didDragUpOrDown && (e.gesture.direction == 'left' || e.gesture.direction == 'right') && Math.abs(e.gesture.deltaX) > 5) {
  6723. // Make sure this is an item with buttons
  6724. item = self._getItem(e.target);
  6725. if (item && item.querySelector('.item-options')) {
  6726. self._dragOp = new SlideDrag({
  6727. el: self.el,
  6728. item: item,
  6729. canSwipe: self.canSwipe
  6730. });
  6731. self._dragOp.start(e);
  6732. e.preventDefault();
  6733. self.isScrollFreeze = self.scrollView.freeze(true);
  6734. }
  6735. }
  6736. // If we had a last drag operation and this is a new one on a different item, clean that last one
  6737. if (lastDragOp && self._dragOp && !self._dragOp.isSameItem(lastDragOp) && e.defaultPrevented) {
  6738. lastDragOp.clean && lastDragOp.clean();
  6739. }
  6740. },
  6741. _handleEndDrag: function(e) {
  6742. var self = this;
  6743. if (self.scrollView) {
  6744. self.isScrollFreeze = self.scrollView.freeze(false);
  6745. }
  6746. self._didDragUpOrDown = false;
  6747. if (!self._dragOp) {
  6748. return;
  6749. }
  6750. self._dragOp.end(e, function() {
  6751. self._initDrag();
  6752. });
  6753. },
  6754. /**
  6755. * Process the drag event to move the item to the left or right.
  6756. */
  6757. _handleDrag: function(e) {
  6758. var self = this;
  6759. if (Math.abs(e.gesture.deltaY) > 5) {
  6760. self._didDragUpOrDown = true;
  6761. }
  6762. // If we get a drag event, make sure we aren't in another drag, then check if we should
  6763. // start one
  6764. if (!self.isDragging && !self._dragOp) {
  6765. self._startDrag(e);
  6766. }
  6767. // No drag still, pass it up
  6768. if (!self._dragOp) {
  6769. return;
  6770. }
  6771. e.gesture.srcEvent.preventDefault();
  6772. self._dragOp.drag(e);
  6773. }
  6774. });
  6775. })(ionic);
  6776. (function(ionic) {
  6777. 'use strict';
  6778. ionic.views.Modal = ionic.views.View.inherit({
  6779. initialize: function(opts) {
  6780. opts = ionic.extend({
  6781. focusFirstInput: false,
  6782. unfocusOnHide: true,
  6783. focusFirstDelay: 600,
  6784. backdropClickToClose: true,
  6785. hardwareBackButtonClose: true,
  6786. }, opts);
  6787. ionic.extend(this, opts);
  6788. this.el = opts.el;
  6789. },
  6790. show: function() {
  6791. var self = this;
  6792. if(self.focusFirstInput) {
  6793. // Let any animations run first
  6794. window.setTimeout(function() {
  6795. var input = self.el.querySelector('input, textarea');
  6796. input && input.focus && input.focus();
  6797. }, self.focusFirstDelay);
  6798. }
  6799. },
  6800. hide: function() {
  6801. // Unfocus all elements
  6802. if(this.unfocusOnHide) {
  6803. var inputs = this.el.querySelectorAll('input, textarea');
  6804. // Let any animations run first
  6805. window.setTimeout(function() {
  6806. for(var i = 0; i < inputs.length; i++) {
  6807. inputs[i].blur && inputs[i].blur();
  6808. }
  6809. });
  6810. }
  6811. }
  6812. });
  6813. })(ionic);
  6814. (function(ionic) {
  6815. 'use strict';
  6816. /**
  6817. * The side menu view handles one of the side menu's in a Side Menu Controller
  6818. * configuration.
  6819. * It takes a DOM reference to that side menu element.
  6820. */
  6821. ionic.views.SideMenu = ionic.views.View.inherit({
  6822. initialize: function(opts) {
  6823. this.el = opts.el;
  6824. this.isEnabled = (typeof opts.isEnabled === 'undefined') ? true : opts.isEnabled;
  6825. this.setWidth(opts.width);
  6826. },
  6827. getFullWidth: function() {
  6828. return this.width;
  6829. },
  6830. setWidth: function(width) {
  6831. this.width = width;
  6832. this.el.style.width = width + 'px';
  6833. },
  6834. setIsEnabled: function(isEnabled) {
  6835. this.isEnabled = isEnabled;
  6836. },
  6837. bringUp: function() {
  6838. if(this.el.style.zIndex !== '0') {
  6839. this.el.style.zIndex = '0';
  6840. }
  6841. },
  6842. pushDown: function() {
  6843. if(this.el.style.zIndex !== '-1') {
  6844. this.el.style.zIndex = '-1';
  6845. }
  6846. }
  6847. });
  6848. ionic.views.SideMenuContent = ionic.views.View.inherit({
  6849. initialize: function(opts) {
  6850. ionic.extend(this, {
  6851. animationClass: 'menu-animated',
  6852. onDrag: function() {},
  6853. onEndDrag: function() {}
  6854. }, opts);
  6855. ionic.onGesture('drag', ionic.proxy(this._onDrag, this), this.el);
  6856. ionic.onGesture('release', ionic.proxy(this._onEndDrag, this), this.el);
  6857. },
  6858. _onDrag: function(e) {
  6859. this.onDrag && this.onDrag(e);
  6860. },
  6861. _onEndDrag: function(e) {
  6862. this.onEndDrag && this.onEndDrag(e);
  6863. },
  6864. disableAnimation: function() {
  6865. this.el.classList.remove(this.animationClass);
  6866. },
  6867. enableAnimation: function() {
  6868. this.el.classList.add(this.animationClass);
  6869. },
  6870. getTranslateX: function() {
  6871. return parseFloat(this.el.style[ionic.CSS.TRANSFORM].replace('translate3d(', '').split(',')[0]);
  6872. },
  6873. setTranslateX: ionic.animationFrameThrottle(function(x) {
  6874. this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(' + x + 'px, 0, 0)';
  6875. })
  6876. });
  6877. })(ionic);
  6878. /*
  6879. * Adapted from Swipe.js 2.0
  6880. *
  6881. * Brad Birdsall
  6882. * Copyright 2013, MIT License
  6883. *
  6884. */
  6885. (function(ionic) {
  6886. 'use strict';
  6887. ionic.views.Slider = ionic.views.View.inherit({
  6888. initialize: function (options) {
  6889. var slider = this;
  6890. var touchStartEvent, touchMoveEvent, touchEndEvent;
  6891. if (window.navigator.pointerEnabled) {
  6892. touchStartEvent = 'pointerdown';
  6893. touchMoveEvent = 'pointermove';
  6894. touchEndEvent = 'pointerup';
  6895. } else if (window.navigator.msPointerEnabled) {
  6896. touchStartEvent = 'MSPointerDown';
  6897. touchMoveEvent = 'MSPointerMove';
  6898. touchEndEvent = 'MSPointerUp';
  6899. } else {
  6900. touchStartEvent = 'touchstart';
  6901. touchMoveEvent = 'touchmove';
  6902. touchEndEvent = 'touchend';
  6903. }
  6904. var mouseStartEvent = 'mousedown';
  6905. var mouseMoveEvent = 'mousemove';
  6906. var mouseEndEvent = 'mouseup';
  6907. // utilities
  6908. var noop = function() {}; // simple no operation function
  6909. var offloadFn = function(fn) { setTimeout(fn || noop, 0); }; // offload a functions execution
  6910. // check browser capabilities
  6911. var browser = {
  6912. addEventListener: !!window.addEventListener,
  6913. transitions: (function(temp) {
  6914. var props = ['transitionProperty', 'WebkitTransition', 'MozTransition', 'OTransition', 'msTransition'];
  6915. for ( var i in props ) if (temp.style[ props[i] ] !== undefined) return true;
  6916. return false;
  6917. })(document.createElement('swipe'))
  6918. };
  6919. var container = options.el;
  6920. // quit if no root element
  6921. if (!container) return;
  6922. var element = container.children[0];
  6923. var slides, slidePos, width, length;
  6924. options = options || {};
  6925. var index = parseInt(options.startSlide, 10) || 0;
  6926. var speed = options.speed || 300;
  6927. options.continuous = options.continuous !== undefined ? options.continuous : true;
  6928. function setup() {
  6929. // do not setup if the container has no width
  6930. if (!container.offsetWidth) {
  6931. return;
  6932. }
  6933. // cache slides
  6934. slides = element.children;
  6935. length = slides.length;
  6936. // set continuous to false if only one slide
  6937. if (slides.length < 2) options.continuous = false;
  6938. //special case if two slides
  6939. if (browser.transitions && options.continuous && slides.length < 3) {
  6940. element.appendChild(slides[0].cloneNode(true));
  6941. element.appendChild(element.children[1].cloneNode(true));
  6942. slides = element.children;
  6943. }
  6944. // create an array to store current positions of each slide
  6945. slidePos = new Array(slides.length);
  6946. // determine width of each slide
  6947. width = container.offsetWidth || container.getBoundingClientRect().width;
  6948. element.style.width = (slides.length * width) + 'px';
  6949. // stack elements
  6950. var pos = slides.length;
  6951. while(pos--) {
  6952. var slide = slides[pos];
  6953. slide.style.width = width + 'px';
  6954. slide.setAttribute('data-index', pos);
  6955. if (browser.transitions) {
  6956. slide.style.left = (pos * -width) + 'px';
  6957. move(pos, index > pos ? -width : (index < pos ? width : 0), 0);
  6958. }
  6959. }
  6960. // reposition elements before and after index
  6961. if (options.continuous && browser.transitions) {
  6962. move(circle(index - 1), -width, 0);
  6963. move(circle(index + 1), width, 0);
  6964. }
  6965. if (!browser.transitions) element.style.left = (index * -width) + 'px';
  6966. container.style.visibility = 'visible';
  6967. options.slidesChanged && options.slidesChanged();
  6968. }
  6969. function prev(slideSpeed) {
  6970. if (options.continuous) slide(index - 1, slideSpeed);
  6971. else if (index) slide(index - 1, slideSpeed);
  6972. }
  6973. function next(slideSpeed) {
  6974. if (options.continuous) slide(index + 1, slideSpeed);
  6975. else if (index < slides.length - 1) slide(index + 1, slideSpeed);
  6976. }
  6977. function circle(index) {
  6978. // a simple positive modulo using slides.length
  6979. return (slides.length + (index % slides.length)) % slides.length;
  6980. }
  6981. function slide(to, slideSpeed) {
  6982. // do nothing if already on requested slide
  6983. if (index == to) return;
  6984. if (!slides) {
  6985. index = to;
  6986. return;
  6987. }
  6988. if (browser.transitions) {
  6989. var direction = Math.abs(index - to) / (index - to); // 1: backward, -1: forward
  6990. // get the actual position of the slide
  6991. if (options.continuous) {
  6992. var naturalDirection = direction;
  6993. direction = -slidePos[circle(to)] / width;
  6994. // if going forward but to < index, use to = slides.length + to
  6995. // if going backward but to > index, use to = -slides.length + to
  6996. if (direction !== naturalDirection) to = -direction * slides.length + to;
  6997. }
  6998. var diff = Math.abs(index - to) - 1;
  6999. // move all the slides between index and to in the right direction
  7000. while (diff--) move( circle((to > index ? to : index) - diff - 1), width * direction, 0);
  7001. to = circle(to);
  7002. move(index, width * direction, slideSpeed || speed);
  7003. move(to, 0, slideSpeed || speed);
  7004. if (options.continuous) move(circle(to - direction), -(width * direction), 0); // we need to get the next in place
  7005. } else {
  7006. to = circle(to);
  7007. animate(index * -width, to * -width, slideSpeed || speed);
  7008. //no fallback for a circular continuous if the browser does not accept transitions
  7009. }
  7010. index = to;
  7011. offloadFn(options.callback && options.callback(index, slides[index]));
  7012. }
  7013. function move(index, dist, speed) {
  7014. translate(index, dist, speed);
  7015. slidePos[index] = dist;
  7016. }
  7017. function translate(index, dist, speed) {
  7018. var slide = slides[index];
  7019. var style = slide && slide.style;
  7020. if (!style) return;
  7021. style.webkitTransitionDuration =
  7022. style.MozTransitionDuration =
  7023. style.msTransitionDuration =
  7024. style.OTransitionDuration =
  7025. style.transitionDuration = speed + 'ms';
  7026. style.webkitTransform = 'translate(' + dist + 'px,0)' + 'translateZ(0)';
  7027. style.msTransform =
  7028. style.MozTransform =
  7029. style.OTransform = 'translateX(' + dist + 'px)';
  7030. }
  7031. function animate(from, to, speed) {
  7032. // if not an animation, just reposition
  7033. if (!speed) {
  7034. element.style.left = to + 'px';
  7035. return;
  7036. }
  7037. var start = +new Date();
  7038. var timer = setInterval(function() {
  7039. var timeElap = +new Date() - start;
  7040. if (timeElap > speed) {
  7041. element.style.left = to + 'px';
  7042. if (delay) begin();
  7043. options.transitionEnd && options.transitionEnd.call(event, index, slides[index]);
  7044. clearInterval(timer);
  7045. return;
  7046. }
  7047. element.style.left = (( (to - from) * (Math.floor((timeElap / speed) * 100) / 100) ) + from) + 'px';
  7048. }, 4);
  7049. }
  7050. // setup auto slideshow
  7051. var delay = options.auto || 0;
  7052. var interval;
  7053. function begin() {
  7054. interval = setTimeout(next, delay);
  7055. }
  7056. function stop() {
  7057. delay = options.auto || 0;
  7058. clearTimeout(interval);
  7059. }
  7060. // setup initial vars
  7061. var start = {};
  7062. var delta = {};
  7063. var isScrolling;
  7064. // setup event capturing
  7065. var events = {
  7066. handleEvent: function(event) {
  7067. if(!event.touches && event.pageX && event.pageY) {
  7068. event.touches = [{
  7069. pageX: event.pageX,
  7070. pageY: event.pageY
  7071. }];
  7072. }
  7073. switch (event.type) {
  7074. case touchStartEvent: this.start(event); break;
  7075. case mouseStartEvent: this.start(event); break;
  7076. case touchMoveEvent: this.touchmove(event); break;
  7077. case mouseMoveEvent: this.touchmove(event); break;
  7078. case touchEndEvent: offloadFn(this.end(event)); break;
  7079. case mouseEndEvent: offloadFn(this.end(event)); break;
  7080. case 'webkitTransitionEnd':
  7081. case 'msTransitionEnd':
  7082. case 'oTransitionEnd':
  7083. case 'otransitionend':
  7084. case 'transitionend': offloadFn(this.transitionEnd(event)); break;
  7085. case 'resize': offloadFn(setup); break;
  7086. }
  7087. if (options.stopPropagation) event.stopPropagation();
  7088. },
  7089. start: function(event) {
  7090. // prevent to start if there is no valid event
  7091. if (!event.touches) {
  7092. return;
  7093. }
  7094. var touches = event.touches[0];
  7095. // measure start values
  7096. start = {
  7097. // get initial touch coords
  7098. x: touches.pageX,
  7099. y: touches.pageY,
  7100. // store time to determine touch duration
  7101. time: +new Date()
  7102. };
  7103. // used for testing first move event
  7104. isScrolling = undefined;
  7105. // reset delta and end measurements
  7106. delta = {};
  7107. // attach touchmove and touchend listeners
  7108. element.addEventListener(touchMoveEvent, this, false);
  7109. element.addEventListener(mouseMoveEvent, this, false);
  7110. element.addEventListener(touchEndEvent, this, false);
  7111. element.addEventListener(mouseEndEvent, this, false);
  7112. document.addEventListener(touchEndEvent, this, false);
  7113. document.addEventListener(mouseEndEvent, this, false);
  7114. },
  7115. touchmove: function(event) {
  7116. // ensure there is a valid event
  7117. // ensure swiping with one touch and not pinching
  7118. // ensure sliding is enabled
  7119. if (!event.touches ||
  7120. event.touches.length > 1 ||
  7121. event.scale && event.scale !== 1 ||
  7122. slider.slideIsDisabled) {
  7123. return;
  7124. }
  7125. if (options.disableScroll) event.preventDefault();
  7126. var touches = event.touches[0];
  7127. // measure change in x and y
  7128. delta = {
  7129. x: touches.pageX - start.x,
  7130. y: touches.pageY - start.y
  7131. };
  7132. // determine if scrolling test has run - one time test
  7133. if ( typeof isScrolling == 'undefined') {
  7134. isScrolling = !!( isScrolling || Math.abs(delta.x) < Math.abs(delta.y) );
  7135. }
  7136. // if user is not trying to scroll vertically
  7137. if (!isScrolling) {
  7138. // prevent native scrolling
  7139. event.preventDefault();
  7140. // stop slideshow
  7141. stop();
  7142. // increase resistance if first or last slide
  7143. if (options.continuous) { // we don't add resistance at the end
  7144. translate(circle(index - 1), delta.x + slidePos[circle(index - 1)], 0);
  7145. translate(index, delta.x + slidePos[index], 0);
  7146. translate(circle(index + 1), delta.x + slidePos[circle(index + 1)], 0);
  7147. } else {
  7148. // If the slider bounces, do the bounce!
  7149. if(options.bouncing) {
  7150. delta.x =
  7151. delta.x /
  7152. ( (!index && delta.x > 0 || // if first slide and sliding left
  7153. index == slides.length - 1 && // or if last slide and sliding right
  7154. delta.x < 0 // and if sliding at all
  7155. ) ?
  7156. ( Math.abs(delta.x) / width + 1 ) // determine resistance level
  7157. : 1 ); // no resistance if false
  7158. } else {
  7159. if(width * index - delta.x < 0) { //We are trying scroll past left boundary
  7160. delta.x = Math.min(delta.x, width * index); //Set delta.x so we don't go past left screen
  7161. }
  7162. if(Math.abs(delta.x) > width * (slides.length - index - 1)){ //We are trying to scroll past right bondary
  7163. delta.x = Math.max( -width * (slides.length - index - 1), delta.x); //Set delta.x so we don't go past right screen
  7164. }
  7165. }
  7166. // translate 1:1
  7167. translate(index - 1, delta.x + slidePos[index - 1], 0);
  7168. translate(index, delta.x + slidePos[index], 0);
  7169. translate(index + 1, delta.x + slidePos[index + 1], 0);
  7170. }
  7171. options.onDrag && options.onDrag();
  7172. }
  7173. },
  7174. end: function() {
  7175. // measure duration
  7176. var duration = +new Date() - start.time;
  7177. // determine if slide attempt triggers next/prev slide
  7178. var isValidSlide =
  7179. Number(duration) < 250 && // if slide duration is less than 250ms
  7180. Math.abs(delta.x) > 20 || // and if slide amt is greater than 20px
  7181. Math.abs(delta.x) > width / 2; // or if slide amt is greater than half the width
  7182. // determine if slide attempt is past start and end
  7183. var isPastBounds = (!index && delta.x > 0) || // if first slide and slide amt is greater than 0
  7184. (index == slides.length - 1 && delta.x < 0); // or if last slide and slide amt is less than 0
  7185. if (options.continuous) isPastBounds = false;
  7186. // determine direction of swipe (true:right, false:left)
  7187. var direction = delta.x < 0;
  7188. // if not scrolling vertically
  7189. if (!isScrolling) {
  7190. if (isValidSlide && !isPastBounds) {
  7191. if (direction) {
  7192. if (options.continuous) { // we need to get the next in this direction in place
  7193. move(circle(index - 1), -width, 0);
  7194. move(circle(index + 2), width, 0);
  7195. } else {
  7196. move(index - 1, -width, 0);
  7197. }
  7198. move(index, slidePos[index] - width, speed);
  7199. move(circle(index + 1), slidePos[circle(index + 1)] - width, speed);
  7200. index = circle(index + 1);
  7201. } else {
  7202. if (options.continuous) { // we need to get the next in this direction in place
  7203. move(circle(index + 1), width, 0);
  7204. move(circle(index - 2), -width, 0);
  7205. } else {
  7206. move(index + 1, width, 0);
  7207. }
  7208. move(index, slidePos[index] + width, speed);
  7209. move(circle(index - 1), slidePos[circle(index - 1)] + width, speed);
  7210. index = circle(index - 1);
  7211. }
  7212. options.callback && options.callback(index, slides[index]);
  7213. } else {
  7214. if (options.continuous) {
  7215. move(circle(index - 1), -width, speed);
  7216. move(index, 0, speed);
  7217. move(circle(index + 1), width, speed);
  7218. } else {
  7219. move(index - 1, -width, speed);
  7220. move(index, 0, speed);
  7221. move(index + 1, width, speed);
  7222. }
  7223. }
  7224. }
  7225. // kill touchmove and touchend event listeners until touchstart called again
  7226. element.removeEventListener(touchMoveEvent, events, false);
  7227. element.removeEventListener(mouseMoveEvent, events, false);
  7228. element.removeEventListener(touchEndEvent, events, false);
  7229. element.removeEventListener(mouseEndEvent, events, false);
  7230. document.removeEventListener(touchEndEvent, events, false);
  7231. document.removeEventListener(mouseEndEvent, events, false);
  7232. options.onDragEnd && options.onDragEnd();
  7233. },
  7234. transitionEnd: function(event) {
  7235. if (parseInt(event.target.getAttribute('data-index'), 10) == index) {
  7236. if (delay) begin();
  7237. options.transitionEnd && options.transitionEnd.call(event, index, slides[index]);
  7238. }
  7239. }
  7240. };
  7241. // Public API
  7242. this.update = function() {
  7243. setTimeout(setup);
  7244. };
  7245. this.setup = function() {
  7246. setup();
  7247. };
  7248. this.loop = function(value) {
  7249. if (arguments.length) options.continuous = !!value;
  7250. return options.continuous;
  7251. };
  7252. this.enableSlide = function(shouldEnable) {
  7253. if (arguments.length) {
  7254. this.slideIsDisabled = !shouldEnable;
  7255. }
  7256. return !this.slideIsDisabled;
  7257. };
  7258. this.slide = this.select = function(to, speed) {
  7259. // cancel slideshow
  7260. stop();
  7261. slide(to, speed);
  7262. };
  7263. this.prev = this.previous = function() {
  7264. // cancel slideshow
  7265. stop();
  7266. prev();
  7267. };
  7268. this.next = function() {
  7269. // cancel slideshow
  7270. stop();
  7271. next();
  7272. };
  7273. this.stop = function() {
  7274. // cancel slideshow
  7275. stop();
  7276. };
  7277. this.start = function() {
  7278. begin();
  7279. };
  7280. this.autoPlay = function(newDelay) {
  7281. if (!delay || delay < 0) {
  7282. stop();
  7283. } else {
  7284. delay = newDelay;
  7285. begin();
  7286. }
  7287. };
  7288. this.currentIndex = this.selected = function() {
  7289. // return current index position
  7290. return index;
  7291. };
  7292. this.slidesCount = this.count = function() {
  7293. // return total number of slides
  7294. return length;
  7295. };
  7296. this.kill = function() {
  7297. // cancel slideshow
  7298. stop();
  7299. // reset element
  7300. element.style.width = '';
  7301. element.style.left = '';
  7302. // reset slides so no refs are held on to
  7303. slides && (slides = []);
  7304. // removed event listeners
  7305. if (browser.addEventListener) {
  7306. // remove current event listeners
  7307. element.removeEventListener(touchStartEvent, events, false);
  7308. element.removeEventListener(mouseStartEvent, events, false);
  7309. element.removeEventListener('webkitTransitionEnd', events, false);
  7310. element.removeEventListener('msTransitionEnd', events, false);
  7311. element.removeEventListener('oTransitionEnd', events, false);
  7312. element.removeEventListener('otransitionend', events, false);
  7313. element.removeEventListener('transitionend', events, false);
  7314. window.removeEventListener('resize', events, false);
  7315. }
  7316. else {
  7317. window.onresize = null;
  7318. }
  7319. };
  7320. this.load = function() {
  7321. // trigger setup
  7322. setup();
  7323. // start auto slideshow if applicable
  7324. if (delay) begin();
  7325. // add event listeners
  7326. if (browser.addEventListener) {
  7327. // set touchstart event on element
  7328. element.addEventListener(touchStartEvent, events, false);
  7329. element.addEventListener(mouseStartEvent, events, false);
  7330. if (browser.transitions) {
  7331. element.addEventListener('webkitTransitionEnd', events, false);
  7332. element.addEventListener('msTransitionEnd', events, false);
  7333. element.addEventListener('oTransitionEnd', events, false);
  7334. element.addEventListener('otransitionend', events, false);
  7335. element.addEventListener('transitionend', events, false);
  7336. }
  7337. // set resize event on window
  7338. window.addEventListener('resize', events, false);
  7339. } else {
  7340. window.onresize = function () { setup(); }; // to play nice with old IE
  7341. }
  7342. };
  7343. }
  7344. });
  7345. })(ionic);
  7346. /*eslint space-after-keywords: 0*/
  7347. /**
  7348. * Swiper 3.2.7
  7349. * Most modern mobile touch slider and framework with hardware accelerated transitions
  7350. *
  7351. * http://www.idangero.us/swiper/
  7352. *
  7353. * Copyright 2015, Vladimir Kharlampidi
  7354. * The iDangero.us
  7355. * http://www.idangero.us/
  7356. *
  7357. * Licensed under MIT
  7358. *
  7359. * Released on: December 7, 2015
  7360. */
  7361. (function () {
  7362. 'use strict';
  7363. var $;
  7364. /*===========================
  7365. Swiper
  7366. ===========================*/
  7367. var Swiper = function (container, params, _scope, $compile) {
  7368. if (!(this instanceof Swiper)) return new Swiper(container, params);
  7369. var defaults = {
  7370. direction: 'horizontal',
  7371. touchEventsTarget: 'container',
  7372. initialSlide: 0,
  7373. speed: 300,
  7374. // autoplay
  7375. autoplay: false,
  7376. autoplayDisableOnInteraction: true,
  7377. // To support iOS's swipe-to-go-back gesture (when being used in-app, with UIWebView).
  7378. iOSEdgeSwipeDetection: false,
  7379. iOSEdgeSwipeThreshold: 20,
  7380. // Free mode
  7381. freeMode: false,
  7382. freeModeMomentum: true,
  7383. freeModeMomentumRatio: 1,
  7384. freeModeMomentumBounce: true,
  7385. freeModeMomentumBounceRatio: 1,
  7386. freeModeSticky: false,
  7387. freeModeMinimumVelocity: 0.02,
  7388. // Autoheight
  7389. autoHeight: false,
  7390. // Set wrapper width
  7391. setWrapperSize: false,
  7392. // Virtual Translate
  7393. virtualTranslate: false,
  7394. // Effects
  7395. effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow'
  7396. coverflow: {
  7397. rotate: 50,
  7398. stretch: 0,
  7399. depth: 100,
  7400. modifier: 1,
  7401. slideShadows : true
  7402. },
  7403. cube: {
  7404. slideShadows: true,
  7405. shadow: true,
  7406. shadowOffset: 20,
  7407. shadowScale: 0.94
  7408. },
  7409. fade: {
  7410. crossFade: false
  7411. },
  7412. // Parallax
  7413. parallax: false,
  7414. // Scrollbar
  7415. scrollbar: null,
  7416. scrollbarHide: true,
  7417. scrollbarDraggable: false,
  7418. scrollbarSnapOnRelease: false,
  7419. // Keyboard Mousewheel
  7420. keyboardControl: false,
  7421. mousewheelControl: false,
  7422. mousewheelReleaseOnEdges: false,
  7423. mousewheelInvert: false,
  7424. mousewheelForceToAxis: false,
  7425. mousewheelSensitivity: 1,
  7426. // Hash Navigation
  7427. hashnav: false,
  7428. // Breakpoints
  7429. breakpoints: undefined,
  7430. // Slides grid
  7431. spaceBetween: 0,
  7432. slidesPerView: 1,
  7433. slidesPerColumn: 1,
  7434. slidesPerColumnFill: 'column',
  7435. slidesPerGroup: 1,
  7436. centeredSlides: false,
  7437. slidesOffsetBefore: 0, // in px
  7438. slidesOffsetAfter: 0, // in px
  7439. // Round length
  7440. roundLengths: false,
  7441. // Touches
  7442. touchRatio: 1,
  7443. touchAngle: 45,
  7444. simulateTouch: true,
  7445. shortSwipes: true,
  7446. longSwipes: true,
  7447. longSwipesRatio: 0.5,
  7448. longSwipesMs: 300,
  7449. followFinger: true,
  7450. onlyExternal: false,
  7451. threshold: 0,
  7452. touchMoveStopPropagation: true,
  7453. // Pagination
  7454. pagination: null,
  7455. paginationElement: 'span',
  7456. paginationClickable: false,
  7457. paginationHide: false,
  7458. paginationBulletRender: null,
  7459. // Resistance
  7460. resistance: true,
  7461. resistanceRatio: 0.85,
  7462. // Next/prev buttons
  7463. nextButton: null,
  7464. prevButton: null,
  7465. // Progress
  7466. watchSlidesProgress: false,
  7467. watchSlidesVisibility: false,
  7468. // Cursor
  7469. grabCursor: false,
  7470. // Clicks
  7471. preventClicks: true,
  7472. preventClicksPropagation: true,
  7473. slideToClickedSlide: false,
  7474. // Lazy Loading
  7475. lazyLoading: false,
  7476. lazyLoadingInPrevNext: false,
  7477. lazyLoadingOnTransitionStart: false,
  7478. // Images
  7479. preloadImages: true,
  7480. updateOnImagesReady: true,
  7481. // loop
  7482. loop: false,
  7483. loopAdditionalSlides: 0,
  7484. loopedSlides: null,
  7485. // Control
  7486. control: undefined,
  7487. controlInverse: false,
  7488. controlBy: 'slide', //or 'container'
  7489. // Swiping/no swiping
  7490. allowSwipeToPrev: true,
  7491. allowSwipeToNext: true,
  7492. swipeHandler: null, //'.swipe-handler',
  7493. noSwiping: true,
  7494. noSwipingClass: 'swiper-no-swiping',
  7495. // NS
  7496. slideClass: 'swiper-slide',
  7497. slideActiveClass: 'swiper-slide-active',
  7498. slideVisibleClass: 'swiper-slide-visible',
  7499. slideDuplicateClass: 'swiper-slide-duplicate',
  7500. slideNextClass: 'swiper-slide-next',
  7501. slidePrevClass: 'swiper-slide-prev',
  7502. wrapperClass: 'swiper-wrapper',
  7503. bulletClass: 'swiper-pagination-bullet',
  7504. bulletActiveClass: 'swiper-pagination-bullet-active',
  7505. buttonDisabledClass: 'swiper-button-disabled',
  7506. paginationHiddenClass: 'swiper-pagination-hidden',
  7507. // Observer
  7508. observer: false,
  7509. observeParents: false,
  7510. // Accessibility
  7511. a11y: false,
  7512. prevSlideMessage: 'Previous slide',
  7513. nextSlideMessage: 'Next slide',
  7514. firstSlideMessage: 'This is the first slide',
  7515. lastSlideMessage: 'This is the last slide',
  7516. paginationBulletMessage: 'Go to slide {{index}}',
  7517. // Callbacks
  7518. runCallbacksOnInit: true
  7519. /*
  7520. Callbacks:
  7521. onInit: function (swiper)
  7522. onDestroy: function (swiper)
  7523. onClick: function (swiper, e)
  7524. onTap: function (swiper, e)
  7525. onDoubleTap: function (swiper, e)
  7526. onSliderMove: function (swiper, e)
  7527. onSlideChangeStart: function (swiper)
  7528. onSlideChangeEnd: function (swiper)
  7529. onTransitionStart: function (swiper)
  7530. onTransitionEnd: function (swiper)
  7531. onImagesReady: function (swiper)
  7532. onProgress: function (swiper, progress)
  7533. onTouchStart: function (swiper, e)
  7534. onTouchMove: function (swiper, e)
  7535. onTouchMoveOpposite: function (swiper, e)
  7536. onTouchEnd: function (swiper, e)
  7537. onReachBeginning: function (swiper)
  7538. onReachEnd: function (swiper)
  7539. onSetTransition: function (swiper, duration)
  7540. onSetTranslate: function (swiper, translate)
  7541. onAutoplayStart: function (swiper)
  7542. onAutoplayStop: function (swiper),
  7543. onLazyImageLoad: function (swiper, slide, image)
  7544. onLazyImageReady: function (swiper, slide, image)
  7545. */
  7546. };
  7547. var initialVirtualTranslate = params && params.virtualTranslate;
  7548. params = params || {};
  7549. var originalParams = {};
  7550. for (var param in params) {
  7551. if (typeof params[param] === 'object' && !(params[param].nodeType || params[param] === window || params[param] === document || (typeof Dom7 !== 'undefined' && params[param] instanceof Dom7) || (typeof jQuery !== 'undefined' && params[param] instanceof jQuery))) {
  7552. originalParams[param] = {};
  7553. for (var deepParam in params[param]) {
  7554. originalParams[param][deepParam] = params[param][deepParam];
  7555. }
  7556. }
  7557. else {
  7558. originalParams[param] = params[param];
  7559. }
  7560. }
  7561. for (var def in defaults) {
  7562. if (typeof params[def] === 'undefined') {
  7563. params[def] = defaults[def];
  7564. }
  7565. else if (typeof params[def] === 'object') {
  7566. for (var deepDef in defaults[def]) {
  7567. if (typeof params[def][deepDef] === 'undefined') {
  7568. params[def][deepDef] = defaults[def][deepDef];
  7569. }
  7570. }
  7571. }
  7572. }
  7573. // Swiper
  7574. var s = this;
  7575. // Params
  7576. s.params = params;
  7577. s.originalParams = originalParams;
  7578. // Classname
  7579. s.classNames = [];
  7580. /*=========================
  7581. Dom Library and plugins
  7582. ===========================*/
  7583. if (typeof $ !== 'undefined' && typeof Dom7 !== 'undefined'){
  7584. $ = Dom7;
  7585. }
  7586. if (typeof $ === 'undefined') {
  7587. if (typeof Dom7 === 'undefined') {
  7588. $ = window.Dom7 || window.Zepto || window.jQuery;
  7589. }
  7590. else {
  7591. $ = Dom7;
  7592. }
  7593. if (!$) return;
  7594. }
  7595. // Export it to Swiper instance
  7596. s.$ = $;
  7597. /*=========================
  7598. Breakpoints
  7599. ===========================*/
  7600. s.currentBreakpoint = undefined;
  7601. s.getActiveBreakpoint = function () {
  7602. //Get breakpoint for window width
  7603. if (!s.params.breakpoints) return false;
  7604. var breakpoint = false;
  7605. var points = [], point;
  7606. for ( point in s.params.breakpoints ) {
  7607. if (s.params.breakpoints.hasOwnProperty(point)) {
  7608. points.push(point);
  7609. }
  7610. }
  7611. points.sort(function (a, b) {
  7612. return parseInt(a, 10) > parseInt(b, 10);
  7613. });
  7614. for (var i = 0; i < points.length; i++) {
  7615. point = points[i];
  7616. if (point >= window.innerWidth && !breakpoint) {
  7617. breakpoint = point;
  7618. }
  7619. }
  7620. return breakpoint || 'max';
  7621. };
  7622. s.setBreakpoint = function () {
  7623. //Set breakpoint for window width and update parameters
  7624. var breakpoint = s.getActiveBreakpoint();
  7625. if (breakpoint && s.currentBreakpoint !== breakpoint) {
  7626. var breakPointsParams = breakpoint in s.params.breakpoints ? s.params.breakpoints[breakpoint] : s.originalParams;
  7627. for ( var param in breakPointsParams ) {
  7628. s.params[param] = breakPointsParams[param];
  7629. }
  7630. s.currentBreakpoint = breakpoint;
  7631. }
  7632. };
  7633. // Set breakpoint on load
  7634. if (s.params.breakpoints) {
  7635. s.setBreakpoint();
  7636. }
  7637. /*=========================
  7638. Preparation - Define Container, Wrapper and Pagination
  7639. ===========================*/
  7640. s.container = $(container);
  7641. if (s.container.length === 0) return;
  7642. if (s.container.length > 1) {
  7643. s.container.each(function () {
  7644. new Swiper(this, params);
  7645. });
  7646. return;
  7647. }
  7648. // Save instance in container HTML Element and in data
  7649. s.container[0].swiper = s;
  7650. s.container.data('swiper', s);
  7651. s.classNames.push('swiper-container-' + s.params.direction);
  7652. if (s.params.freeMode) {
  7653. s.classNames.push('swiper-container-free-mode');
  7654. }
  7655. if (!s.support.flexbox) {
  7656. s.classNames.push('swiper-container-no-flexbox');
  7657. s.params.slidesPerColumn = 1;
  7658. }
  7659. if (s.params.autoHeight) {
  7660. s.classNames.push('swiper-container-autoheight');
  7661. }
  7662. // Enable slides progress when required
  7663. if (s.params.parallax || s.params.watchSlidesVisibility) {
  7664. s.params.watchSlidesProgress = true;
  7665. }
  7666. // Coverflow / 3D
  7667. if (['cube', 'coverflow'].indexOf(s.params.effect) >= 0) {
  7668. if (s.support.transforms3d) {
  7669. s.params.watchSlidesProgress = true;
  7670. s.classNames.push('swiper-container-3d');
  7671. }
  7672. else {
  7673. s.params.effect = 'slide';
  7674. }
  7675. }
  7676. if (s.params.effect !== 'slide') {
  7677. s.classNames.push('swiper-container-' + s.params.effect);
  7678. }
  7679. if (s.params.effect === 'cube') {
  7680. s.params.resistanceRatio = 0;
  7681. s.params.slidesPerView = 1;
  7682. s.params.slidesPerColumn = 1;
  7683. s.params.slidesPerGroup = 1;
  7684. s.params.centeredSlides = false;
  7685. s.params.spaceBetween = 0;
  7686. s.params.virtualTranslate = true;
  7687. s.params.setWrapperSize = false;
  7688. }
  7689. if (s.params.effect === 'fade') {
  7690. s.params.slidesPerView = 1;
  7691. s.params.slidesPerColumn = 1;
  7692. s.params.slidesPerGroup = 1;
  7693. s.params.watchSlidesProgress = true;
  7694. s.params.spaceBetween = 0;
  7695. if (typeof initialVirtualTranslate === 'undefined') {
  7696. s.params.virtualTranslate = true;
  7697. }
  7698. }
  7699. // Grab Cursor
  7700. if (s.params.grabCursor && s.support.touch) {
  7701. s.params.grabCursor = false;
  7702. }
  7703. // Wrapper
  7704. s.wrapper = s.container.children('.' + s.params.wrapperClass);
  7705. // Pagination
  7706. if (s.params.pagination) {
  7707. s.paginationContainer = $(s.params.pagination);
  7708. if (s.params.paginationClickable) {
  7709. s.paginationContainer.addClass('swiper-pagination-clickable');
  7710. }
  7711. }
  7712. // Is Horizontal
  7713. function isH() {
  7714. return s.params.direction === 'horizontal';
  7715. }
  7716. // RTL
  7717. s.rtl = isH() && (s.container[0].dir.toLowerCase() === 'rtl' || s.container.css('direction') === 'rtl');
  7718. if (s.rtl) {
  7719. s.classNames.push('swiper-container-rtl');
  7720. }
  7721. // Wrong RTL support
  7722. if (s.rtl) {
  7723. s.wrongRTL = s.wrapper.css('display') === '-webkit-box';
  7724. }
  7725. // Columns
  7726. if (s.params.slidesPerColumn > 1) {
  7727. s.classNames.push('swiper-container-multirow');
  7728. }
  7729. // Check for Android
  7730. if (s.device.android) {
  7731. s.classNames.push('swiper-container-android');
  7732. }
  7733. // Add classes
  7734. s.container.addClass(s.classNames.join(' '));
  7735. // Translate
  7736. s.translate = 0;
  7737. // Progress
  7738. s.progress = 0;
  7739. // Velocity
  7740. s.velocity = 0;
  7741. /*=========================
  7742. Locks, unlocks
  7743. ===========================*/
  7744. s.lockSwipeToNext = function () {
  7745. s.params.allowSwipeToNext = false;
  7746. };
  7747. s.lockSwipeToPrev = function () {
  7748. s.params.allowSwipeToPrev = false;
  7749. };
  7750. s.lockSwipes = function () {
  7751. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = false;
  7752. };
  7753. s.unlockSwipeToNext = function () {
  7754. s.params.allowSwipeToNext = true;
  7755. };
  7756. s.unlockSwipeToPrev = function () {
  7757. s.params.allowSwipeToPrev = true;
  7758. };
  7759. s.unlockSwipes = function () {
  7760. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = true;
  7761. };
  7762. /*=========================
  7763. Round helper
  7764. ===========================*/
  7765. function round(a) {
  7766. return Math.floor(a);
  7767. }
  7768. /*=========================
  7769. Set grab cursor
  7770. ===========================*/
  7771. if (s.params.grabCursor) {
  7772. s.container[0].style.cursor = 'move';
  7773. s.container[0].style.cursor = '-webkit-grab';
  7774. s.container[0].style.cursor = '-moz-grab';
  7775. s.container[0].style.cursor = 'grab';
  7776. }
  7777. /*=========================
  7778. Update on Images Ready
  7779. ===========================*/
  7780. s.imagesToLoad = [];
  7781. s.imagesLoaded = 0;
  7782. s.loadImage = function (imgElement, src, srcset, checkForComplete, callback) {
  7783. var image;
  7784. function onReady () {
  7785. if (callback) callback();
  7786. }
  7787. if (!imgElement.complete || !checkForComplete) {
  7788. if (src) {
  7789. image = new window.Image();
  7790. image.onload = onReady;
  7791. image.onerror = onReady;
  7792. if (srcset) {
  7793. image.srcset = srcset;
  7794. }
  7795. if (src) {
  7796. image.src = src;
  7797. }
  7798. } else {
  7799. onReady();
  7800. }
  7801. } else {//image already loaded...
  7802. onReady();
  7803. }
  7804. };
  7805. s.preloadImages = function () {
  7806. s.imagesToLoad = s.container.find('img');
  7807. function _onReady() {
  7808. if (typeof s === 'undefined' || s === null) return;
  7809. if (s.imagesLoaded !== undefined) s.imagesLoaded++;
  7810. if (s.imagesLoaded === s.imagesToLoad.length) {
  7811. if (s.params.updateOnImagesReady) s.update();
  7812. s.emit('onImagesReady', s);
  7813. }
  7814. }
  7815. for (var i = 0; i < s.imagesToLoad.length; i++) {
  7816. s.loadImage(s.imagesToLoad[i], (s.imagesToLoad[i].currentSrc || s.imagesToLoad[i].getAttribute('src')), (s.imagesToLoad[i].srcset || s.imagesToLoad[i].getAttribute('srcset')), true, _onReady);
  7817. }
  7818. };
  7819. /*=========================
  7820. Autoplay
  7821. ===========================*/
  7822. s.autoplayTimeoutId = undefined;
  7823. s.autoplaying = false;
  7824. s.autoplayPaused = false;
  7825. function autoplay() {
  7826. s.autoplayTimeoutId = setTimeout(function () {
  7827. if (s.params.loop) {
  7828. s.fixLoop();
  7829. s._slideNext();
  7830. }
  7831. else {
  7832. if (!s.isEnd) {
  7833. s._slideNext();
  7834. }
  7835. else {
  7836. if (!params.autoplayStopOnLast) {
  7837. s._slideTo(0);
  7838. }
  7839. else {
  7840. s.stopAutoplay();
  7841. }
  7842. }
  7843. }
  7844. }, s.params.autoplay);
  7845. }
  7846. s.startAutoplay = function () {
  7847. if (typeof s.autoplayTimeoutId !== 'undefined') return false;
  7848. if (!s.params.autoplay) return false;
  7849. if (s.autoplaying) return false;
  7850. s.autoplaying = true;
  7851. s.emit('onAutoplayStart', s);
  7852. autoplay();
  7853. };
  7854. s.stopAutoplay = function (internal) {
  7855. if (!s.autoplayTimeoutId) return;
  7856. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  7857. s.autoplaying = false;
  7858. s.autoplayTimeoutId = undefined;
  7859. s.emit('onAutoplayStop', s);
  7860. };
  7861. s.pauseAutoplay = function (speed) {
  7862. if (s.autoplayPaused) return;
  7863. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  7864. s.autoplayPaused = true;
  7865. if (speed === 0) {
  7866. s.autoplayPaused = false;
  7867. autoplay();
  7868. }
  7869. else {
  7870. s.wrapper.transitionEnd(function () {
  7871. if (!s) return;
  7872. s.autoplayPaused = false;
  7873. if (!s.autoplaying) {
  7874. s.stopAutoplay();
  7875. }
  7876. else {
  7877. autoplay();
  7878. }
  7879. });
  7880. }
  7881. };
  7882. /*=========================
  7883. Min/Max Translate
  7884. ===========================*/
  7885. s.minTranslate = function () {
  7886. return (-s.snapGrid[0]);
  7887. };
  7888. s.maxTranslate = function () {
  7889. return (-s.snapGrid[s.snapGrid.length - 1]);
  7890. };
  7891. /*=========================
  7892. Slider/slides sizes
  7893. ===========================*/
  7894. s.updateAutoHeight = function () {
  7895. // Update Height
  7896. var newHeight = s.slides.eq(s.activeIndex)[0].offsetHeight;
  7897. if (newHeight) s.wrapper.css('height', s.slides.eq(s.activeIndex)[0].offsetHeight + 'px');
  7898. };
  7899. s.updateContainerSize = function () {
  7900. var width, height;
  7901. if (typeof s.params.width !== 'undefined') {
  7902. width = s.params.width;
  7903. }
  7904. else {
  7905. width = s.container[0].clientWidth;
  7906. }
  7907. if (typeof s.params.height !== 'undefined') {
  7908. height = s.params.height;
  7909. }
  7910. else {
  7911. height = s.container[0].clientHeight;
  7912. }
  7913. if (width === 0 && isH() || height === 0 && !isH()) {
  7914. return;
  7915. }
  7916. //Subtract paddings
  7917. width = width - parseInt(s.container.css('padding-left'), 10) - parseInt(s.container.css('padding-right'), 10);
  7918. height = height - parseInt(s.container.css('padding-top'), 10) - parseInt(s.container.css('padding-bottom'), 10);
  7919. // Store values
  7920. s.width = width;
  7921. s.height = height;
  7922. s.size = isH() ? s.width : s.height;
  7923. };
  7924. s.updateSlidesSize = function () {
  7925. s.slides = s.wrapper.children('.' + s.params.slideClass);
  7926. s.snapGrid = [];
  7927. s.slidesGrid = [];
  7928. s.slidesSizesGrid = [];
  7929. var spaceBetween = s.params.spaceBetween,
  7930. slidePosition = -s.params.slidesOffsetBefore,
  7931. i,
  7932. prevSlideSize = 0,
  7933. index = 0;
  7934. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  7935. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s.size;
  7936. }
  7937. s.virtualSize = -spaceBetween;
  7938. // reset margins
  7939. if (s.rtl) s.slides.css({marginLeft: '', marginTop: ''});
  7940. else s.slides.css({marginRight: '', marginBottom: ''});
  7941. var slidesNumberEvenToRows;
  7942. if (s.params.slidesPerColumn > 1) {
  7943. if (Math.floor(s.slides.length / s.params.slidesPerColumn) === s.slides.length / s.params.slidesPerColumn) {
  7944. slidesNumberEvenToRows = s.slides.length;
  7945. }
  7946. else {
  7947. slidesNumberEvenToRows = Math.ceil(s.slides.length / s.params.slidesPerColumn) * s.params.slidesPerColumn;
  7948. }
  7949. if (s.params.slidesPerView !== 'auto' && s.params.slidesPerColumnFill === 'row') {
  7950. slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, s.params.slidesPerView * s.params.slidesPerColumn);
  7951. }
  7952. }
  7953. // Calc slides
  7954. var slideSize;
  7955. var slidesPerColumn = s.params.slidesPerColumn;
  7956. var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
  7957. var numFullColumns = slidesPerRow - (s.params.slidesPerColumn * slidesPerRow - s.slides.length);
  7958. for (i = 0; i < s.slides.length; i++) {
  7959. slideSize = 0;
  7960. var slide = s.slides.eq(i);
  7961. if (s.params.slidesPerColumn > 1) {
  7962. // Set slides order
  7963. var newSlideOrderIndex;
  7964. var column, row;
  7965. if (s.params.slidesPerColumnFill === 'column') {
  7966. column = Math.floor(i / slidesPerColumn);
  7967. row = i - column * slidesPerColumn;
  7968. if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn-1)) {
  7969. if (++row >= slidesPerColumn) {
  7970. row = 0;
  7971. column++;
  7972. }
  7973. }
  7974. newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
  7975. slide
  7976. .css({
  7977. '-webkit-box-ordinal-group': newSlideOrderIndex,
  7978. '-moz-box-ordinal-group': newSlideOrderIndex,
  7979. '-ms-flex-order': newSlideOrderIndex,
  7980. '-webkit-order': newSlideOrderIndex,
  7981. 'order': newSlideOrderIndex
  7982. });
  7983. }
  7984. else {
  7985. row = Math.floor(i / slidesPerRow);
  7986. column = i - row * slidesPerRow;
  7987. }
  7988. slide
  7989. .css({
  7990. 'margin-top': (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px')
  7991. })
  7992. .attr('data-swiper-column', column)
  7993. .attr('data-swiper-row', row);
  7994. }
  7995. if (slide.css('display') === 'none') continue;
  7996. if (s.params.slidesPerView === 'auto') {
  7997. slideSize = isH() ? slide.outerWidth(true) : slide.outerHeight(true);
  7998. if (s.params.roundLengths) slideSize = round(slideSize);
  7999. }
  8000. else {
  8001. slideSize = (s.size - (s.params.slidesPerView - 1) * spaceBetween) / s.params.slidesPerView;
  8002. if (s.params.roundLengths) slideSize = round(slideSize);
  8003. if (isH()) {
  8004. s.slides[i].style.width = slideSize + 'px';
  8005. }
  8006. else {
  8007. s.slides[i].style.height = slideSize + 'px';
  8008. }
  8009. }
  8010. s.slides[i].swiperSlideSize = slideSize;
  8011. s.slidesSizesGrid.push(slideSize);
  8012. if (s.params.centeredSlides) {
  8013. slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
  8014. if (i === 0) slidePosition = slidePosition - s.size / 2 - spaceBetween;
  8015. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  8016. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  8017. s.slidesGrid.push(slidePosition);
  8018. }
  8019. else {
  8020. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  8021. s.slidesGrid.push(slidePosition);
  8022. slidePosition = slidePosition + slideSize + spaceBetween;
  8023. }
  8024. s.virtualSize += slideSize + spaceBetween;
  8025. prevSlideSize = slideSize;
  8026. index ++;
  8027. }
  8028. s.virtualSize = Math.max(s.virtualSize, s.size) + s.params.slidesOffsetAfter;
  8029. var newSlidesGrid;
  8030. if (
  8031. s.rtl && s.wrongRTL && (s.params.effect === 'slide' || s.params.effect === 'coverflow')) {
  8032. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  8033. }
  8034. if (!s.support.flexbox || s.params.setWrapperSize) {
  8035. if (isH()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  8036. else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
  8037. }
  8038. if (s.params.slidesPerColumn > 1) {
  8039. s.virtualSize = (slideSize + s.params.spaceBetween) * slidesNumberEvenToRows;
  8040. s.virtualSize = Math.ceil(s.virtualSize / s.params.slidesPerColumn) - s.params.spaceBetween;
  8041. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  8042. if (s.params.centeredSlides) {
  8043. newSlidesGrid = [];
  8044. for (i = 0; i < s.snapGrid.length; i++) {
  8045. if (s.snapGrid[i] < s.virtualSize + s.snapGrid[0]) newSlidesGrid.push(s.snapGrid[i]);
  8046. }
  8047. s.snapGrid = newSlidesGrid;
  8048. }
  8049. }
  8050. // Remove last grid elements depending on width
  8051. if (!s.params.centeredSlides) {
  8052. newSlidesGrid = [];
  8053. for (i = 0; i < s.snapGrid.length; i++) {
  8054. if (s.snapGrid[i] <= s.virtualSize - s.size) {
  8055. newSlidesGrid.push(s.snapGrid[i]);
  8056. }
  8057. }
  8058. s.snapGrid = newSlidesGrid;
  8059. if (Math.floor(s.virtualSize - s.size) > Math.floor(s.snapGrid[s.snapGrid.length - 1])) {
  8060. s.snapGrid.push(s.virtualSize - s.size);
  8061. }
  8062. }
  8063. if (s.snapGrid.length === 0) s.snapGrid = [0];
  8064. if (s.params.spaceBetween !== 0) {
  8065. if (isH()) {
  8066. if (s.rtl) s.slides.css({marginLeft: spaceBetween + 'px'});
  8067. else s.slides.css({marginRight: spaceBetween + 'px'});
  8068. }
  8069. else s.slides.css({marginBottom: spaceBetween + 'px'});
  8070. }
  8071. if (s.params.watchSlidesProgress) {
  8072. s.updateSlidesOffset();
  8073. }
  8074. };
  8075. s.updateSlidesOffset = function () {
  8076. for (var i = 0; i < s.slides.length; i++) {
  8077. s.slides[i].swiperSlideOffset = isH() ? s.slides[i].offsetLeft : s.slides[i].offsetTop;
  8078. }
  8079. };
  8080. /*=========================
  8081. Slider/slides progress
  8082. ===========================*/
  8083. s.updateSlidesProgress = function (translate) {
  8084. if (typeof translate === 'undefined') {
  8085. translate = s.translate || 0;
  8086. }
  8087. if (s.slides.length === 0) return;
  8088. if (typeof s.slides[0].swiperSlideOffset === 'undefined') s.updateSlidesOffset();
  8089. var offsetCenter = -translate;
  8090. if (s.rtl) offsetCenter = translate;
  8091. // Visible Slides
  8092. s.slides.removeClass(s.params.slideVisibleClass);
  8093. for (var i = 0; i < s.slides.length; i++) {
  8094. var slide = s.slides[i];
  8095. var slideProgress = (offsetCenter - slide.swiperSlideOffset) / (slide.swiperSlideSize + s.params.spaceBetween);
  8096. if (s.params.watchSlidesVisibility) {
  8097. var slideBefore = -(offsetCenter - slide.swiperSlideOffset);
  8098. var slideAfter = slideBefore + s.slidesSizesGrid[i];
  8099. var isVisible =
  8100. (slideBefore >= 0 && slideBefore < s.size) ||
  8101. (slideAfter > 0 && slideAfter <= s.size) ||
  8102. (slideBefore <= 0 && slideAfter >= s.size);
  8103. if (isVisible) {
  8104. s.slides.eq(i).addClass(s.params.slideVisibleClass);
  8105. }
  8106. }
  8107. slide.progress = s.rtl ? -slideProgress : slideProgress;
  8108. }
  8109. };
  8110. s.updateProgress = function (translate) {
  8111. if (typeof translate === 'undefined') {
  8112. translate = s.translate || 0;
  8113. }
  8114. var translatesDiff = s.maxTranslate() - s.minTranslate();
  8115. var wasBeginning = s.isBeginning;
  8116. var wasEnd = s.isEnd;
  8117. if (translatesDiff === 0) {
  8118. s.progress = 0;
  8119. s.isBeginning = s.isEnd = true;
  8120. }
  8121. else {
  8122. s.progress = (translate - s.minTranslate()) / (translatesDiff);
  8123. s.isBeginning = s.progress <= 0;
  8124. s.isEnd = s.progress >= 1;
  8125. }
  8126. if (s.isBeginning && !wasBeginning) s.emit('onReachBeginning', s);
  8127. if (s.isEnd && !wasEnd) s.emit('onReachEnd', s);
  8128. if (s.params.watchSlidesProgress) s.updateSlidesProgress(translate);
  8129. s.emit('onProgress', s, s.progress);
  8130. };
  8131. s.updateActiveIndex = function () {
  8132. var translate = s.rtl ? s.translate : -s.translate;
  8133. var newActiveIndex, i, snapIndex;
  8134. for (i = 0; i < s.slidesGrid.length; i ++) {
  8135. if (typeof s.slidesGrid[i + 1] !== 'undefined') {
  8136. if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1] - (s.slidesGrid[i + 1] - s.slidesGrid[i]) / 2) {
  8137. newActiveIndex = i;
  8138. }
  8139. else if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1]) {
  8140. newActiveIndex = i + 1;
  8141. }
  8142. }
  8143. else {
  8144. if (translate >= s.slidesGrid[i]) {
  8145. newActiveIndex = i;
  8146. }
  8147. }
  8148. }
  8149. // Normalize slideIndex
  8150. if (newActiveIndex < 0 || typeof newActiveIndex === 'undefined') newActiveIndex = 0;
  8151. // for (i = 0; i < s.slidesGrid.length; i++) {
  8152. // if (- translate >= s.slidesGrid[i]) {
  8153. // newActiveIndex = i;
  8154. // }
  8155. // }
  8156. snapIndex = Math.floor(newActiveIndex / s.params.slidesPerGroup);
  8157. if (snapIndex >= s.snapGrid.length) snapIndex = s.snapGrid.length - 1;
  8158. if (newActiveIndex === s.activeIndex) {
  8159. return;
  8160. }
  8161. s.snapIndex = snapIndex;
  8162. s.previousIndex = s.activeIndex;
  8163. s.activeIndex = newActiveIndex;
  8164. s.updateClasses();
  8165. };
  8166. /*=========================
  8167. Classes
  8168. ===========================*/
  8169. s.updateClasses = function () {
  8170. s.slides.removeClass(s.params.slideActiveClass + ' ' + s.params.slideNextClass + ' ' + s.params.slidePrevClass);
  8171. var activeSlide = s.slides.eq(s.activeIndex);
  8172. // Active classes
  8173. activeSlide.addClass(s.params.slideActiveClass);
  8174. activeSlide.next('.' + s.params.slideClass).addClass(s.params.slideNextClass);
  8175. activeSlide.prev('.' + s.params.slideClass).addClass(s.params.slidePrevClass);
  8176. // Pagination
  8177. if (s.bullets && s.bullets.length > 0) {
  8178. s.bullets.removeClass(s.params.bulletActiveClass);
  8179. var bulletIndex;
  8180. if (s.params.loop) {
  8181. bulletIndex = Math.ceil(s.activeIndex - s.loopedSlides)/s.params.slidesPerGroup;
  8182. if (bulletIndex > s.slides.length - 1 - s.loopedSlides * 2) {
  8183. bulletIndex = bulletIndex - (s.slides.length - s.loopedSlides * 2);
  8184. }
  8185. if (bulletIndex > s.bullets.length - 1) bulletIndex = bulletIndex - s.bullets.length;
  8186. }
  8187. else {
  8188. if (typeof s.snapIndex !== 'undefined') {
  8189. bulletIndex = s.snapIndex;
  8190. }
  8191. else {
  8192. bulletIndex = s.activeIndex || 0;
  8193. }
  8194. }
  8195. if (s.paginationContainer.length > 1) {
  8196. s.bullets.each(function () {
  8197. if ($(this).index() === bulletIndex) $(this).addClass(s.params.bulletActiveClass);
  8198. });
  8199. }
  8200. else {
  8201. s.bullets.eq(bulletIndex).addClass(s.params.bulletActiveClass);
  8202. }
  8203. }
  8204. // Next/active buttons
  8205. if (!s.params.loop) {
  8206. if (s.params.prevButton) {
  8207. if (s.isBeginning) {
  8208. $(s.params.prevButton).addClass(s.params.buttonDisabledClass);
  8209. if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.prevButton));
  8210. }
  8211. else {
  8212. $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  8213. if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.prevButton));
  8214. }
  8215. }
  8216. if (s.params.nextButton) {
  8217. if (s.isEnd) {
  8218. $(s.params.nextButton).addClass(s.params.buttonDisabledClass);
  8219. if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.nextButton));
  8220. }
  8221. else {
  8222. $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  8223. if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.nextButton));
  8224. }
  8225. }
  8226. }
  8227. };
  8228. /*=========================
  8229. Pagination
  8230. ===========================*/
  8231. s.updatePagination = function () {
  8232. if (!s.params.pagination) return;
  8233. if (s.paginationContainer && s.paginationContainer.length > 0) {
  8234. var bulletsHTML = '';
  8235. var numberOfBullets = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  8236. for (var i = 0; i < numberOfBullets; i++) {
  8237. if (s.params.paginationBulletRender) {
  8238. bulletsHTML += s.params.paginationBulletRender(i, s.params.bulletClass);
  8239. }
  8240. else {
  8241. bulletsHTML += '<' + s.params.paginationElement+' class="' + s.params.bulletClass + '"></' + s.params.paginationElement + '>';
  8242. }
  8243. }
  8244. s.paginationContainer.html(bulletsHTML);
  8245. s.bullets = s.paginationContainer.find('.' + s.params.bulletClass);
  8246. if (s.params.paginationClickable && s.params.a11y && s.a11y) {
  8247. s.a11y.initPagination();
  8248. }
  8249. }
  8250. };
  8251. /*=========================
  8252. Common update method
  8253. ===========================*/
  8254. s.update = function (updateTranslate) {
  8255. s.updateContainerSize();
  8256. s.updateSlidesSize();
  8257. s.updateProgress();
  8258. s.updatePagination();
  8259. s.updateClasses();
  8260. if (s.params.scrollbar && s.scrollbar) {
  8261. s.scrollbar.set();
  8262. }
  8263. function forceSetTranslate() {
  8264. newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  8265. s.setWrapperTranslate(newTranslate);
  8266. s.updateActiveIndex();
  8267. s.updateClasses();
  8268. }
  8269. if (updateTranslate) {
  8270. var translated, newTranslate;
  8271. if (s.controller && s.controller.spline) {
  8272. s.controller.spline = undefined;
  8273. }
  8274. if (s.params.freeMode) {
  8275. forceSetTranslate();
  8276. if (s.params.autoHeight) {
  8277. s.updateAutoHeight();
  8278. }
  8279. }
  8280. else {
  8281. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  8282. translated = s.slideTo(s.slides.length - 1, 0, false, true);
  8283. }
  8284. else {
  8285. translated = s.slideTo(s.activeIndex, 0, false, true);
  8286. }
  8287. if (!translated) {
  8288. forceSetTranslate();
  8289. }
  8290. }
  8291. }
  8292. else if (s.params.autoHeight) {
  8293. s.updateAutoHeight();
  8294. }
  8295. };
  8296. /*=========================
  8297. Resize Handler
  8298. ===========================*/
  8299. s.onResize = function (forceUpdatePagination) {
  8300. //Breakpoints
  8301. if (s.params.breakpoints) {
  8302. s.setBreakpoint();
  8303. }
  8304. // Disable locks on resize
  8305. var allowSwipeToPrev = s.params.allowSwipeToPrev;
  8306. var allowSwipeToNext = s.params.allowSwipeToNext;
  8307. s.params.allowSwipeToPrev = s.params.allowSwipeToNext = true;
  8308. s.updateContainerSize();
  8309. s.updateSlidesSize();
  8310. if (s.params.slidesPerView === 'auto' || s.params.freeMode || forceUpdatePagination) s.updatePagination();
  8311. if (s.params.scrollbar && s.scrollbar) {
  8312. s.scrollbar.set();
  8313. }
  8314. if (s.controller && s.controller.spline) {
  8315. s.controller.spline = undefined;
  8316. }
  8317. if (s.params.freeMode) {
  8318. var newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  8319. s.setWrapperTranslate(newTranslate);
  8320. s.updateActiveIndex();
  8321. s.updateClasses();
  8322. if (s.params.autoHeight) {
  8323. s.updateAutoHeight();
  8324. }
  8325. }
  8326. else {
  8327. s.updateClasses();
  8328. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  8329. s.slideTo(s.slides.length - 1, 0, false, true);
  8330. }
  8331. else {
  8332. s.slideTo(s.activeIndex, 0, false, true);
  8333. }
  8334. }
  8335. // Return locks after resize
  8336. s.params.allowSwipeToPrev = allowSwipeToPrev;
  8337. s.params.allowSwipeToNext = allowSwipeToNext;
  8338. };
  8339. /*=========================
  8340. Events
  8341. ===========================*/
  8342. //Define Touch Events
  8343. var desktopEvents = ['mousedown', 'mousemove', 'mouseup'];
  8344. if (window.navigator.pointerEnabled) desktopEvents = ['pointerdown', 'pointermove', 'pointerup'];
  8345. else if (window.navigator.msPointerEnabled) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp'];
  8346. s.touchEvents = {
  8347. start : s.support.touch || !s.params.simulateTouch ? 'touchstart' : desktopEvents[0],
  8348. move : s.support.touch || !s.params.simulateTouch ? 'touchmove' : desktopEvents[1],
  8349. end : s.support.touch || !s.params.simulateTouch ? 'touchend' : desktopEvents[2]
  8350. };
  8351. // WP8 Touch Events Fix
  8352. if (window.navigator.pointerEnabled || window.navigator.msPointerEnabled) {
  8353. (s.params.touchEventsTarget === 'container' ? s.container : s.wrapper).addClass('swiper-wp8-' + s.params.direction);
  8354. }
  8355. // Attach/detach events
  8356. s.initEvents = function (detach) {
  8357. var actionDom = detach ? 'off' : 'on';
  8358. var action = detach ? 'removeEventListener' : 'addEventListener';
  8359. var touchEventsTarget = s.params.touchEventsTarget === 'container' ? s.container[0] : s.wrapper[0];
  8360. var target = s.support.touch ? touchEventsTarget : document;
  8361. var moveCapture = s.params.nested ? true : false;
  8362. //Touch Events
  8363. if (s.browser.ie) {
  8364. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  8365. target[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  8366. target[action](s.touchEvents.end, s.onTouchEnd, false);
  8367. }
  8368. else {
  8369. if (s.support.touch) {
  8370. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  8371. touchEventsTarget[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  8372. touchEventsTarget[action](s.touchEvents.end, s.onTouchEnd, false);
  8373. }
  8374. if (params.simulateTouch && !s.device.ios && !s.device.android) {
  8375. touchEventsTarget[action]('mousedown', s.onTouchStart, false);
  8376. document[action]('mousemove', s.onTouchMove, moveCapture);
  8377. document[action]('mouseup', s.onTouchEnd, false);
  8378. }
  8379. }
  8380. window[action]('resize', s.onResize);
  8381. // Next, Prev, Index
  8382. if (s.params.nextButton) {
  8383. $(s.params.nextButton)[actionDom]('click', s.onClickNext);
  8384. if (s.params.a11y && s.a11y) $(s.params.nextButton)[actionDom]('keydown', s.a11y.onEnterKey);
  8385. }
  8386. if (s.params.prevButton) {
  8387. $(s.params.prevButton)[actionDom]('click', s.onClickPrev);
  8388. if (s.params.a11y && s.a11y) $(s.params.prevButton)[actionDom]('keydown', s.a11y.onEnterKey);
  8389. }
  8390. if (s.params.pagination && s.params.paginationClickable) {
  8391. $(s.paginationContainer)[actionDom]('click', '.' + s.params.bulletClass, s.onClickIndex);
  8392. if (s.params.a11y && s.a11y) $(s.paginationContainer)[actionDom]('keydown', '.' + s.params.bulletClass, s.a11y.onEnterKey);
  8393. }
  8394. // Prevent Links Clicks
  8395. if (s.params.preventClicks || s.params.preventClicksPropagation) touchEventsTarget[action]('click', s.preventClicks, true);
  8396. };
  8397. s.attachEvents = function (detach) {
  8398. s.initEvents();
  8399. };
  8400. s.detachEvents = function () {
  8401. s.initEvents(true);
  8402. };
  8403. /*=========================
  8404. Handle Clicks
  8405. ===========================*/
  8406. // Prevent Clicks
  8407. s.allowClick = true;
  8408. s.preventClicks = function (e) {
  8409. if (!s.allowClick) {
  8410. if (s.params.preventClicks) e.preventDefault();
  8411. if (s.params.preventClicksPropagation && s.animating) {
  8412. e.stopPropagation();
  8413. e.stopImmediatePropagation();
  8414. }
  8415. }
  8416. };
  8417. // Clicks
  8418. s.onClickNext = function (e) {
  8419. e.preventDefault();
  8420. if (s.isEnd && !s.params.loop) return;
  8421. s.slideNext();
  8422. };
  8423. s.onClickPrev = function (e) {
  8424. e.preventDefault();
  8425. if (s.isBeginning && !s.params.loop) return;
  8426. s.slidePrev();
  8427. };
  8428. s.onClickIndex = function (e) {
  8429. e.preventDefault();
  8430. var index = $(this).index() * s.params.slidesPerGroup;
  8431. if (s.params.loop) index = index + s.loopedSlides;
  8432. s.slideTo(index);
  8433. };
  8434. /*=========================
  8435. Handle Touches
  8436. ===========================*/
  8437. function findElementInEvent(e, selector) {
  8438. var el = $(e.target);
  8439. if (!el.is(selector)) {
  8440. if (typeof selector === 'string') {
  8441. el = el.parents(selector);
  8442. }
  8443. else if (selector.nodeType) {
  8444. var found;
  8445. el.parents().each(function (index, _el) {
  8446. if (_el === selector) found = selector;
  8447. });
  8448. if (!found) return undefined;
  8449. else return selector;
  8450. }
  8451. }
  8452. if (el.length === 0) {
  8453. return undefined;
  8454. }
  8455. return el[0];
  8456. }
  8457. s.updateClickedSlide = function (e) {
  8458. var slide = findElementInEvent(e, '.' + s.params.slideClass);
  8459. var slideFound = false;
  8460. if (slide) {
  8461. for (var i = 0; i < s.slides.length; i++) {
  8462. if (s.slides[i] === slide) slideFound = true;
  8463. }
  8464. }
  8465. if (slide && slideFound) {
  8466. s.clickedSlide = slide;
  8467. s.clickedIndex = $(slide).index();
  8468. }
  8469. else {
  8470. s.clickedSlide = undefined;
  8471. s.clickedIndex = undefined;
  8472. return;
  8473. }
  8474. if (s.params.slideToClickedSlide && s.clickedIndex !== undefined && s.clickedIndex !== s.activeIndex) {
  8475. var slideToIndex = s.clickedIndex,
  8476. realIndex,
  8477. duplicatedSlides;
  8478. if (s.params.loop) {
  8479. if (s.animating) return;
  8480. realIndex = $(s.clickedSlide).attr('data-swiper-slide-index');
  8481. if (s.params.centeredSlides) {
  8482. if ((slideToIndex < s.loopedSlides - s.params.slidesPerView/2) || (slideToIndex > s.slides.length - s.loopedSlides + s.params.slidesPerView/2)) {
  8483. s.fixLoop();
  8484. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.swiper-slide-duplicate)').eq(0).index();
  8485. setTimeout(function () {
  8486. s.slideTo(slideToIndex);
  8487. }, 0);
  8488. }
  8489. else {
  8490. s.slideTo(slideToIndex);
  8491. }
  8492. }
  8493. else {
  8494. if (slideToIndex > s.slides.length - s.params.slidesPerView) {
  8495. s.fixLoop();
  8496. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.swiper-slide-duplicate)').eq(0).index();
  8497. setTimeout(function () {
  8498. s.slideTo(slideToIndex);
  8499. }, 0);
  8500. }
  8501. else {
  8502. s.slideTo(slideToIndex);
  8503. }
  8504. }
  8505. }
  8506. else {
  8507. s.slideTo(slideToIndex);
  8508. }
  8509. }
  8510. };
  8511. var isTouched,
  8512. isMoved,
  8513. allowTouchCallbacks,
  8514. touchStartTime,
  8515. isScrolling,
  8516. currentTranslate,
  8517. startTranslate,
  8518. allowThresholdMove,
  8519. // Form elements to match
  8520. formElements = 'input, select, textarea, button',
  8521. // Last click time
  8522. lastClickTime = Date.now(), clickTimeout,
  8523. //Velocities
  8524. velocities = [],
  8525. allowMomentumBounce;
  8526. // Animating Flag
  8527. s.animating = false;
  8528. // Touches information
  8529. s.touches = {
  8530. startX: 0,
  8531. startY: 0,
  8532. currentX: 0,
  8533. currentY: 0,
  8534. diff: 0
  8535. };
  8536. // Touch handlers
  8537. var isTouchEvent, startMoving;
  8538. s.onTouchStart = function (e) {
  8539. if (e.originalEvent) e = e.originalEvent;
  8540. isTouchEvent = e.type === 'touchstart';
  8541. if (!isTouchEvent && 'which' in e && e.which === 3) return;
  8542. if (s.params.noSwiping && findElementInEvent(e, '.' + s.params.noSwipingClass)) {
  8543. s.allowClick = true;
  8544. return;
  8545. }
  8546. if (s.params.swipeHandler) {
  8547. if (!findElementInEvent(e, s.params.swipeHandler)) return;
  8548. }
  8549. var startX = s.touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  8550. var startY = s.touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  8551. // Do NOT start if iOS edge swipe is detected. Otherwise iOS app (UIWebView) cannot swipe-to-go-back anymore
  8552. if(s.device.ios && s.params.iOSEdgeSwipeDetection && startX <= s.params.iOSEdgeSwipeThreshold) {
  8553. return;
  8554. }
  8555. isTouched = true;
  8556. isMoved = false;
  8557. allowTouchCallbacks = true;
  8558. isScrolling = undefined;
  8559. startMoving = undefined;
  8560. s.touches.startX = startX;
  8561. s.touches.startY = startY;
  8562. touchStartTime = Date.now();
  8563. s.allowClick = true;
  8564. s.updateContainerSize();
  8565. s.swipeDirection = undefined;
  8566. if (s.params.threshold > 0) allowThresholdMove = false;
  8567. if (e.type !== 'touchstart') {
  8568. var preventDefault = true;
  8569. if ($(e.target).is(formElements)) preventDefault = false;
  8570. if (document.activeElement && $(document.activeElement).is(formElements)) {
  8571. document.activeElement.blur();
  8572. }
  8573. if (preventDefault) {
  8574. e.preventDefault();
  8575. }
  8576. }
  8577. s.emit('onTouchStart', s, e);
  8578. };
  8579. s.onTouchMove = function (e) {
  8580. if (e.originalEvent) e = e.originalEvent;
  8581. if (isTouchEvent && e.type === 'mousemove') return;
  8582. if (e.preventedByNestedSwiper) return;
  8583. if (s.params.onlyExternal) {
  8584. // isMoved = true;
  8585. s.allowClick = false;
  8586. if (isTouched) {
  8587. s.touches.startX = s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  8588. s.touches.startY = s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  8589. touchStartTime = Date.now();
  8590. }
  8591. return;
  8592. }
  8593. if (isTouchEvent && document.activeElement) {
  8594. if (e.target === document.activeElement && $(e.target).is(formElements)) {
  8595. isMoved = true;
  8596. s.allowClick = false;
  8597. return;
  8598. }
  8599. }
  8600. if (allowTouchCallbacks) {
  8601. s.emit('onTouchMove', s, e);
  8602. }
  8603. if (e.targetTouches && e.targetTouches.length > 1) return;
  8604. s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  8605. s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  8606. if (typeof isScrolling === 'undefined') {
  8607. var touchAngle = Math.atan2(Math.abs(s.touches.currentY - s.touches.startY), Math.abs(s.touches.currentX - s.touches.startX)) * 180 / Math.PI;
  8608. isScrolling = isH() ? touchAngle > s.params.touchAngle : (90 - touchAngle > s.params.touchAngle);
  8609. }
  8610. if (isScrolling) {
  8611. s.emit('onTouchMoveOpposite', s, e);
  8612. }
  8613. if (typeof startMoving === 'undefined' && s.browser.ieTouch) {
  8614. if (s.touches.currentX !== s.touches.startX || s.touches.currentY !== s.touches.startY) {
  8615. startMoving = true;
  8616. }
  8617. }
  8618. if (!isTouched) return;
  8619. if (isScrolling) {
  8620. isTouched = false;
  8621. return;
  8622. }
  8623. if (!startMoving && s.browser.ieTouch) {
  8624. return;
  8625. }
  8626. s.allowClick = false;
  8627. s.emit('onSliderMove', s, e);
  8628. e.preventDefault();
  8629. if (s.params.touchMoveStopPropagation && !s.params.nested) {
  8630. e.stopPropagation();
  8631. }
  8632. if (!isMoved) {
  8633. if (params.loop) {
  8634. s.fixLoop();
  8635. }
  8636. startTranslate = s.getWrapperTranslate();
  8637. s.setWrapperTransition(0);
  8638. if (s.animating) {
  8639. s.wrapper.trigger('webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd msTransitionEnd');
  8640. }
  8641. if (s.params.autoplay && s.autoplaying) {
  8642. if (s.params.autoplayDisableOnInteraction) {
  8643. s.stopAutoplay();
  8644. }
  8645. else {
  8646. s.pauseAutoplay();
  8647. }
  8648. }
  8649. allowMomentumBounce = false;
  8650. //Grab Cursor
  8651. if (s.params.grabCursor) {
  8652. s.container[0].style.cursor = 'move';
  8653. s.container[0].style.cursor = '-webkit-grabbing';
  8654. s.container[0].style.cursor = '-moz-grabbin';
  8655. s.container[0].style.cursor = 'grabbing';
  8656. }
  8657. }
  8658. isMoved = true;
  8659. var diff = s.touches.diff = isH() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  8660. diff = diff * s.params.touchRatio;
  8661. if (s.rtl) diff = -diff;
  8662. s.swipeDirection = diff > 0 ? 'prev' : 'next';
  8663. currentTranslate = diff + startTranslate;
  8664. var disableParentSwiper = true;
  8665. if ((diff > 0 && currentTranslate > s.minTranslate())) {
  8666. disableParentSwiper = false;
  8667. if (s.params.resistance) currentTranslate = s.minTranslate() - 1 + Math.pow(-s.minTranslate() + startTranslate + diff, s.params.resistanceRatio);
  8668. }
  8669. else if (diff < 0 && currentTranslate < s.maxTranslate()) {
  8670. disableParentSwiper = false;
  8671. if (s.params.resistance) currentTranslate = s.maxTranslate() + 1 - Math.pow(s.maxTranslate() - startTranslate - diff, s.params.resistanceRatio);
  8672. }
  8673. if (disableParentSwiper) {
  8674. e.preventedByNestedSwiper = true;
  8675. }
  8676. // Directions locks
  8677. if (!s.params.allowSwipeToNext && s.swipeDirection === 'next' && currentTranslate < startTranslate) {
  8678. currentTranslate = startTranslate;
  8679. }
  8680. if (!s.params.allowSwipeToPrev && s.swipeDirection === 'prev' && currentTranslate > startTranslate) {
  8681. currentTranslate = startTranslate;
  8682. }
  8683. if (!s.params.followFinger) return;
  8684. // Threshold
  8685. if (s.params.threshold > 0) {
  8686. if (Math.abs(diff) > s.params.threshold || allowThresholdMove) {
  8687. if (!allowThresholdMove) {
  8688. allowThresholdMove = true;
  8689. s.touches.startX = s.touches.currentX;
  8690. s.touches.startY = s.touches.currentY;
  8691. currentTranslate = startTranslate;
  8692. s.touches.diff = isH() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  8693. return;
  8694. }
  8695. }
  8696. else {
  8697. currentTranslate = startTranslate;
  8698. return;
  8699. }
  8700. }
  8701. // Update active index in free mode
  8702. if (s.params.freeMode || s.params.watchSlidesProgress) {
  8703. s.updateActiveIndex();
  8704. }
  8705. if (s.params.freeMode) {
  8706. //Velocity
  8707. if (velocities.length === 0) {
  8708. velocities.push({
  8709. position: s.touches[isH() ? 'startX' : 'startY'],
  8710. time: touchStartTime
  8711. });
  8712. }
  8713. velocities.push({
  8714. position: s.touches[isH() ? 'currentX' : 'currentY'],
  8715. time: (new window.Date()).getTime()
  8716. });
  8717. }
  8718. // Update progress
  8719. s.updateProgress(currentTranslate);
  8720. // Update translate
  8721. s.setWrapperTranslate(currentTranslate);
  8722. };
  8723. s.onTouchEnd = function (e) {
  8724. if (e.originalEvent) e = e.originalEvent;
  8725. if (allowTouchCallbacks) {
  8726. s.emit('onTouchEnd', s, e);
  8727. }
  8728. allowTouchCallbacks = false;
  8729. if (!isTouched) return;
  8730. //Return Grab Cursor
  8731. if (s.params.grabCursor && isMoved && isTouched) {
  8732. s.container[0].style.cursor = 'move';
  8733. s.container[0].style.cursor = '-webkit-grab';
  8734. s.container[0].style.cursor = '-moz-grab';
  8735. s.container[0].style.cursor = 'grab';
  8736. }
  8737. // Time diff
  8738. var touchEndTime = Date.now();
  8739. var timeDiff = touchEndTime - touchStartTime;
  8740. // Tap, doubleTap, Click
  8741. if (s.allowClick) {
  8742. s.updateClickedSlide(e);
  8743. s.emit('onTap', s, e);
  8744. if (timeDiff < 300 && (touchEndTime - lastClickTime) > 300) {
  8745. if (clickTimeout) clearTimeout(clickTimeout);
  8746. clickTimeout = setTimeout(function () {
  8747. if (!s) return;
  8748. if (s.params.paginationHide && s.paginationContainer.length > 0 && !$(e.target).hasClass(s.params.bulletClass)) {
  8749. s.paginationContainer.toggleClass(s.params.paginationHiddenClass);
  8750. }
  8751. s.emit('onClick', s, e);
  8752. }, 300);
  8753. }
  8754. if (timeDiff < 300 && (touchEndTime - lastClickTime) < 300) {
  8755. if (clickTimeout) clearTimeout(clickTimeout);
  8756. s.emit('onDoubleTap', s, e);
  8757. }
  8758. }
  8759. lastClickTime = Date.now();
  8760. setTimeout(function () {
  8761. if (s) s.allowClick = true;
  8762. }, 0);
  8763. if (!isTouched || !isMoved || !s.swipeDirection || s.touches.diff === 0 || currentTranslate === startTranslate) {
  8764. isTouched = isMoved = false;
  8765. return;
  8766. }
  8767. isTouched = isMoved = false;
  8768. var currentPos;
  8769. if (s.params.followFinger) {
  8770. currentPos = s.rtl ? s.translate : -s.translate;
  8771. }
  8772. else {
  8773. currentPos = -currentTranslate;
  8774. }
  8775. if (s.params.freeMode) {
  8776. if (currentPos < -s.minTranslate()) {
  8777. s.slideTo(s.activeIndex);
  8778. return;
  8779. }
  8780. else if (currentPos > -s.maxTranslate()) {
  8781. if (s.slides.length < s.snapGrid.length) {
  8782. s.slideTo(s.snapGrid.length - 1);
  8783. }
  8784. else {
  8785. s.slideTo(s.slides.length - 1);
  8786. }
  8787. return;
  8788. }
  8789. if (s.params.freeModeMomentum) {
  8790. if (velocities.length > 1) {
  8791. var lastMoveEvent = velocities.pop(), velocityEvent = velocities.pop();
  8792. var distance = lastMoveEvent.position - velocityEvent.position;
  8793. var time = lastMoveEvent.time - velocityEvent.time;
  8794. s.velocity = distance / time;
  8795. s.velocity = s.velocity / 2;
  8796. if (Math.abs(s.velocity) < s.params.freeModeMinimumVelocity) {
  8797. s.velocity = 0;
  8798. }
  8799. // this implies that the user stopped moving a finger then released.
  8800. // There would be no events with distance zero, so the last event is stale.
  8801. if (time > 150 || (new window.Date().getTime() - lastMoveEvent.time) > 300) {
  8802. s.velocity = 0;
  8803. }
  8804. } else {
  8805. s.velocity = 0;
  8806. }
  8807. velocities.length = 0;
  8808. var momentumDuration = 1000 * s.params.freeModeMomentumRatio;
  8809. var momentumDistance = s.velocity * momentumDuration;
  8810. var newPosition = s.translate + momentumDistance;
  8811. if (s.rtl) newPosition = - newPosition;
  8812. var doBounce = false;
  8813. var afterBouncePosition;
  8814. var bounceAmount = Math.abs(s.velocity) * 20 * s.params.freeModeMomentumBounceRatio;
  8815. if (newPosition < s.maxTranslate()) {
  8816. if (s.params.freeModeMomentumBounce) {
  8817. if (newPosition + s.maxTranslate() < -bounceAmount) {
  8818. newPosition = s.maxTranslate() - bounceAmount;
  8819. }
  8820. afterBouncePosition = s.maxTranslate();
  8821. doBounce = true;
  8822. allowMomentumBounce = true;
  8823. }
  8824. else {
  8825. newPosition = s.maxTranslate();
  8826. }
  8827. }
  8828. else if (newPosition > s.minTranslate()) {
  8829. if (s.params.freeModeMomentumBounce) {
  8830. if (newPosition - s.minTranslate() > bounceAmount) {
  8831. newPosition = s.minTranslate() + bounceAmount;
  8832. }
  8833. afterBouncePosition = s.minTranslate();
  8834. doBounce = true;
  8835. allowMomentumBounce = true;
  8836. }
  8837. else {
  8838. newPosition = s.minTranslate();
  8839. }
  8840. }
  8841. else if (s.params.freeModeSticky) {
  8842. var j = 0,
  8843. nextSlide;
  8844. for (j = 0; j < s.snapGrid.length; j += 1) {
  8845. if (s.snapGrid[j] > -newPosition) {
  8846. nextSlide = j;
  8847. break;
  8848. }
  8849. }
  8850. if (Math.abs(s.snapGrid[nextSlide] - newPosition) < Math.abs(s.snapGrid[nextSlide - 1] - newPosition) || s.swipeDirection === 'next') {
  8851. newPosition = s.snapGrid[nextSlide];
  8852. } else {
  8853. newPosition = s.snapGrid[nextSlide - 1];
  8854. }
  8855. if (!s.rtl) newPosition = - newPosition;
  8856. }
  8857. //Fix duration
  8858. if (s.velocity !== 0) {
  8859. if (s.rtl) {
  8860. momentumDuration = Math.abs((-newPosition - s.translate) / s.velocity);
  8861. }
  8862. else {
  8863. momentumDuration = Math.abs((newPosition - s.translate) / s.velocity);
  8864. }
  8865. }
  8866. else if (s.params.freeModeSticky) {
  8867. s.slideReset();
  8868. return;
  8869. }
  8870. if (s.params.freeModeMomentumBounce && doBounce) {
  8871. s.updateProgress(afterBouncePosition);
  8872. s.setWrapperTransition(momentumDuration);
  8873. s.setWrapperTranslate(newPosition);
  8874. s.onTransitionStart();
  8875. s.animating = true;
  8876. s.wrapper.transitionEnd(function () {
  8877. if (!s || !allowMomentumBounce) return;
  8878. s.emit('onMomentumBounce', s);
  8879. s.setWrapperTransition(s.params.speed);
  8880. s.setWrapperTranslate(afterBouncePosition);
  8881. s.wrapper.transitionEnd(function () {
  8882. if (!s) return;
  8883. s.onTransitionEnd();
  8884. });
  8885. });
  8886. } else if (s.velocity) {
  8887. s.updateProgress(newPosition);
  8888. s.setWrapperTransition(momentumDuration);
  8889. s.setWrapperTranslate(newPosition);
  8890. s.onTransitionStart();
  8891. if (!s.animating) {
  8892. s.animating = true;
  8893. s.wrapper.transitionEnd(function () {
  8894. if (!s) return;
  8895. s.onTransitionEnd();
  8896. });
  8897. }
  8898. } else {
  8899. s.updateProgress(newPosition);
  8900. }
  8901. s.updateActiveIndex();
  8902. }
  8903. if (!s.params.freeModeMomentum || timeDiff >= s.params.longSwipesMs) {
  8904. s.updateProgress();
  8905. s.updateActiveIndex();
  8906. }
  8907. return;
  8908. }
  8909. // Find current slide
  8910. var i, stopIndex = 0, groupSize = s.slidesSizesGrid[0];
  8911. for (i = 0; i < s.slidesGrid.length; i += s.params.slidesPerGroup) {
  8912. if (typeof s.slidesGrid[i + s.params.slidesPerGroup] !== 'undefined') {
  8913. if (currentPos >= s.slidesGrid[i] && currentPos < s.slidesGrid[i + s.params.slidesPerGroup]) {
  8914. stopIndex = i;
  8915. groupSize = s.slidesGrid[i + s.params.slidesPerGroup] - s.slidesGrid[i];
  8916. }
  8917. }
  8918. else {
  8919. if (currentPos >= s.slidesGrid[i]) {
  8920. stopIndex = i;
  8921. groupSize = s.slidesGrid[s.slidesGrid.length - 1] - s.slidesGrid[s.slidesGrid.length - 2];
  8922. }
  8923. }
  8924. }
  8925. // Find current slide size
  8926. var ratio = (currentPos - s.slidesGrid[stopIndex]) / groupSize;
  8927. if (timeDiff > s.params.longSwipesMs) {
  8928. // Long touches
  8929. if (!s.params.longSwipes) {
  8930. s.slideTo(s.activeIndex);
  8931. return;
  8932. }
  8933. if (s.swipeDirection === 'next') {
  8934. if (ratio >= s.params.longSwipesRatio) s.slideTo(stopIndex + s.params.slidesPerGroup);
  8935. else s.slideTo(stopIndex);
  8936. }
  8937. if (s.swipeDirection === 'prev') {
  8938. if (ratio > (1 - s.params.longSwipesRatio)) s.slideTo(stopIndex + s.params.slidesPerGroup);
  8939. else s.slideTo(stopIndex);
  8940. }
  8941. }
  8942. else {
  8943. // Short swipes
  8944. if (!s.params.shortSwipes) {
  8945. s.slideTo(s.activeIndex);
  8946. return;
  8947. }
  8948. if (s.swipeDirection === 'next') {
  8949. s.slideTo(stopIndex + s.params.slidesPerGroup);
  8950. }
  8951. if (s.swipeDirection === 'prev') {
  8952. s.slideTo(stopIndex);
  8953. }
  8954. }
  8955. };
  8956. /*=========================
  8957. Transitions
  8958. ===========================*/
  8959. s._slideTo = function (slideIndex, speed) {
  8960. return s.slideTo(slideIndex, speed, true, true);
  8961. };
  8962. s.slideTo = function (slideIndex, speed, runCallbacks, internal) {
  8963. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  8964. if (typeof slideIndex === 'undefined') slideIndex = 0;
  8965. if (slideIndex < 0) slideIndex = 0;
  8966. s.snapIndex = Math.floor(slideIndex / s.params.slidesPerGroup);
  8967. if (s.snapIndex >= s.snapGrid.length) s.snapIndex = s.snapGrid.length - 1;
  8968. var translate = - s.snapGrid[s.snapIndex];
  8969. // Stop autoplay
  8970. if (s.params.autoplay && s.autoplaying) {
  8971. if (internal || !s.params.autoplayDisableOnInteraction) {
  8972. s.pauseAutoplay(speed);
  8973. }
  8974. else {
  8975. s.stopAutoplay();
  8976. }
  8977. }
  8978. // Update progress
  8979. s.updateProgress(translate);
  8980. // Normalize slideIndex
  8981. for (var i = 0; i < s.slidesGrid.length; i++) {
  8982. if (- Math.floor(translate * 100) >= Math.floor(s.slidesGrid[i] * 100)) {
  8983. slideIndex = i;
  8984. }
  8985. }
  8986. // Directions locks
  8987. if (!s.params.allowSwipeToNext && translate < s.translate && translate < s.minTranslate()) {
  8988. return false;
  8989. }
  8990. if (!s.params.allowSwipeToPrev && translate > s.translate && translate > s.maxTranslate()) {
  8991. if ((s.activeIndex || 0) !== slideIndex ) return false;
  8992. }
  8993. // Update Index
  8994. if (typeof speed === 'undefined') speed = s.params.speed;
  8995. s.previousIndex = s.activeIndex || 0;
  8996. s.activeIndex = slideIndex;
  8997. if ((s.rtl && -translate === s.translate) || (!s.rtl && translate === s.translate)) {
  8998. // Update Height
  8999. if (s.params.autoHeight) {
  9000. s.updateAutoHeight();
  9001. }
  9002. s.updateClasses();
  9003. if (s.params.effect !== 'slide') {
  9004. s.setWrapperTranslate(translate);
  9005. }
  9006. return false;
  9007. }
  9008. s.updateClasses();
  9009. s.onTransitionStart(runCallbacks);
  9010. if (speed === 0) {
  9011. s.setWrapperTranslate(translate);
  9012. s.setWrapperTransition(0);
  9013. s.onTransitionEnd(runCallbacks);
  9014. }
  9015. else {
  9016. s.setWrapperTranslate(translate);
  9017. s.setWrapperTransition(speed);
  9018. if (!s.animating) {
  9019. s.animating = true;
  9020. s.wrapper.transitionEnd(function () {
  9021. if (!s) return;
  9022. s.onTransitionEnd(runCallbacks);
  9023. });
  9024. }
  9025. }
  9026. return true;
  9027. };
  9028. s.onTransitionStart = function (runCallbacks) {
  9029. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  9030. if (s.params.autoHeight) {
  9031. s.updateAutoHeight();
  9032. }
  9033. if (s.lazy) s.lazy.onTransitionStart();
  9034. if (runCallbacks) {
  9035. s.emit('onTransitionStart', s);
  9036. if (s.activeIndex !== s.previousIndex) {
  9037. s.emit('onSlideChangeStart', s);
  9038. _scope.$emit("$ionicSlides.slideChangeStart", {
  9039. slider: s,
  9040. activeIndex: s.getSlideDataIndex(s.activeIndex),
  9041. previousIndex: s.getSlideDataIndex(s.previousIndex)
  9042. });
  9043. if (s.activeIndex > s.previousIndex) {
  9044. s.emit('onSlideNextStart', s);
  9045. }
  9046. else {
  9047. s.emit('onSlidePrevStart', s);
  9048. }
  9049. }
  9050. }
  9051. };
  9052. s.onTransitionEnd = function (runCallbacks) {
  9053. s.animating = false;
  9054. s.setWrapperTransition(0);
  9055. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  9056. if (s.lazy) s.lazy.onTransitionEnd();
  9057. if (runCallbacks) {
  9058. s.emit('onTransitionEnd', s);
  9059. if (s.activeIndex !== s.previousIndex) {
  9060. s.emit('onSlideChangeEnd', s);
  9061. _scope.$emit("$ionicSlides.slideChangeEnd", {
  9062. slider: s,
  9063. activeIndex: s.getSlideDataIndex(s.activeIndex),
  9064. previousIndex: s.getSlideDataIndex(s.previousIndex)
  9065. });
  9066. if (s.activeIndex > s.previousIndex) {
  9067. s.emit('onSlideNextEnd', s);
  9068. }
  9069. else {
  9070. s.emit('onSlidePrevEnd', s);
  9071. }
  9072. }
  9073. }
  9074. if (s.params.hashnav && s.hashnav) {
  9075. s.hashnav.setHash();
  9076. }
  9077. };
  9078. s.slideNext = function (runCallbacks, speed, internal) {
  9079. if (s.params.loop) {
  9080. if (s.animating) return false;
  9081. s.fixLoop();
  9082. var clientLeft = s.container[0].clientLeft;
  9083. return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  9084. }
  9085. else return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  9086. };
  9087. s._slideNext = function (speed) {
  9088. return s.slideNext(true, speed, true);
  9089. };
  9090. s.slidePrev = function (runCallbacks, speed, internal) {
  9091. if (s.params.loop) {
  9092. if (s.animating) return false;
  9093. s.fixLoop();
  9094. var clientLeft = s.container[0].clientLeft;
  9095. return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  9096. }
  9097. else return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  9098. };
  9099. s._slidePrev = function (speed) {
  9100. return s.slidePrev(true, speed, true);
  9101. };
  9102. s.slideReset = function (runCallbacks, speed, internal) {
  9103. return s.slideTo(s.activeIndex, speed, runCallbacks);
  9104. };
  9105. /*=========================
  9106. Translate/transition helpers
  9107. ===========================*/
  9108. s.setWrapperTransition = function (duration, byController) {
  9109. s.wrapper.transition(duration);
  9110. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  9111. s.effects[s.params.effect].setTransition(duration);
  9112. }
  9113. if (s.params.parallax && s.parallax) {
  9114. s.parallax.setTransition(duration);
  9115. }
  9116. if (s.params.scrollbar && s.scrollbar) {
  9117. s.scrollbar.setTransition(duration);
  9118. }
  9119. if (s.params.control && s.controller) {
  9120. s.controller.setTransition(duration, byController);
  9121. }
  9122. s.emit('onSetTransition', s, duration);
  9123. };
  9124. s.setWrapperTranslate = function (translate, updateActiveIndex, byController) {
  9125. var x = 0, y = 0, z = 0;
  9126. if (isH()) {
  9127. x = s.rtl ? -translate : translate;
  9128. }
  9129. else {
  9130. y = translate;
  9131. }
  9132. if (s.params.roundLengths) {
  9133. x = round(x);
  9134. y = round(y);
  9135. }
  9136. if (!s.params.virtualTranslate) {
  9137. if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)');
  9138. else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)');
  9139. }
  9140. s.translate = isH() ? x : y;
  9141. // Check if we need to update progress
  9142. var progress;
  9143. var translatesDiff = s.maxTranslate() - s.minTranslate();
  9144. if (translatesDiff === 0) {
  9145. progress = 0;
  9146. }
  9147. else {
  9148. progress = (translate - s.minTranslate()) / (translatesDiff);
  9149. }
  9150. if (progress !== s.progress) {
  9151. s.updateProgress(translate);
  9152. }
  9153. if (updateActiveIndex) s.updateActiveIndex();
  9154. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  9155. s.effects[s.params.effect].setTranslate(s.translate);
  9156. }
  9157. if (s.params.parallax && s.parallax) {
  9158. s.parallax.setTranslate(s.translate);
  9159. }
  9160. if (s.params.scrollbar && s.scrollbar) {
  9161. s.scrollbar.setTranslate(s.translate);
  9162. }
  9163. if (s.params.control && s.controller) {
  9164. s.controller.setTranslate(s.translate, byController);
  9165. }
  9166. s.emit('onSetTranslate', s, s.translate);
  9167. };
  9168. s.getTranslate = function (el, axis) {
  9169. var matrix, curTransform, curStyle, transformMatrix;
  9170. // automatic axis detection
  9171. if (typeof axis === 'undefined') {
  9172. axis = 'x';
  9173. }
  9174. if (s.params.virtualTranslate) {
  9175. return s.rtl ? -s.translate : s.translate;
  9176. }
  9177. curStyle = window.getComputedStyle(el, null);
  9178. if (window.WebKitCSSMatrix) {
  9179. curTransform = curStyle.transform || curStyle.webkitTransform;
  9180. if (curTransform.split(',').length > 6) {
  9181. curTransform = curTransform.split(', ').map(function(a){
  9182. return a.replace(',','.');
  9183. }).join(', ');
  9184. }
  9185. // Some old versions of Webkit choke when 'none' is passed; pass
  9186. // empty string instead in this case
  9187. transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
  9188. }
  9189. else {
  9190. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  9191. matrix = transformMatrix.toString().split(',');
  9192. }
  9193. if (axis === 'x') {
  9194. //Latest Chrome and webkits Fix
  9195. if (window.WebKitCSSMatrix)
  9196. curTransform = transformMatrix.m41;
  9197. //Crazy IE10 Matrix
  9198. else if (matrix.length === 16)
  9199. curTransform = parseFloat(matrix[12]);
  9200. //Normal Browsers
  9201. else
  9202. curTransform = parseFloat(matrix[4]);
  9203. }
  9204. if (axis === 'y') {
  9205. //Latest Chrome and webkits Fix
  9206. if (window.WebKitCSSMatrix)
  9207. curTransform = transformMatrix.m42;
  9208. //Crazy IE10 Matrix
  9209. else if (matrix.length === 16)
  9210. curTransform = parseFloat(matrix[13]);
  9211. //Normal Browsers
  9212. else
  9213. curTransform = parseFloat(matrix[5]);
  9214. }
  9215. if (s.rtl && curTransform) curTransform = -curTransform;
  9216. return curTransform || 0;
  9217. };
  9218. s.getWrapperTranslate = function (axis) {
  9219. if (typeof axis === 'undefined') {
  9220. axis = isH() ? 'x' : 'y';
  9221. }
  9222. return s.getTranslate(s.wrapper[0], axis);
  9223. };
  9224. /*=========================
  9225. Observer
  9226. ===========================*/
  9227. s.observers = [];
  9228. function initObserver(target, options) {
  9229. options = options || {};
  9230. // create an observer instance
  9231. var ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
  9232. var observer = new ObserverFunc(function (mutations) {
  9233. mutations.forEach(function (mutation) {
  9234. s.onResize(true);
  9235. s.emit('onObserverUpdate', s, mutation);
  9236. });
  9237. });
  9238. observer.observe(target, {
  9239. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  9240. childList: typeof options.childList === 'undefined' ? true : options.childList,
  9241. characterData: typeof options.characterData === 'undefined' ? true : options.characterData
  9242. });
  9243. s.observers.push(observer);
  9244. }
  9245. s.initObservers = function () {
  9246. if (s.params.observeParents) {
  9247. var containerParents = s.container.parents();
  9248. for (var i = 0; i < containerParents.length; i++) {
  9249. initObserver(containerParents[i]);
  9250. }
  9251. }
  9252. // Observe container
  9253. initObserver(s.container[0], {childList: false});
  9254. // Observe wrapper
  9255. initObserver(s.wrapper[0], {attributes: false});
  9256. };
  9257. s.disconnectObservers = function () {
  9258. for (var i = 0; i < s.observers.length; i++) {
  9259. s.observers[i].disconnect();
  9260. }
  9261. s.observers = [];
  9262. };
  9263. s.updateLoop = function(){
  9264. var currentSlide = s.slides.eq(s.activeIndex);
  9265. if ( angular.element(currentSlide).hasClass(s.params.slideDuplicateClass) ){
  9266. // we're on a duplicate, so slide to the non-duplicate
  9267. var swiperSlideIndex = angular.element(currentSlide).attr("data-swiper-slide-index");
  9268. var slides = s.wrapper.children('.' + s.params.slideClass);
  9269. for ( var i = 0; i < slides.length; i++ ){
  9270. if ( !angular.element(slides[i]).hasClass(s.params.slideDuplicateClass) && angular.element(slides[i]).attr("data-swiper-slide-index") === swiperSlideIndex ){
  9271. s.slideTo(i, 0, false, true);
  9272. break;
  9273. }
  9274. }
  9275. // if we needed to switch slides, we did that. So, now call the createLoop function internally
  9276. setTimeout(function(){
  9277. s.createLoop();
  9278. }, 50);
  9279. }
  9280. }
  9281. s.getSlideDataIndex = function(slideIndex){
  9282. // this is an Ionic custom function
  9283. // Swiper loops utilize duplicate DOM elements for slides when in a loop
  9284. // which means that we cannot rely on the actual slide index for our events
  9285. // because index 0 does not necessarily point to index 0
  9286. // and index n+1 does not necessarily point to the expected piece of data
  9287. // therefore, rather than using the actual slide index we should
  9288. // use the data index that swiper includes as an attribute on the dom elements
  9289. // because this is what will be meaningful to the consumer of our events
  9290. var slide = s.slides.eq(slideIndex);
  9291. var attributeIndex = angular.element(slide).attr("data-swiper-slide-index");
  9292. return parseInt(attributeIndex);
  9293. }
  9294. /*=========================
  9295. Loop
  9296. ===========================*/
  9297. // Create looped slides
  9298. s.createLoop = function () {
  9299. //console.log("Slider create loop method");
  9300. //var toRemove = s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass);
  9301. //angular.element(toRemove).remove();
  9302. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  9303. var slides = s.wrapper.children('.' + s.params.slideClass);
  9304. if(s.params.slidesPerView === 'auto' && !s.params.loopedSlides) s.params.loopedSlides = slides.length;
  9305. s.loopedSlides = parseInt(s.params.loopedSlides || s.params.slidesPerView, 10);
  9306. s.loopedSlides = s.loopedSlides + s.params.loopAdditionalSlides;
  9307. if (s.loopedSlides > slides.length) {
  9308. s.loopedSlides = slides.length;
  9309. }
  9310. var prependSlides = [], appendSlides = [], i, scope, newNode;
  9311. slides.each(function (index, el) {
  9312. var slide = $(this);
  9313. if (index < s.loopedSlides) appendSlides.push(el);
  9314. if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el);
  9315. slide.attr('data-swiper-slide-index', index);
  9316. });
  9317. for (i = 0; i < appendSlides.length; i++) {
  9318. newNode = angular.element(appendSlides[i]).clone().addClass(s.params.slideDuplicateClass);
  9319. newNode.removeAttr('ng-transclude');
  9320. newNode.removeAttr('ng-repeat');
  9321. scope = angular.element(appendSlides[i]).scope();
  9322. newNode = $compile(newNode)(scope);
  9323. angular.element(s.wrapper).append(newNode);
  9324. //s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  9325. }
  9326. for (i = prependSlides.length - 1; i >= 0; i--) {
  9327. //s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  9328. newNode = angular.element(prependSlides[i]).clone().addClass(s.params.slideDuplicateClass);
  9329. newNode.removeAttr('ng-transclude');
  9330. newNode.removeAttr('ng-repeat');
  9331. scope = angular.element(prependSlides[i]).scope();
  9332. newNode = $compile(newNode)(scope);
  9333. angular.element(s.wrapper).prepend(newNode);
  9334. }
  9335. };
  9336. s.destroyLoop = function () {
  9337. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  9338. s.slides.removeAttr('data-swiper-slide-index');
  9339. };
  9340. s.fixLoop = function () {
  9341. var newIndex;
  9342. //Fix For Negative Oversliding
  9343. if (s.activeIndex < s.loopedSlides) {
  9344. newIndex = s.slides.length - s.loopedSlides * 3 + s.activeIndex;
  9345. newIndex = newIndex + s.loopedSlides;
  9346. s.slideTo(newIndex, 0, false, true);
  9347. }
  9348. //Fix For Positive Oversliding
  9349. else if ((s.params.slidesPerView === 'auto' && s.activeIndex >= s.loopedSlides * 2) || (s.activeIndex > s.slides.length - s.params.slidesPerView * 2)) {
  9350. newIndex = -s.slides.length + s.activeIndex + s.loopedSlides;
  9351. newIndex = newIndex + s.loopedSlides;
  9352. s.slideTo(newIndex, 0, false, true);
  9353. }
  9354. };
  9355. /*=========================
  9356. Append/Prepend/Remove Slides
  9357. ===========================*/
  9358. s.appendSlide = function (slides) {
  9359. if (s.params.loop) {
  9360. s.destroyLoop();
  9361. }
  9362. if (typeof slides === 'object' && slides.length) {
  9363. for (var i = 0; i < slides.length; i++) {
  9364. if (slides[i]) s.wrapper.append(slides[i]);
  9365. }
  9366. }
  9367. else {
  9368. s.wrapper.append(slides);
  9369. }
  9370. if (s.params.loop) {
  9371. s.createLoop();
  9372. }
  9373. if (!(s.params.observer && s.support.observer)) {
  9374. s.update(true);
  9375. }
  9376. };
  9377. s.prependSlide = function (slides) {
  9378. if (s.params.loop) {
  9379. s.destroyLoop();
  9380. }
  9381. var newActiveIndex = s.activeIndex + 1;
  9382. if (typeof slides === 'object' && slides.length) {
  9383. for (var i = 0; i < slides.length; i++) {
  9384. if (slides[i]) s.wrapper.prepend(slides[i]);
  9385. }
  9386. newActiveIndex = s.activeIndex + slides.length;
  9387. }
  9388. else {
  9389. s.wrapper.prepend(slides);
  9390. }
  9391. if (s.params.loop) {
  9392. s.createLoop();
  9393. }
  9394. if (!(s.params.observer && s.support.observer)) {
  9395. s.update(true);
  9396. }
  9397. s.slideTo(newActiveIndex, 0, false);
  9398. };
  9399. s.removeSlide = function (slidesIndexes) {
  9400. if (s.params.loop) {
  9401. s.destroyLoop();
  9402. s.slides = s.wrapper.children('.' + s.params.slideClass);
  9403. }
  9404. var newActiveIndex = s.activeIndex,
  9405. indexToRemove;
  9406. if (typeof slidesIndexes === 'object' && slidesIndexes.length) {
  9407. for (var i = 0; i < slidesIndexes.length; i++) {
  9408. indexToRemove = slidesIndexes[i];
  9409. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  9410. if (indexToRemove < newActiveIndex) newActiveIndex--;
  9411. }
  9412. newActiveIndex = Math.max(newActiveIndex, 0);
  9413. }
  9414. else {
  9415. indexToRemove = slidesIndexes;
  9416. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  9417. if (indexToRemove < newActiveIndex) newActiveIndex--;
  9418. newActiveIndex = Math.max(newActiveIndex, 0);
  9419. }
  9420. if (s.params.loop) {
  9421. s.createLoop();
  9422. }
  9423. if (!(s.params.observer && s.support.observer)) {
  9424. s.update(true);
  9425. }
  9426. if (s.params.loop) {
  9427. s.slideTo(newActiveIndex + s.loopedSlides, 0, false);
  9428. }
  9429. else {
  9430. s.slideTo(newActiveIndex, 0, false);
  9431. }
  9432. };
  9433. s.removeAllSlides = function () {
  9434. var slidesIndexes = [];
  9435. for (var i = 0; i < s.slides.length; i++) {
  9436. slidesIndexes.push(i);
  9437. }
  9438. s.removeSlide(slidesIndexes);
  9439. };
  9440. /*=========================
  9441. Effects
  9442. ===========================*/
  9443. s.effects = {
  9444. fade: {
  9445. setTranslate: function () {
  9446. for (var i = 0; i < s.slides.length; i++) {
  9447. var slide = s.slides.eq(i);
  9448. var offset = slide[0].swiperSlideOffset;
  9449. var tx = -offset;
  9450. if (!s.params.virtualTranslate) tx = tx - s.translate;
  9451. var ty = 0;
  9452. if (!isH()) {
  9453. ty = tx;
  9454. tx = 0;
  9455. }
  9456. var slideOpacity = s.params.fade.crossFade ?
  9457. Math.max(1 - Math.abs(slide[0].progress), 0) :
  9458. 1 + Math.min(Math.max(slide[0].progress, -1), 0);
  9459. slide
  9460. .css({
  9461. opacity: slideOpacity
  9462. })
  9463. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px)');
  9464. }
  9465. },
  9466. setTransition: function (duration) {
  9467. s.slides.transition(duration);
  9468. if (s.params.virtualTranslate && duration !== 0) {
  9469. var eventTriggered = false;
  9470. s.slides.transitionEnd(function () {
  9471. if (eventTriggered) return;
  9472. if (!s) return;
  9473. eventTriggered = true;
  9474. s.animating = false;
  9475. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  9476. for (var i = 0; i < triggerEvents.length; i++) {
  9477. s.wrapper.trigger(triggerEvents[i]);
  9478. }
  9479. });
  9480. }
  9481. }
  9482. },
  9483. cube: {
  9484. setTranslate: function () {
  9485. var wrapperRotate = 0, cubeShadow;
  9486. if (s.params.cube.shadow) {
  9487. if (isH()) {
  9488. cubeShadow = s.wrapper.find('.swiper-cube-shadow');
  9489. if (cubeShadow.length === 0) {
  9490. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  9491. s.wrapper.append(cubeShadow);
  9492. }
  9493. cubeShadow.css({height: s.width + 'px'});
  9494. }
  9495. else {
  9496. cubeShadow = s.container.find('.swiper-cube-shadow');
  9497. if (cubeShadow.length === 0) {
  9498. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  9499. s.container.append(cubeShadow);
  9500. }
  9501. }
  9502. }
  9503. for (var i = 0; i < s.slides.length; i++) {
  9504. var slide = s.slides.eq(i);
  9505. var slideAngle = i * 90;
  9506. var round = Math.floor(slideAngle / 360);
  9507. if (s.rtl) {
  9508. slideAngle = -slideAngle;
  9509. round = Math.floor(-slideAngle / 360);
  9510. }
  9511. var progress = Math.max(Math.min(slide[0].progress, 1), -1);
  9512. var tx = 0, ty = 0, tz = 0;
  9513. if (i % 4 === 0) {
  9514. tx = - round * 4 * s.size;
  9515. tz = 0;
  9516. }
  9517. else if ((i - 1) % 4 === 0) {
  9518. tx = 0;
  9519. tz = - round * 4 * s.size;
  9520. }
  9521. else if ((i - 2) % 4 === 0) {
  9522. tx = s.size + round * 4 * s.size;
  9523. tz = s.size;
  9524. }
  9525. else if ((i - 3) % 4 === 0) {
  9526. tx = - s.size;
  9527. tz = 3 * s.size + s.size * 4 * round;
  9528. }
  9529. if (s.rtl) {
  9530. tx = -tx;
  9531. }
  9532. if (!isH()) {
  9533. ty = tx;
  9534. tx = 0;
  9535. }
  9536. var transform = 'rotateX(' + (isH() ? 0 : -slideAngle) + 'deg) rotateY(' + (isH() ? slideAngle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)';
  9537. if (progress <= 1 && progress > -1) {
  9538. wrapperRotate = i * 90 + progress * 90;
  9539. if (s.rtl) wrapperRotate = -i * 90 - progress * 90;
  9540. }
  9541. slide.transform(transform);
  9542. if (s.params.cube.slideShadows) {
  9543. //Set shadows
  9544. var shadowBefore = isH() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  9545. var shadowAfter = isH() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  9546. if (shadowBefore.length === 0) {
  9547. shadowBefore = $('<div class="swiper-slide-shadow-' + (isH() ? 'left' : 'top') + '"></div>');
  9548. slide.append(shadowBefore);
  9549. }
  9550. if (shadowAfter.length === 0) {
  9551. shadowAfter = $('<div class="swiper-slide-shadow-' + (isH() ? 'right' : 'bottom') + '"></div>');
  9552. slide.append(shadowAfter);
  9553. }
  9554. var shadowOpacity = slide[0].progress;
  9555. if (shadowBefore.length) shadowBefore[0].style.opacity = -slide[0].progress;
  9556. if (shadowAfter.length) shadowAfter[0].style.opacity = slide[0].progress;
  9557. }
  9558. }
  9559. s.wrapper.css({
  9560. '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  9561. '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  9562. '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  9563. 'transform-origin': '50% 50% -' + (s.size / 2) + 'px'
  9564. });
  9565. if (s.params.cube.shadow) {
  9566. if (isH()) {
  9567. cubeShadow.transform('translate3d(0px, ' + (s.width / 2 + s.params.cube.shadowOffset) + 'px, ' + (-s.width / 2) + 'px) rotateX(90deg) rotateZ(0deg) scale(' + (s.params.cube.shadowScale) + ')');
  9568. }
  9569. else {
  9570. var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
  9571. var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
  9572. var scale1 = s.params.cube.shadowScale,
  9573. scale2 = s.params.cube.shadowScale / multiplier,
  9574. offset = s.params.cube.shadowOffset;
  9575. cubeShadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotateX(-90deg)');
  9576. }
  9577. }
  9578. var zFactor = (s.isSafari || s.isUiWebView) ? (-s.size / 2) : 0;
  9579. s.wrapper.transform('translate3d(0px,0,' + zFactor + 'px) rotateX(' + (isH() ? 0 : wrapperRotate) + 'deg) rotateY(' + (isH() ? -wrapperRotate : 0) + 'deg)');
  9580. },
  9581. setTransition: function (duration) {
  9582. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  9583. if (s.params.cube.shadow && !isH()) {
  9584. s.container.find('.swiper-cube-shadow').transition(duration);
  9585. }
  9586. }
  9587. },
  9588. coverflow: {
  9589. setTranslate: function () {
  9590. var transform = s.translate;
  9591. var center = isH() ? -transform + s.width / 2 : -transform + s.height / 2;
  9592. var rotate = isH() ? s.params.coverflow.rotate: -s.params.coverflow.rotate;
  9593. var translate = s.params.coverflow.depth;
  9594. //Each slide offset from center
  9595. for (var i = 0, length = s.slides.length; i < length; i++) {
  9596. var slide = s.slides.eq(i);
  9597. var slideSize = s.slidesSizesGrid[i];
  9598. var slideOffset = slide[0].swiperSlideOffset;
  9599. var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier;
  9600. var rotateY = isH() ? rotate * offsetMultiplier : 0;
  9601. var rotateX = isH() ? 0 : rotate * offsetMultiplier;
  9602. // var rotateZ = 0
  9603. var translateZ = -translate * Math.abs(offsetMultiplier);
  9604. var translateY = isH() ? 0 : s.params.coverflow.stretch * (offsetMultiplier);
  9605. var translateX = isH() ? s.params.coverflow.stretch * (offsetMultiplier) : 0;
  9606. //Fix for ultra small values
  9607. if (Math.abs(translateX) < 0.001) translateX = 0;
  9608. if (Math.abs(translateY) < 0.001) translateY = 0;
  9609. if (Math.abs(translateZ) < 0.001) translateZ = 0;
  9610. if (Math.abs(rotateY) < 0.001) rotateY = 0;
  9611. if (Math.abs(rotateX) < 0.001) rotateX = 0;
  9612. var slideTransform = 'translate3d(' + translateX + 'px,' + translateY + 'px,' + translateZ + 'px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)';
  9613. slide.transform(slideTransform);
  9614. slide[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
  9615. if (s.params.coverflow.slideShadows) {
  9616. //Set shadows
  9617. var shadowBefore = isH() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  9618. var shadowAfter = isH() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  9619. if (shadowBefore.length === 0) {
  9620. shadowBefore = $('<div class="swiper-slide-shadow-' + (isH() ? 'left' : 'top') + '"></div>');
  9621. slide.append(shadowBefore);
  9622. }
  9623. if (shadowAfter.length === 0) {
  9624. shadowAfter = $('<div class="swiper-slide-shadow-' + (isH() ? 'right' : 'bottom') + '"></div>');
  9625. slide.append(shadowAfter);
  9626. }
  9627. if (shadowBefore.length) shadowBefore[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
  9628. if (shadowAfter.length) shadowAfter[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0;
  9629. }
  9630. }
  9631. //Set correct perspective for IE10
  9632. if (s.browser.ie) {
  9633. var ws = s.wrapper[0].style;
  9634. ws.perspectiveOrigin = center + 'px 50%';
  9635. }
  9636. },
  9637. setTransition: function (duration) {
  9638. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  9639. }
  9640. }
  9641. };
  9642. /*=========================
  9643. Images Lazy Loading
  9644. ===========================*/
  9645. s.lazy = {
  9646. initialImageLoaded: false,
  9647. loadImageInSlide: function (index, loadInDuplicate) {
  9648. if (typeof index === 'undefined') return;
  9649. if (typeof loadInDuplicate === 'undefined') loadInDuplicate = true;
  9650. if (s.slides.length === 0) return;
  9651. var slide = s.slides.eq(index);
  9652. var img = slide.find('.swiper-lazy:not(.swiper-lazy-loaded):not(.swiper-lazy-loading)');
  9653. if (slide.hasClass('swiper-lazy') && !slide.hasClass('swiper-lazy-loaded') && !slide.hasClass('swiper-lazy-loading')) {
  9654. img = img.add(slide[0]);
  9655. }
  9656. if (img.length === 0) return;
  9657. img.each(function () {
  9658. var _img = $(this);
  9659. _img.addClass('swiper-lazy-loading');
  9660. var background = _img.attr('data-background');
  9661. var src = _img.attr('data-src'),
  9662. srcset = _img.attr('data-srcset');
  9663. s.loadImage(_img[0], (src || background), srcset, false, function () {
  9664. if (background) {
  9665. _img.css('background-image', 'url(' + background + ')');
  9666. _img.removeAttr('data-background');
  9667. }
  9668. else {
  9669. if (srcset) {
  9670. _img.attr('srcset', srcset);
  9671. _img.removeAttr('data-srcset');
  9672. }
  9673. if (src) {
  9674. _img.attr('src', src);
  9675. _img.removeAttr('data-src');
  9676. }
  9677. }
  9678. _img.addClass('swiper-lazy-loaded').removeClass('swiper-lazy-loading');
  9679. slide.find('.swiper-lazy-preloader, .preloader').remove();
  9680. if (s.params.loop && loadInDuplicate) {
  9681. var slideOriginalIndex = slide.attr('data-swiper-slide-index');
  9682. if (slide.hasClass(s.params.slideDuplicateClass)) {
  9683. var originalSlide = s.wrapper.children('[data-swiper-slide-index="' + slideOriginalIndex + '"]:not(.' + s.params.slideDuplicateClass + ')');
  9684. s.lazy.loadImageInSlide(originalSlide.index(), false);
  9685. }
  9686. else {
  9687. var duplicatedSlide = s.wrapper.children('.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + slideOriginalIndex + '"]');
  9688. s.lazy.loadImageInSlide(duplicatedSlide.index(), false);
  9689. }
  9690. }
  9691. s.emit('onLazyImageReady', s, slide[0], _img[0]);
  9692. });
  9693. s.emit('onLazyImageLoad', s, slide[0], _img[0]);
  9694. });
  9695. },
  9696. load: function () {
  9697. var i;
  9698. if (s.params.watchSlidesVisibility) {
  9699. s.wrapper.children('.' + s.params.slideVisibleClass).each(function () {
  9700. s.lazy.loadImageInSlide($(this).index());
  9701. });
  9702. }
  9703. else {
  9704. if (s.params.slidesPerView > 1) {
  9705. for (i = s.activeIndex; i < s.activeIndex + s.params.slidesPerView ; i++) {
  9706. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  9707. }
  9708. }
  9709. else {
  9710. s.lazy.loadImageInSlide(s.activeIndex);
  9711. }
  9712. }
  9713. if (s.params.lazyLoadingInPrevNext) {
  9714. if (s.params.slidesPerView > 1) {
  9715. // Next Slides
  9716. for (i = s.activeIndex + s.params.slidesPerView; i < s.activeIndex + s.params.slidesPerView + s.params.slidesPerView; i++) {
  9717. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  9718. }
  9719. // Prev Slides
  9720. for (i = s.activeIndex - s.params.slidesPerView; i < s.activeIndex ; i++) {
  9721. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  9722. }
  9723. }
  9724. else {
  9725. var nextSlide = s.wrapper.children('.' + s.params.slideNextClass);
  9726. if (nextSlide.length > 0) s.lazy.loadImageInSlide(nextSlide.index());
  9727. var prevSlide = s.wrapper.children('.' + s.params.slidePrevClass);
  9728. if (prevSlide.length > 0) s.lazy.loadImageInSlide(prevSlide.index());
  9729. }
  9730. }
  9731. },
  9732. onTransitionStart: function () {
  9733. if (s.params.lazyLoading) {
  9734. if (s.params.lazyLoadingOnTransitionStart || (!s.params.lazyLoadingOnTransitionStart && !s.lazy.initialImageLoaded)) {
  9735. s.lazy.load();
  9736. }
  9737. }
  9738. },
  9739. onTransitionEnd: function () {
  9740. if (s.params.lazyLoading && !s.params.lazyLoadingOnTransitionStart) {
  9741. s.lazy.load();
  9742. }
  9743. }
  9744. };
  9745. /*=========================
  9746. Scrollbar
  9747. ===========================*/
  9748. s.scrollbar = {
  9749. isTouched: false,
  9750. setDragPosition: function (e) {
  9751. var sb = s.scrollbar;
  9752. var x = 0, y = 0;
  9753. var translate;
  9754. var pointerPosition = isH() ?
  9755. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageX : e.pageX || e.clientX) :
  9756. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageY : e.pageY || e.clientY) ;
  9757. var position = (pointerPosition) - sb.track.offset()[isH() ? 'left' : 'top'] - sb.dragSize / 2;
  9758. var positionMin = -s.minTranslate() * sb.moveDivider;
  9759. var positionMax = -s.maxTranslate() * sb.moveDivider;
  9760. if (position < positionMin) {
  9761. position = positionMin;
  9762. }
  9763. else if (position > positionMax) {
  9764. position = positionMax;
  9765. }
  9766. position = -position / sb.moveDivider;
  9767. s.updateProgress(position);
  9768. s.setWrapperTranslate(position, true);
  9769. },
  9770. dragStart: function (e) {
  9771. var sb = s.scrollbar;
  9772. sb.isTouched = true;
  9773. e.preventDefault();
  9774. e.stopPropagation();
  9775. sb.setDragPosition(e);
  9776. clearTimeout(sb.dragTimeout);
  9777. sb.track.transition(0);
  9778. if (s.params.scrollbarHide) {
  9779. sb.track.css('opacity', 1);
  9780. }
  9781. s.wrapper.transition(100);
  9782. sb.drag.transition(100);
  9783. s.emit('onScrollbarDragStart', s);
  9784. },
  9785. dragMove: function (e) {
  9786. var sb = s.scrollbar;
  9787. if (!sb.isTouched) return;
  9788. if (e.preventDefault) e.preventDefault();
  9789. else e.returnValue = false;
  9790. sb.setDragPosition(e);
  9791. s.wrapper.transition(0);
  9792. sb.track.transition(0);
  9793. sb.drag.transition(0);
  9794. s.emit('onScrollbarDragMove', s);
  9795. },
  9796. dragEnd: function (e) {
  9797. var sb = s.scrollbar;
  9798. if (!sb.isTouched) return;
  9799. sb.isTouched = false;
  9800. if (s.params.scrollbarHide) {
  9801. clearTimeout(sb.dragTimeout);
  9802. sb.dragTimeout = setTimeout(function () {
  9803. sb.track.css('opacity', 0);
  9804. sb.track.transition(400);
  9805. }, 1000);
  9806. }
  9807. s.emit('onScrollbarDragEnd', s);
  9808. if (s.params.scrollbarSnapOnRelease) {
  9809. s.slideReset();
  9810. }
  9811. },
  9812. enableDraggable: function () {
  9813. var sb = s.scrollbar;
  9814. var target = s.support.touch ? sb.track : document;
  9815. $(sb.track).on(s.touchEvents.start, sb.dragStart);
  9816. $(target).on(s.touchEvents.move, sb.dragMove);
  9817. $(target).on(s.touchEvents.end, sb.dragEnd);
  9818. },
  9819. disableDraggable: function () {
  9820. var sb = s.scrollbar;
  9821. var target = s.support.touch ? sb.track : document;
  9822. $(sb.track).off(s.touchEvents.start, sb.dragStart);
  9823. $(target).off(s.touchEvents.move, sb.dragMove);
  9824. $(target).off(s.touchEvents.end, sb.dragEnd);
  9825. },
  9826. set: function () {
  9827. if (!s.params.scrollbar) return;
  9828. var sb = s.scrollbar;
  9829. sb.track = $(s.params.scrollbar);
  9830. sb.drag = sb.track.find('.swiper-scrollbar-drag');
  9831. if (sb.drag.length === 0) {
  9832. sb.drag = $('<div class="swiper-scrollbar-drag"></div>');
  9833. sb.track.append(sb.drag);
  9834. }
  9835. sb.drag[0].style.width = '';
  9836. sb.drag[0].style.height = '';
  9837. sb.trackSize = isH() ? sb.track[0].offsetWidth : sb.track[0].offsetHeight;
  9838. sb.divider = s.size / s.virtualSize;
  9839. sb.moveDivider = sb.divider * (sb.trackSize / s.size);
  9840. sb.dragSize = sb.trackSize * sb.divider;
  9841. if (isH()) {
  9842. sb.drag[0].style.width = sb.dragSize + 'px';
  9843. }
  9844. else {
  9845. sb.drag[0].style.height = sb.dragSize + 'px';
  9846. }
  9847. if (sb.divider >= 1) {
  9848. sb.track[0].style.display = 'none';
  9849. }
  9850. else {
  9851. sb.track[0].style.display = '';
  9852. }
  9853. if (s.params.scrollbarHide) {
  9854. sb.track[0].style.opacity = 0;
  9855. }
  9856. },
  9857. setTranslate: function () {
  9858. if (!s.params.scrollbar) return;
  9859. var diff;
  9860. var sb = s.scrollbar;
  9861. var translate = s.translate || 0;
  9862. var newPos;
  9863. var newSize = sb.dragSize;
  9864. newPos = (sb.trackSize - sb.dragSize) * s.progress;
  9865. if (s.rtl && isH()) {
  9866. newPos = -newPos;
  9867. if (newPos > 0) {
  9868. newSize = sb.dragSize - newPos;
  9869. newPos = 0;
  9870. }
  9871. else if (-newPos + sb.dragSize > sb.trackSize) {
  9872. newSize = sb.trackSize + newPos;
  9873. }
  9874. }
  9875. else {
  9876. if (newPos < 0) {
  9877. newSize = sb.dragSize + newPos;
  9878. newPos = 0;
  9879. }
  9880. else if (newPos + sb.dragSize > sb.trackSize) {
  9881. newSize = sb.trackSize - newPos;
  9882. }
  9883. }
  9884. if (isH()) {
  9885. if (s.support.transforms3d) {
  9886. sb.drag.transform('translate3d(' + (newPos) + 'px, 0, 0)');
  9887. }
  9888. else {
  9889. sb.drag.transform('translateX(' + (newPos) + 'px)');
  9890. }
  9891. sb.drag[0].style.width = newSize + 'px';
  9892. }
  9893. else {
  9894. if (s.support.transforms3d) {
  9895. sb.drag.transform('translate3d(0px, ' + (newPos) + 'px, 0)');
  9896. }
  9897. else {
  9898. sb.drag.transform('translateY(' + (newPos) + 'px)');
  9899. }
  9900. sb.drag[0].style.height = newSize + 'px';
  9901. }
  9902. if (s.params.scrollbarHide) {
  9903. clearTimeout(sb.timeout);
  9904. sb.track[0].style.opacity = 1;
  9905. sb.timeout = setTimeout(function () {
  9906. sb.track[0].style.opacity = 0;
  9907. sb.track.transition(400);
  9908. }, 1000);
  9909. }
  9910. },
  9911. setTransition: function (duration) {
  9912. if (!s.params.scrollbar) return;
  9913. s.scrollbar.drag.transition(duration);
  9914. }
  9915. };
  9916. /*=========================
  9917. Controller
  9918. ===========================*/
  9919. s.controller = {
  9920. LinearSpline: function (x, y) {
  9921. this.x = x;
  9922. this.y = y;
  9923. this.lastIndex = x.length - 1;
  9924. // Given an x value (x2), return the expected y2 value:
  9925. // (x1,y1) is the known point before given value,
  9926. // (x3,y3) is the known point after given value.
  9927. var i1, i3;
  9928. var l = this.x.length;
  9929. this.interpolate = function (x2) {
  9930. if (!x2) return 0;
  9931. // Get the indexes of x1 and x3 (the array indexes before and after given x2):
  9932. i3 = binarySearch(this.x, x2);
  9933. i1 = i3 - 1;
  9934. // We have our indexes i1 & i3, so we can calculate already:
  9935. // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
  9936. return ((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1]) + this.y[i1];
  9937. };
  9938. var binarySearch = (function() {
  9939. var maxIndex, minIndex, guess;
  9940. return function(array, val) {
  9941. minIndex = -1;
  9942. maxIndex = array.length;
  9943. while (maxIndex - minIndex > 1)
  9944. if (array[guess = maxIndex + minIndex >> 1] <= val) {
  9945. minIndex = guess;
  9946. } else {
  9947. maxIndex = guess;
  9948. }
  9949. return maxIndex;
  9950. };
  9951. })();
  9952. },
  9953. //xxx: for now i will just save one spline function to to
  9954. getInterpolateFunction: function(c){
  9955. if(!s.controller.spline) s.controller.spline = s.params.loop ?
  9956. new s.controller.LinearSpline(s.slidesGrid, c.slidesGrid) :
  9957. new s.controller.LinearSpline(s.snapGrid, c.snapGrid);
  9958. },
  9959. setTranslate: function (translate, byController) {
  9960. var controlled = s.params.control;
  9961. var multiplier, controlledTranslate;
  9962. function setControlledTranslate(c) {
  9963. // this will create an Interpolate function based on the snapGrids
  9964. // x is the Grid of the scrolled scroller and y will be the controlled scroller
  9965. // it makes sense to create this only once and recall it for the interpolation
  9966. // the function does a lot of value caching for performance
  9967. translate = c.rtl && c.params.direction === 'horizontal' ? -s.translate : s.translate;
  9968. if (s.params.controlBy === 'slide') {
  9969. s.controller.getInterpolateFunction(c);
  9970. // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
  9971. // but it did not work out
  9972. controlledTranslate = -s.controller.spline.interpolate(-translate);
  9973. }
  9974. if(!controlledTranslate || s.params.controlBy === 'container'){
  9975. multiplier = (c.maxTranslate() - c.minTranslate()) / (s.maxTranslate() - s.minTranslate());
  9976. controlledTranslate = (translate - s.minTranslate()) * multiplier + c.minTranslate();
  9977. }
  9978. if (s.params.controlInverse) {
  9979. controlledTranslate = c.maxTranslate() - controlledTranslate;
  9980. }
  9981. c.updateProgress(controlledTranslate);
  9982. c.setWrapperTranslate(controlledTranslate, false, s);
  9983. c.updateActiveIndex();
  9984. }
  9985. if (s.isArray(controlled)) {
  9986. for (var i = 0; i < controlled.length; i++) {
  9987. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  9988. setControlledTranslate(controlled[i]);
  9989. }
  9990. }
  9991. }
  9992. else if (controlled instanceof Swiper && byController !== controlled) {
  9993. setControlledTranslate(controlled);
  9994. }
  9995. },
  9996. setTransition: function (duration, byController) {
  9997. var controlled = s.params.control;
  9998. var i;
  9999. function setControlledTransition(c) {
  10000. c.setWrapperTransition(duration, s);
  10001. if (duration !== 0) {
  10002. c.onTransitionStart();
  10003. c.wrapper.transitionEnd(function(){
  10004. if (!controlled) return;
  10005. if (c.params.loop && s.params.controlBy === 'slide') {
  10006. c.fixLoop();
  10007. }
  10008. c.onTransitionEnd();
  10009. });
  10010. }
  10011. }
  10012. if (s.isArray(controlled)) {
  10013. for (i = 0; i < controlled.length; i++) {
  10014. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  10015. setControlledTransition(controlled[i]);
  10016. }
  10017. }
  10018. }
  10019. else if (controlled instanceof Swiper && byController !== controlled) {
  10020. setControlledTransition(controlled);
  10021. }
  10022. }
  10023. };
  10024. /*=========================
  10025. Hash Navigation
  10026. ===========================*/
  10027. s.hashnav = {
  10028. init: function () {
  10029. if (!s.params.hashnav) return;
  10030. s.hashnav.initialized = true;
  10031. var hash = document.location.hash.replace('#', '');
  10032. if (!hash) return;
  10033. var speed = 0;
  10034. for (var i = 0, length = s.slides.length; i < length; i++) {
  10035. var slide = s.slides.eq(i);
  10036. var slideHash = slide.attr('data-hash');
  10037. if (slideHash === hash && !slide.hasClass(s.params.slideDuplicateClass)) {
  10038. var index = slide.index();
  10039. s.slideTo(index, speed, s.params.runCallbacksOnInit, true);
  10040. }
  10041. }
  10042. },
  10043. setHash: function () {
  10044. if (!s.hashnav.initialized || !s.params.hashnav) return;
  10045. document.location.hash = s.slides.eq(s.activeIndex).attr('data-hash') || '';
  10046. }
  10047. };
  10048. /*=========================
  10049. Keyboard Control
  10050. ===========================*/
  10051. function handleKeyboard(e) {
  10052. if (e.originalEvent) e = e.originalEvent; //jquery fix
  10053. var kc = e.keyCode || e.charCode;
  10054. // Directions locks
  10055. if (!s.params.allowSwipeToNext && (isH() && kc === 39 || !isH() && kc === 40)) {
  10056. return false;
  10057. }
  10058. if (!s.params.allowSwipeToPrev && (isH() && kc === 37 || !isH() && kc === 38)) {
  10059. return false;
  10060. }
  10061. if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
  10062. return;
  10063. }
  10064. if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) {
  10065. return;
  10066. }
  10067. if (kc === 37 || kc === 39 || kc === 38 || kc === 40) {
  10068. var inView = false;
  10069. //Check that swiper should be inside of visible area of window
  10070. if (s.container.parents('.swiper-slide').length > 0 && s.container.parents('.swiper-slide-active').length === 0) {
  10071. return;
  10072. }
  10073. var windowScroll = {
  10074. left: window.pageXOffset,
  10075. top: window.pageYOffset
  10076. };
  10077. var windowWidth = window.innerWidth;
  10078. var windowHeight = window.innerHeight;
  10079. var swiperOffset = s.container.offset();
  10080. if (s.rtl) swiperOffset.left = swiperOffset.left - s.container[0].scrollLeft;
  10081. var swiperCoord = [
  10082. [swiperOffset.left, swiperOffset.top],
  10083. [swiperOffset.left + s.width, swiperOffset.top],
  10084. [swiperOffset.left, swiperOffset.top + s.height],
  10085. [swiperOffset.left + s.width, swiperOffset.top + s.height]
  10086. ];
  10087. for (var i = 0; i < swiperCoord.length; i++) {
  10088. var point = swiperCoord[i];
  10089. if (
  10090. point[0] >= windowScroll.left && point[0] <= windowScroll.left + windowWidth &&
  10091. point[1] >= windowScroll.top && point[1] <= windowScroll.top + windowHeight
  10092. ) {
  10093. inView = true;
  10094. }
  10095. }
  10096. if (!inView) return;
  10097. }
  10098. if (isH()) {
  10099. if (kc === 37 || kc === 39) {
  10100. if (e.preventDefault) e.preventDefault();
  10101. else e.returnValue = false;
  10102. }
  10103. if ((kc === 39 && !s.rtl) || (kc === 37 && s.rtl)) s.slideNext();
  10104. if ((kc === 37 && !s.rtl) || (kc === 39 && s.rtl)) s.slidePrev();
  10105. }
  10106. else {
  10107. if (kc === 38 || kc === 40) {
  10108. if (e.preventDefault) e.preventDefault();
  10109. else e.returnValue = false;
  10110. }
  10111. if (kc === 40) s.slideNext();
  10112. if (kc === 38) s.slidePrev();
  10113. }
  10114. }
  10115. s.disableKeyboardControl = function () {
  10116. s.params.keyboardControl = false;
  10117. $(document).off('keydown', handleKeyboard);
  10118. };
  10119. s.enableKeyboardControl = function () {
  10120. s.params.keyboardControl = true;
  10121. $(document).on('keydown', handleKeyboard);
  10122. };
  10123. /*=========================
  10124. Mousewheel Control
  10125. ===========================*/
  10126. s.mousewheel = {
  10127. event: false,
  10128. lastScrollTime: (new window.Date()).getTime()
  10129. };
  10130. if (s.params.mousewheelControl) {
  10131. try {
  10132. new window.WheelEvent('wheel');
  10133. s.mousewheel.event = 'wheel';
  10134. } catch (e) {}
  10135. if (!s.mousewheel.event && document.onmousewheel !== undefined) {
  10136. s.mousewheel.event = 'mousewheel';
  10137. }
  10138. if (!s.mousewheel.event) {
  10139. s.mousewheel.event = 'DOMMouseScroll';
  10140. }
  10141. }
  10142. function handleMousewheel(e) {
  10143. if (e.originalEvent) e = e.originalEvent; //jquery fix
  10144. var we = s.mousewheel.event;
  10145. var delta = 0;
  10146. var rtlFactor = s.rtl ? -1 : 1;
  10147. //Opera & IE
  10148. if (e.detail) delta = -e.detail;
  10149. //WebKits
  10150. else if (we === 'mousewheel') {
  10151. if (s.params.mousewheelForceToAxis) {
  10152. if (isH()) {
  10153. if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) delta = e.wheelDeltaX * rtlFactor;
  10154. else return;
  10155. }
  10156. else {
  10157. if (Math.abs(e.wheelDeltaY) > Math.abs(e.wheelDeltaX)) delta = e.wheelDeltaY;
  10158. else return;
  10159. }
  10160. }
  10161. else {
  10162. delta = Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY) ? - e.wheelDeltaX * rtlFactor : - e.wheelDeltaY;
  10163. }
  10164. }
  10165. //Old FireFox
  10166. else if (we === 'DOMMouseScroll') delta = -e.detail;
  10167. //New FireFox
  10168. else if (we === 'wheel') {
  10169. if (s.params.mousewheelForceToAxis) {
  10170. if (isH()) {
  10171. if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = -e.deltaX * rtlFactor;
  10172. else return;
  10173. }
  10174. else {
  10175. if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) delta = -e.deltaY;
  10176. else return;
  10177. }
  10178. }
  10179. else {
  10180. delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? - e.deltaX * rtlFactor : - e.deltaY;
  10181. }
  10182. }
  10183. if (delta === 0) return;
  10184. if (s.params.mousewheelInvert) delta = -delta;
  10185. if (!s.params.freeMode) {
  10186. if ((new window.Date()).getTime() - s.mousewheel.lastScrollTime > 60) {
  10187. if (delta < 0) {
  10188. if ((!s.isEnd || s.params.loop) && !s.animating) s.slideNext();
  10189. else if (s.params.mousewheelReleaseOnEdges) return true;
  10190. }
  10191. else {
  10192. if ((!s.isBeginning || s.params.loop) && !s.animating) s.slidePrev();
  10193. else if (s.params.mousewheelReleaseOnEdges) return true;
  10194. }
  10195. }
  10196. s.mousewheel.lastScrollTime = (new window.Date()).getTime();
  10197. }
  10198. else {
  10199. //Freemode or scrollContainer:
  10200. var position = s.getWrapperTranslate() + delta * s.params.mousewheelSensitivity;
  10201. var wasBeginning = s.isBeginning,
  10202. wasEnd = s.isEnd;
  10203. if (position >= s.minTranslate()) position = s.minTranslate();
  10204. if (position <= s.maxTranslate()) position = s.maxTranslate();
  10205. s.setWrapperTransition(0);
  10206. s.setWrapperTranslate(position);
  10207. s.updateProgress();
  10208. s.updateActiveIndex();
  10209. if (!wasBeginning && s.isBeginning || !wasEnd && s.isEnd) {
  10210. s.updateClasses();
  10211. }
  10212. if (s.params.freeModeSticky) {
  10213. clearTimeout(s.mousewheel.timeout);
  10214. s.mousewheel.timeout = setTimeout(function () {
  10215. s.slideReset();
  10216. }, 300);
  10217. }
  10218. // Return page scroll on edge positions
  10219. if (position === 0 || position === s.maxTranslate()) return;
  10220. }
  10221. if (s.params.autoplay) s.stopAutoplay();
  10222. if (e.preventDefault) e.preventDefault();
  10223. else e.returnValue = false;
  10224. return false;
  10225. }
  10226. s.disableMousewheelControl = function () {
  10227. if (!s.mousewheel.event) return false;
  10228. s.container.off(s.mousewheel.event, handleMousewheel);
  10229. return true;
  10230. };
  10231. s.enableMousewheelControl = function () {
  10232. if (!s.mousewheel.event) return false;
  10233. s.container.on(s.mousewheel.event, handleMousewheel);
  10234. return true;
  10235. };
  10236. /*=========================
  10237. Parallax
  10238. ===========================*/
  10239. function setParallaxTransform(el, progress) {
  10240. el = $(el);
  10241. var p, pX, pY;
  10242. var rtlFactor = s.rtl ? -1 : 1;
  10243. p = el.attr('data-swiper-parallax') || '0';
  10244. pX = el.attr('data-swiper-parallax-x');
  10245. pY = el.attr('data-swiper-parallax-y');
  10246. if (pX || pY) {
  10247. pX = pX || '0';
  10248. pY = pY || '0';
  10249. }
  10250. else {
  10251. if (isH()) {
  10252. pX = p;
  10253. pY = '0';
  10254. }
  10255. else {
  10256. pY = p;
  10257. pX = '0';
  10258. }
  10259. }
  10260. if ((pX).indexOf('%') >= 0) {
  10261. pX = parseInt(pX, 10) * progress * rtlFactor + '%';
  10262. }
  10263. else {
  10264. pX = pX * progress * rtlFactor + 'px' ;
  10265. }
  10266. if ((pY).indexOf('%') >= 0) {
  10267. pY = parseInt(pY, 10) * progress + '%';
  10268. }
  10269. else {
  10270. pY = pY * progress + 'px' ;
  10271. }
  10272. el.transform('translate3d(' + pX + ', ' + pY + ',0px)');
  10273. }
  10274. s.parallax = {
  10275. setTranslate: function () {
  10276. s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  10277. setParallaxTransform(this, s.progress);
  10278. });
  10279. s.slides.each(function () {
  10280. var slide = $(this);
  10281. slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () {
  10282. var progress = Math.min(Math.max(slide[0].progress, -1), 1);
  10283. setParallaxTransform(this, progress);
  10284. });
  10285. });
  10286. },
  10287. setTransition: function (duration) {
  10288. if (typeof duration === 'undefined') duration = s.params.speed;
  10289. s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  10290. var el = $(this);
  10291. var parallaxDuration = parseInt(el.attr('data-swiper-parallax-duration'), 10) || duration;
  10292. if (duration === 0) parallaxDuration = 0;
  10293. el.transition(parallaxDuration);
  10294. });
  10295. }
  10296. };
  10297. /*=========================
  10298. Plugins API. Collect all and init all plugins
  10299. ===========================*/
  10300. s._plugins = [];
  10301. for (var plugin in s.plugins) {
  10302. var p = s.plugins[plugin](s, s.params[plugin]);
  10303. if (p) s._plugins.push(p);
  10304. }
  10305. // Method to call all plugins event/method
  10306. s.callPlugins = function (eventName) {
  10307. for (var i = 0; i < s._plugins.length; i++) {
  10308. if (eventName in s._plugins[i]) {
  10309. s._plugins[i][eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  10310. }
  10311. }
  10312. };
  10313. /*=========================
  10314. Events/Callbacks/Plugins Emitter
  10315. ===========================*/
  10316. function normalizeEventName (eventName) {
  10317. if (eventName.indexOf('on') !== 0) {
  10318. if (eventName[0] !== eventName[0].toUpperCase()) {
  10319. eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1);
  10320. }
  10321. else {
  10322. eventName = 'on' + eventName;
  10323. }
  10324. }
  10325. return eventName;
  10326. }
  10327. s.emitterEventListeners = {
  10328. };
  10329. s.emit = function (eventName) {
  10330. // Trigger callbacks
  10331. if (s.params[eventName]) {
  10332. s.params[eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  10333. }
  10334. var i;
  10335. // Trigger events
  10336. if (s.emitterEventListeners[eventName]) {
  10337. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  10338. s.emitterEventListeners[eventName][i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  10339. }
  10340. }
  10341. // Trigger plugins
  10342. if (s.callPlugins) s.callPlugins(eventName, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  10343. };
  10344. s.on = function (eventName, handler) {
  10345. eventName = normalizeEventName(eventName);
  10346. if (!s.emitterEventListeners[eventName]) s.emitterEventListeners[eventName] = [];
  10347. s.emitterEventListeners[eventName].push(handler);
  10348. return s;
  10349. };
  10350. s.off = function (eventName, handler) {
  10351. var i;
  10352. eventName = normalizeEventName(eventName);
  10353. if (typeof handler === 'undefined') {
  10354. // Remove all handlers for such event
  10355. s.emitterEventListeners[eventName] = [];
  10356. return s;
  10357. }
  10358. if (!s.emitterEventListeners[eventName] || s.emitterEventListeners[eventName].length === 0) return;
  10359. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  10360. if(s.emitterEventListeners[eventName][i] === handler) s.emitterEventListeners[eventName].splice(i, 1);
  10361. }
  10362. return s;
  10363. };
  10364. s.once = function (eventName, handler) {
  10365. eventName = normalizeEventName(eventName);
  10366. var _handler = function () {
  10367. handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
  10368. s.off(eventName, _handler);
  10369. };
  10370. s.on(eventName, _handler);
  10371. return s;
  10372. };
  10373. // Accessibility tools
  10374. s.a11y = {
  10375. makeFocusable: function ($el) {
  10376. $el.attr('tabIndex', '0');
  10377. return $el;
  10378. },
  10379. addRole: function ($el, role) {
  10380. $el.attr('role', role);
  10381. return $el;
  10382. },
  10383. addLabel: function ($el, label) {
  10384. $el.attr('aria-label', label);
  10385. return $el;
  10386. },
  10387. disable: function ($el) {
  10388. $el.attr('aria-disabled', true);
  10389. return $el;
  10390. },
  10391. enable: function ($el) {
  10392. $el.attr('aria-disabled', false);
  10393. return $el;
  10394. },
  10395. onEnterKey: function (event) {
  10396. if (event.keyCode !== 13) return;
  10397. if ($(event.target).is(s.params.nextButton)) {
  10398. s.onClickNext(event);
  10399. if (s.isEnd) {
  10400. s.a11y.notify(s.params.lastSlideMessage);
  10401. }
  10402. else {
  10403. s.a11y.notify(s.params.nextSlideMessage);
  10404. }
  10405. }
  10406. else if ($(event.target).is(s.params.prevButton)) {
  10407. s.onClickPrev(event);
  10408. if (s.isBeginning) {
  10409. s.a11y.notify(s.params.firstSlideMessage);
  10410. }
  10411. else {
  10412. s.a11y.notify(s.params.prevSlideMessage);
  10413. }
  10414. }
  10415. if ($(event.target).is('.' + s.params.bulletClass)) {
  10416. $(event.target)[0].click();
  10417. }
  10418. },
  10419. liveRegion: $('<span class="swiper-notification" aria-live="assertive" aria-atomic="true"></span>'),
  10420. notify: function (message) {
  10421. var notification = s.a11y.liveRegion;
  10422. if (notification.length === 0) return;
  10423. notification.html('');
  10424. notification.html(message);
  10425. },
  10426. init: function () {
  10427. // Setup accessibility
  10428. if (s.params.nextButton) {
  10429. var nextButton = $(s.params.nextButton);
  10430. s.a11y.makeFocusable(nextButton);
  10431. s.a11y.addRole(nextButton, 'button');
  10432. s.a11y.addLabel(nextButton, s.params.nextSlideMessage);
  10433. }
  10434. if (s.params.prevButton) {
  10435. var prevButton = $(s.params.prevButton);
  10436. s.a11y.makeFocusable(prevButton);
  10437. s.a11y.addRole(prevButton, 'button');
  10438. s.a11y.addLabel(prevButton, s.params.prevSlideMessage);
  10439. }
  10440. $(s.container).append(s.a11y.liveRegion);
  10441. },
  10442. initPagination: function () {
  10443. if (s.params.pagination && s.params.paginationClickable && s.bullets && s.bullets.length) {
  10444. s.bullets.each(function () {
  10445. var bullet = $(this);
  10446. s.a11y.makeFocusable(bullet);
  10447. s.a11y.addRole(bullet, 'button');
  10448. s.a11y.addLabel(bullet, s.params.paginationBulletMessage.replace(/{{index}}/, bullet.index() + 1));
  10449. });
  10450. }
  10451. },
  10452. destroy: function () {
  10453. if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove();
  10454. }
  10455. };
  10456. /*=========================
  10457. Init/Destroy
  10458. ===========================*/
  10459. s.init = function () {
  10460. if (s.params.loop) s.createLoop();
  10461. s.updateContainerSize();
  10462. s.updateSlidesSize();
  10463. s.updatePagination();
  10464. if (s.params.scrollbar && s.scrollbar) {
  10465. s.scrollbar.set();
  10466. if (s.params.scrollbarDraggable) {
  10467. s.scrollbar.enableDraggable();
  10468. }
  10469. }
  10470. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  10471. if (!s.params.loop) s.updateProgress();
  10472. s.effects[s.params.effect].setTranslate();
  10473. }
  10474. if (s.params.loop) {
  10475. s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit);
  10476. }
  10477. else {
  10478. s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit);
  10479. if (s.params.initialSlide === 0) {
  10480. if (s.parallax && s.params.parallax) s.parallax.setTranslate();
  10481. if (s.lazy && s.params.lazyLoading) {
  10482. s.lazy.load();
  10483. s.lazy.initialImageLoaded = true;
  10484. }
  10485. }
  10486. }
  10487. s.attachEvents();
  10488. if (s.params.observer && s.support.observer) {
  10489. s.initObservers();
  10490. }
  10491. if (s.params.preloadImages && !s.params.lazyLoading) {
  10492. s.preloadImages();
  10493. }
  10494. if (s.params.autoplay) {
  10495. s.startAutoplay();
  10496. }
  10497. if (s.params.keyboardControl) {
  10498. if (s.enableKeyboardControl) s.enableKeyboardControl();
  10499. }
  10500. if (s.params.mousewheelControl) {
  10501. if (s.enableMousewheelControl) s.enableMousewheelControl();
  10502. }
  10503. if (s.params.hashnav) {
  10504. if (s.hashnav) s.hashnav.init();
  10505. }
  10506. if (s.params.a11y && s.a11y) s.a11y.init();
  10507. s.emit('onInit', s);
  10508. };
  10509. // Cleanup dynamic styles
  10510. s.cleanupStyles = function () {
  10511. // Container
  10512. s.container.removeClass(s.classNames.join(' ')).removeAttr('style');
  10513. // Wrapper
  10514. s.wrapper.removeAttr('style');
  10515. // Slides
  10516. if (s.slides && s.slides.length) {
  10517. s.slides
  10518. .removeClass([
  10519. s.params.slideVisibleClass,
  10520. s.params.slideActiveClass,
  10521. s.params.slideNextClass,
  10522. s.params.slidePrevClass
  10523. ].join(' '))
  10524. .removeAttr('style')
  10525. .removeAttr('data-swiper-column')
  10526. .removeAttr('data-swiper-row');
  10527. }
  10528. // Pagination/Bullets
  10529. if (s.paginationContainer && s.paginationContainer.length) {
  10530. s.paginationContainer.removeClass(s.params.paginationHiddenClass);
  10531. }
  10532. if (s.bullets && s.bullets.length) {
  10533. s.bullets.removeClass(s.params.bulletActiveClass);
  10534. }
  10535. // Buttons
  10536. if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  10537. if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  10538. // Scrollbar
  10539. if (s.params.scrollbar && s.scrollbar) {
  10540. if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style');
  10541. if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style');
  10542. }
  10543. };
  10544. // Destroy
  10545. s.destroy = function (deleteInstance, cleanupStyles) {
  10546. // Detach evebts
  10547. s.detachEvents();
  10548. // Stop autoplay
  10549. s.stopAutoplay();
  10550. // Disable draggable
  10551. if (s.params.scrollbar && s.scrollbar) {
  10552. if (s.params.scrollbarDraggable) {
  10553. s.scrollbar.disableDraggable();
  10554. }
  10555. }
  10556. // Destroy loop
  10557. if (s.params.loop) {
  10558. s.destroyLoop();
  10559. }
  10560. // Cleanup styles
  10561. if (cleanupStyles) {
  10562. s.cleanupStyles();
  10563. }
  10564. // Disconnect observer
  10565. s.disconnectObservers();
  10566. // Disable keyboard/mousewheel
  10567. if (s.params.keyboardControl) {
  10568. if (s.disableKeyboardControl) s.disableKeyboardControl();
  10569. }
  10570. if (s.params.mousewheelControl) {
  10571. if (s.disableMousewheelControl) s.disableMousewheelControl();
  10572. }
  10573. // Disable a11y
  10574. if (s.params.a11y && s.a11y) s.a11y.destroy();
  10575. // Destroy callback
  10576. s.emit('onDestroy');
  10577. // Delete instance
  10578. if (deleteInstance !== false) s = null;
  10579. };
  10580. s.init();
  10581. // Return swiper instance
  10582. return s;
  10583. };
  10584. /*==================================================
  10585. Prototype
  10586. ====================================================*/
  10587. Swiper.prototype = {
  10588. isSafari: (function () {
  10589. var ua = navigator.userAgent.toLowerCase();
  10590. return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0);
  10591. })(),
  10592. isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent),
  10593. isArray: function (arr) {
  10594. return Object.prototype.toString.apply(arr) === '[object Array]';
  10595. },
  10596. /*==================================================
  10597. Browser
  10598. ====================================================*/
  10599. browser: {
  10600. ie: window.navigator.pointerEnabled || window.navigator.msPointerEnabled,
  10601. ieTouch: (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 1) || (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 1)
  10602. },
  10603. /*==================================================
  10604. Devices
  10605. ====================================================*/
  10606. device: (function () {
  10607. var ua = navigator.userAgent;
  10608. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  10609. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  10610. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  10611. var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  10612. return {
  10613. ios: ipad || iphone || ipod,
  10614. android: android
  10615. };
  10616. })(),
  10617. /*==================================================
  10618. Feature Detection
  10619. ====================================================*/
  10620. support: {
  10621. touch : (window.Modernizr && Modernizr.touch === true) || (function () {
  10622. return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
  10623. })(),
  10624. transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () {
  10625. var div = document.createElement('div').style;
  10626. return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
  10627. })(),
  10628. flexbox: (function () {
  10629. var div = document.createElement('div').style;
  10630. var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' ');
  10631. for (var i = 0; i < styles.length; i++) {
  10632. if (styles[i] in div) return true;
  10633. }
  10634. })(),
  10635. observer: (function () {
  10636. return ('MutationObserver' in window || 'WebkitMutationObserver' in window);
  10637. })()
  10638. },
  10639. /*==================================================
  10640. Plugins
  10641. ====================================================*/
  10642. plugins: {}
  10643. };
  10644. /*===========================
  10645. Dom7 Library
  10646. ===========================*/
  10647. var Dom7 = (function () {
  10648. var Dom7 = function (arr) {
  10649. var _this = this, i = 0;
  10650. // Create array-like object
  10651. for (i = 0; i < arr.length; i++) {
  10652. _this[i] = arr[i];
  10653. }
  10654. _this.length = arr.length;
  10655. // Return collection with methods
  10656. return this;
  10657. };
  10658. var $ = function (selector, context) {
  10659. var arr = [], i = 0;
  10660. if (selector && !context) {
  10661. if (selector instanceof Dom7) {
  10662. return selector;
  10663. }
  10664. }
  10665. if (selector) {
  10666. // String
  10667. if (typeof selector === 'string') {
  10668. var els, tempParent, html = selector.trim();
  10669. if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) {
  10670. var toCreate = 'div';
  10671. if (html.indexOf('<li') === 0) toCreate = 'ul';
  10672. if (html.indexOf('<tr') === 0) toCreate = 'tbody';
  10673. if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) toCreate = 'tr';
  10674. if (html.indexOf('<tbody') === 0) toCreate = 'table';
  10675. if (html.indexOf('<option') === 0) toCreate = 'select';
  10676. tempParent = document.createElement(toCreate);
  10677. tempParent.innerHTML = selector;
  10678. for (i = 0; i < tempParent.childNodes.length; i++) {
  10679. arr.push(tempParent.childNodes[i]);
  10680. }
  10681. }
  10682. else {
  10683. if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) {
  10684. // Pure ID selector
  10685. els = [document.getElementById(selector.split('#')[1])];
  10686. }
  10687. else {
  10688. // Other selectors
  10689. els = (context || document).querySelectorAll(selector);
  10690. }
  10691. for (i = 0; i < els.length; i++) {
  10692. if (els[i]) arr.push(els[i]);
  10693. }
  10694. }
  10695. }
  10696. // Node/element
  10697. else if (selector.nodeType || selector === window || selector === document) {
  10698. arr.push(selector);
  10699. }
  10700. //Array of elements or instance of Dom
  10701. else if (selector.length > 0 && selector[0].nodeType) {
  10702. for (i = 0; i < selector.length; i++) {
  10703. arr.push(selector[i]);
  10704. }
  10705. }
  10706. }
  10707. return new Dom7(arr);
  10708. };
  10709. Dom7.prototype = {
  10710. // Classes and attriutes
  10711. addClass: function (className) {
  10712. if (typeof className === 'undefined') {
  10713. return this;
  10714. }
  10715. var classes = className.split(' ');
  10716. for (var i = 0; i < classes.length; i++) {
  10717. for (var j = 0; j < this.length; j++) {
  10718. this[j].classList.add(classes[i]);
  10719. }
  10720. }
  10721. return this;
  10722. },
  10723. removeClass: function (className) {
  10724. var classes = className.split(' ');
  10725. for (var i = 0; i < classes.length; i++) {
  10726. for (var j = 0; j < this.length; j++) {
  10727. this[j].classList.remove(classes[i]);
  10728. }
  10729. }
  10730. return this;
  10731. },
  10732. hasClass: function (className) {
  10733. if (!this[0]) return false;
  10734. else return this[0].classList.contains(className);
  10735. },
  10736. toggleClass: function (className) {
  10737. var classes = className.split(' ');
  10738. for (var i = 0; i < classes.length; i++) {
  10739. for (var j = 0; j < this.length; j++) {
  10740. this[j].classList.toggle(classes[i]);
  10741. }
  10742. }
  10743. return this;
  10744. },
  10745. attr: function (attrs, value) {
  10746. if (arguments.length === 1 && typeof attrs === 'string') {
  10747. // Get attr
  10748. if (this[0]) return this[0].getAttribute(attrs);
  10749. else return undefined;
  10750. }
  10751. else {
  10752. // Set attrs
  10753. for (var i = 0; i < this.length; i++) {
  10754. if (arguments.length === 2) {
  10755. // String
  10756. this[i].setAttribute(attrs, value);
  10757. }
  10758. else {
  10759. // Object
  10760. for (var attrName in attrs) {
  10761. this[i][attrName] = attrs[attrName];
  10762. this[i].setAttribute(attrName, attrs[attrName]);
  10763. }
  10764. }
  10765. }
  10766. return this;
  10767. }
  10768. },
  10769. removeAttr: function (attr) {
  10770. for (var i = 0; i < this.length; i++) {
  10771. this[i].removeAttribute(attr);
  10772. }
  10773. return this;
  10774. },
  10775. data: function (key, value) {
  10776. if (typeof value === 'undefined') {
  10777. // Get value
  10778. if (this[0]) {
  10779. var dataKey = this[0].getAttribute('data-' + key);
  10780. if (dataKey) return dataKey;
  10781. else if (this[0].dom7ElementDataStorage && (key in this[0].dom7ElementDataStorage)) return this[0].dom7ElementDataStorage[key];
  10782. else return undefined;
  10783. }
  10784. else return undefined;
  10785. }
  10786. else {
  10787. // Set value
  10788. for (var i = 0; i < this.length; i++) {
  10789. var el = this[i];
  10790. if (!el.dom7ElementDataStorage) el.dom7ElementDataStorage = {};
  10791. el.dom7ElementDataStorage[key] = value;
  10792. }
  10793. return this;
  10794. }
  10795. },
  10796. // Transforms
  10797. transform : function (transform) {
  10798. for (var i = 0; i < this.length; i++) {
  10799. var elStyle = this[i].style;
  10800. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  10801. }
  10802. return this;
  10803. },
  10804. transition: function (duration) {
  10805. if (typeof duration !== 'string') {
  10806. duration = duration + 'ms';
  10807. }
  10808. for (var i = 0; i < this.length; i++) {
  10809. var elStyle = this[i].style;
  10810. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  10811. }
  10812. return this;
  10813. },
  10814. //Events
  10815. on: function (eventName, targetSelector, listener, capture) {
  10816. function handleLiveEvent(e) {
  10817. var target = e.target;
  10818. if ($(target).is(targetSelector)) listener.call(target, e);
  10819. else {
  10820. var parents = $(target).parents();
  10821. for (var k = 0; k < parents.length; k++) {
  10822. if ($(parents[k]).is(targetSelector)) listener.call(parents[k], e);
  10823. }
  10824. }
  10825. }
  10826. var events = eventName.split(' ');
  10827. var i, j;
  10828. for (i = 0; i < this.length; i++) {
  10829. if (typeof targetSelector === 'function' || targetSelector === false) {
  10830. // Usual events
  10831. if (typeof targetSelector === 'function') {
  10832. listener = arguments[1];
  10833. capture = arguments[2] || false;
  10834. }
  10835. for (j = 0; j < events.length; j++) {
  10836. this[i].addEventListener(events[j], listener, capture);
  10837. }
  10838. }
  10839. else {
  10840. //Live events
  10841. for (j = 0; j < events.length; j++) {
  10842. if (!this[i].dom7LiveListeners) this[i].dom7LiveListeners = [];
  10843. this[i].dom7LiveListeners.push({listener: listener, liveListener: handleLiveEvent});
  10844. this[i].addEventListener(events[j], handleLiveEvent, capture);
  10845. }
  10846. }
  10847. }
  10848. return this;
  10849. },
  10850. off: function (eventName, targetSelector, listener, capture) {
  10851. var events = eventName.split(' ');
  10852. for (var i = 0; i < events.length; i++) {
  10853. for (var j = 0; j < this.length; j++) {
  10854. if (typeof targetSelector === 'function' || targetSelector === false) {
  10855. // Usual events
  10856. if (typeof targetSelector === 'function') {
  10857. listener = arguments[1];
  10858. capture = arguments[2] || false;
  10859. }
  10860. this[j].removeEventListener(events[i], listener, capture);
  10861. }
  10862. else {
  10863. // Live event
  10864. if (this[j].dom7LiveListeners) {
  10865. for (var k = 0; k < this[j].dom7LiveListeners.length; k++) {
  10866. if (this[j].dom7LiveListeners[k].listener === listener) {
  10867. this[j].removeEventListener(events[i], this[j].dom7LiveListeners[k].liveListener, capture);
  10868. }
  10869. }
  10870. }
  10871. }
  10872. }
  10873. }
  10874. return this;
  10875. },
  10876. once: function (eventName, targetSelector, listener, capture) {
  10877. var dom = this;
  10878. if (typeof targetSelector === 'function') {
  10879. targetSelector = false;
  10880. listener = arguments[1];
  10881. capture = arguments[2];
  10882. }
  10883. function proxy(e) {
  10884. listener(e);
  10885. dom.off(eventName, targetSelector, proxy, capture);
  10886. }
  10887. dom.on(eventName, targetSelector, proxy, capture);
  10888. },
  10889. trigger: function (eventName, eventData) {
  10890. for (var i = 0; i < this.length; i++) {
  10891. var evt;
  10892. try {
  10893. evt = new window.CustomEvent(eventName, {detail: eventData, bubbles: true, cancelable: true});
  10894. }
  10895. catch (e) {
  10896. evt = document.createEvent('Event');
  10897. evt.initEvent(eventName, true, true);
  10898. evt.detail = eventData;
  10899. }
  10900. this[i].dispatchEvent(evt);
  10901. }
  10902. return this;
  10903. },
  10904. transitionEnd: function (callback) {
  10905. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  10906. i, j, dom = this;
  10907. function fireCallBack(e) {
  10908. /*jshint validthis:true */
  10909. if (e.target !== this) return;
  10910. callback.call(this, e);
  10911. for (i = 0; i < events.length; i++) {
  10912. dom.off(events[i], fireCallBack);
  10913. }
  10914. }
  10915. if (callback) {
  10916. for (i = 0; i < events.length; i++) {
  10917. dom.on(events[i], fireCallBack);
  10918. }
  10919. }
  10920. return this;
  10921. },
  10922. // Sizing/Styles
  10923. width: function () {
  10924. if (this[0] === window) {
  10925. return window.innerWidth;
  10926. }
  10927. else {
  10928. if (this.length > 0) {
  10929. return parseFloat(this.css('width'));
  10930. }
  10931. else {
  10932. return null;
  10933. }
  10934. }
  10935. },
  10936. outerWidth: function (includeMargins) {
  10937. if (this.length > 0) {
  10938. if (includeMargins)
  10939. return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left'));
  10940. else
  10941. return this[0].offsetWidth;
  10942. }
  10943. else return null;
  10944. },
  10945. height: function () {
  10946. if (this[0] === window) {
  10947. return window.innerHeight;
  10948. }
  10949. else {
  10950. if (this.length > 0) {
  10951. return parseFloat(this.css('height'));
  10952. }
  10953. else {
  10954. return null;
  10955. }
  10956. }
  10957. },
  10958. outerHeight: function (includeMargins) {
  10959. if (this.length > 0) {
  10960. if (includeMargins)
  10961. return this[0].offsetHeight + parseFloat(this.css('margin-top')) + parseFloat(this.css('margin-bottom'));
  10962. else
  10963. return this[0].offsetHeight;
  10964. }
  10965. else return null;
  10966. },
  10967. offset: function () {
  10968. if (this.length > 0) {
  10969. var el = this[0];
  10970. var box = el.getBoundingClientRect();
  10971. var body = document.body;
  10972. var clientTop = el.clientTop || body.clientTop || 0;
  10973. var clientLeft = el.clientLeft || body.clientLeft || 0;
  10974. var scrollTop = window.pageYOffset || el.scrollTop;
  10975. var scrollLeft = window.pageXOffset || el.scrollLeft;
  10976. return {
  10977. top: box.top + scrollTop - clientTop,
  10978. left: box.left + scrollLeft - clientLeft
  10979. };
  10980. }
  10981. else {
  10982. return null;
  10983. }
  10984. },
  10985. css: function (props, value) {
  10986. var i;
  10987. if (arguments.length === 1) {
  10988. if (typeof props === 'string') {
  10989. if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props);
  10990. }
  10991. else {
  10992. for (i = 0; i < this.length; i++) {
  10993. for (var prop in props) {
  10994. this[i].style[prop] = props[prop];
  10995. }
  10996. }
  10997. return this;
  10998. }
  10999. }
  11000. if (arguments.length === 2 && typeof props === 'string') {
  11001. for (i = 0; i < this.length; i++) {
  11002. this[i].style[props] = value;
  11003. }
  11004. return this;
  11005. }
  11006. return this;
  11007. },
  11008. //Dom manipulation
  11009. each: function (callback) {
  11010. for (var i = 0; i < this.length; i++) {
  11011. callback.call(this[i], i, this[i]);
  11012. }
  11013. return this;
  11014. },
  11015. html: function (html) {
  11016. if (typeof html === 'undefined') {
  11017. return this[0] ? this[0].innerHTML : undefined;
  11018. }
  11019. else {
  11020. for (var i = 0; i < this.length; i++) {
  11021. this[i].innerHTML = html;
  11022. }
  11023. return this;
  11024. }
  11025. },
  11026. is: function (selector) {
  11027. if (!this[0]) return false;
  11028. var compareWith, i;
  11029. if (typeof selector === 'string') {
  11030. var el = this[0];
  11031. if (el === document) return selector === document;
  11032. if (el === window) return selector === window;
  11033. if (el.matches) return el.matches(selector);
  11034. else if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector);
  11035. else if (el.mozMatchesSelector) return el.mozMatchesSelector(selector);
  11036. else if (el.msMatchesSelector) return el.msMatchesSelector(selector);
  11037. else {
  11038. compareWith = $(selector);
  11039. for (i = 0; i < compareWith.length; i++) {
  11040. if (compareWith[i] === this[0]) return true;
  11041. }
  11042. return false;
  11043. }
  11044. }
  11045. else if (selector === document) return this[0] === document;
  11046. else if (selector === window) return this[0] === window;
  11047. else {
  11048. if (selector.nodeType || selector instanceof Dom7) {
  11049. compareWith = selector.nodeType ? [selector] : selector;
  11050. for (i = 0; i < compareWith.length; i++) {
  11051. if (compareWith[i] === this[0]) return true;
  11052. }
  11053. return false;
  11054. }
  11055. return false;
  11056. }
  11057. },
  11058. index: function () {
  11059. if (this[0]) {
  11060. var child = this[0];
  11061. var i = 0;
  11062. while ((child = child.previousSibling) !== null) {
  11063. if (child.nodeType === 1) i++;
  11064. }
  11065. return i;
  11066. }
  11067. else return undefined;
  11068. },
  11069. eq: function (index) {
  11070. if (typeof index === 'undefined') return this;
  11071. var length = this.length;
  11072. var returnIndex;
  11073. if (index > length - 1) {
  11074. return new Dom7([]);
  11075. }
  11076. if (index < 0) {
  11077. returnIndex = length + index;
  11078. if (returnIndex < 0) return new Dom7([]);
  11079. else return new Dom7([this[returnIndex]]);
  11080. }
  11081. return new Dom7([this[index]]);
  11082. },
  11083. append: function (newChild) {
  11084. var i, j;
  11085. for (i = 0; i < this.length; i++) {
  11086. if (typeof newChild === 'string') {
  11087. var tempDiv = document.createElement('div');
  11088. tempDiv.innerHTML = newChild;
  11089. while (tempDiv.firstChild) {
  11090. this[i].appendChild(tempDiv.firstChild);
  11091. }
  11092. }
  11093. else if (newChild instanceof Dom7) {
  11094. for (j = 0; j < newChild.length; j++) {
  11095. this[i].appendChild(newChild[j]);
  11096. }
  11097. }
  11098. else {
  11099. this[i].appendChild(newChild);
  11100. }
  11101. }
  11102. return this;
  11103. },
  11104. prepend: function (newChild) {
  11105. var i, j;
  11106. for (i = 0; i < this.length; i++) {
  11107. if (typeof newChild === 'string') {
  11108. var tempDiv = document.createElement('div');
  11109. tempDiv.innerHTML = newChild;
  11110. for (j = tempDiv.childNodes.length - 1; j >= 0; j--) {
  11111. this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
  11112. }
  11113. // this[i].insertAdjacentHTML('afterbegin', newChild);
  11114. }
  11115. else if (newChild instanceof Dom7) {
  11116. for (j = 0; j < newChild.length; j++) {
  11117. this[i].insertBefore(newChild[j], this[i].childNodes[0]);
  11118. }
  11119. }
  11120. else {
  11121. this[i].insertBefore(newChild, this[i].childNodes[0]);
  11122. }
  11123. }
  11124. return this;
  11125. },
  11126. insertBefore: function (selector) {
  11127. var before = $(selector);
  11128. for (var i = 0; i < this.length; i++) {
  11129. if (before.length === 1) {
  11130. before[0].parentNode.insertBefore(this[i], before[0]);
  11131. }
  11132. else if (before.length > 1) {
  11133. for (var j = 0; j < before.length; j++) {
  11134. before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]);
  11135. }
  11136. }
  11137. }
  11138. },
  11139. insertAfter: function (selector) {
  11140. var after = $(selector);
  11141. for (var i = 0; i < this.length; i++) {
  11142. if (after.length === 1) {
  11143. after[0].parentNode.insertBefore(this[i], after[0].nextSibling);
  11144. }
  11145. else if (after.length > 1) {
  11146. for (var j = 0; j < after.length; j++) {
  11147. after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling);
  11148. }
  11149. }
  11150. }
  11151. },
  11152. next: function (selector) {
  11153. if (this.length > 0) {
  11154. if (selector) {
  11155. if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) return new Dom7([this[0].nextElementSibling]);
  11156. else return new Dom7([]);
  11157. }
  11158. else {
  11159. if (this[0].nextElementSibling) return new Dom7([this[0].nextElementSibling]);
  11160. else return new Dom7([]);
  11161. }
  11162. }
  11163. else return new Dom7([]);
  11164. },
  11165. nextAll: function (selector) {
  11166. var nextEls = [];
  11167. var el = this[0];
  11168. if (!el) return new Dom7([]);
  11169. while (el.nextElementSibling) {
  11170. var next = el.nextElementSibling;
  11171. if (selector) {
  11172. if($(next).is(selector)) nextEls.push(next);
  11173. }
  11174. else nextEls.push(next);
  11175. el = next;
  11176. }
  11177. return new Dom7(nextEls);
  11178. },
  11179. prev: function (selector) {
  11180. if (this.length > 0) {
  11181. if (selector) {
  11182. if (this[0].previousElementSibling && $(this[0].previousElementSibling).is(selector)) return new Dom7([this[0].previousElementSibling]);
  11183. else return new Dom7([]);
  11184. }
  11185. else {
  11186. if (this[0].previousElementSibling) return new Dom7([this[0].previousElementSibling]);
  11187. else return new Dom7([]);
  11188. }
  11189. }
  11190. else return new Dom7([]);
  11191. },
  11192. prevAll: function (selector) {
  11193. var prevEls = [];
  11194. var el = this[0];
  11195. if (!el) return new Dom7([]);
  11196. while (el.previousElementSibling) {
  11197. var prev = el.previousElementSibling;
  11198. if (selector) {
  11199. if($(prev).is(selector)) prevEls.push(prev);
  11200. }
  11201. else prevEls.push(prev);
  11202. el = prev;
  11203. }
  11204. return new Dom7(prevEls);
  11205. },
  11206. parent: function (selector) {
  11207. var parents = [];
  11208. for (var i = 0; i < this.length; i++) {
  11209. if (selector) {
  11210. if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode);
  11211. }
  11212. else {
  11213. parents.push(this[i].parentNode);
  11214. }
  11215. }
  11216. return $($.unique(parents));
  11217. },
  11218. parents: function (selector) {
  11219. var parents = [];
  11220. for (var i = 0; i < this.length; i++) {
  11221. var parent = this[i].parentNode;
  11222. while (parent) {
  11223. if (selector) {
  11224. if ($(parent).is(selector)) parents.push(parent);
  11225. }
  11226. else {
  11227. parents.push(parent);
  11228. }
  11229. parent = parent.parentNode;
  11230. }
  11231. }
  11232. return $($.unique(parents));
  11233. },
  11234. find : function (selector) {
  11235. var foundElements = [];
  11236. for (var i = 0; i < this.length; i++) {
  11237. var found = this[i].querySelectorAll(selector);
  11238. for (var j = 0; j < found.length; j++) {
  11239. foundElements.push(found[j]);
  11240. }
  11241. }
  11242. return new Dom7(foundElements);
  11243. },
  11244. children: function (selector) {
  11245. var children = [];
  11246. for (var i = 0; i < this.length; i++) {
  11247. var childNodes = this[i].childNodes;
  11248. for (var j = 0; j < childNodes.length; j++) {
  11249. if (!selector) {
  11250. if (childNodes[j].nodeType === 1) children.push(childNodes[j]);
  11251. }
  11252. else {
  11253. if (childNodes[j].nodeType === 1 && $(childNodes[j]).is(selector)) children.push(childNodes[j]);
  11254. }
  11255. }
  11256. }
  11257. return new Dom7($.unique(children));
  11258. },
  11259. remove: function () {
  11260. for (var i = 0; i < this.length; i++) {
  11261. if (this[i].parentNode) this[i].parentNode.removeChild(this[i]);
  11262. }
  11263. return this;
  11264. },
  11265. add: function () {
  11266. var dom = this;
  11267. var i, j;
  11268. for (i = 0; i < arguments.length; i++) {
  11269. var toAdd = $(arguments[i]);
  11270. for (j = 0; j < toAdd.length; j++) {
  11271. dom[dom.length] = toAdd[j];
  11272. dom.length++;
  11273. }
  11274. }
  11275. return dom;
  11276. }
  11277. };
  11278. $.fn = Dom7.prototype;
  11279. $.unique = function (arr) {
  11280. var unique = [];
  11281. for (var i = 0; i < arr.length; i++) {
  11282. if (unique.indexOf(arr[i]) === -1) unique.push(arr[i]);
  11283. }
  11284. return unique;
  11285. };
  11286. return $;
  11287. })();
  11288. /*===========================
  11289. Get Dom libraries
  11290. ===========================*/
  11291. var swiperDomPlugins = ['jQuery', 'Zepto', 'Dom7'];
  11292. for (var i = 0; i < swiperDomPlugins.length; i++) {
  11293. if (window[swiperDomPlugins[i]]) {
  11294. addLibraryPlugin(window[swiperDomPlugins[i]]);
  11295. }
  11296. }
  11297. // Required DOM Plugins
  11298. var domLib;
  11299. if (typeof Dom7 === 'undefined') {
  11300. domLib = window.Dom7 || window.Zepto || window.jQuery;
  11301. }
  11302. else {
  11303. domLib = Dom7;
  11304. }
  11305. /*===========================
  11306. Add .swiper plugin from Dom libraries
  11307. ===========================*/
  11308. function addLibraryPlugin(lib) {
  11309. lib.fn.swiper = function (params) {
  11310. var firstInstance;
  11311. lib(this).each(function () {
  11312. var s = new Swiper(this, params);
  11313. if (!firstInstance) firstInstance = s;
  11314. });
  11315. return firstInstance;
  11316. };
  11317. }
  11318. if (domLib) {
  11319. if (!('transitionEnd' in domLib.fn)) {
  11320. domLib.fn.transitionEnd = function (callback) {
  11321. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  11322. i, j, dom = this;
  11323. function fireCallBack(e) {
  11324. /*jshint validthis:true */
  11325. if (e.target !== this) return;
  11326. callback.call(this, e);
  11327. for (i = 0; i < events.length; i++) {
  11328. dom.off(events[i], fireCallBack);
  11329. }
  11330. }
  11331. if (callback) {
  11332. for (i = 0; i < events.length; i++) {
  11333. dom.on(events[i], fireCallBack);
  11334. }
  11335. }
  11336. return this;
  11337. };
  11338. }
  11339. if (!('transform' in domLib.fn)) {
  11340. domLib.fn.transform = function (transform) {
  11341. for (var i = 0; i < this.length; i++) {
  11342. var elStyle = this[i].style;
  11343. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  11344. }
  11345. return this;
  11346. };
  11347. }
  11348. if (!('transition' in domLib.fn)) {
  11349. domLib.fn.transition = function (duration) {
  11350. if (typeof duration !== 'string') {
  11351. duration = duration + 'ms';
  11352. }
  11353. for (var i = 0; i < this.length; i++) {
  11354. var elStyle = this[i].style;
  11355. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  11356. }
  11357. return this;
  11358. };
  11359. }
  11360. }
  11361. ionic.views.Swiper = Swiper;
  11362. })();
  11363. (function(ionic) {
  11364. 'use strict';
  11365. ionic.views.Toggle = ionic.views.View.inherit({
  11366. initialize: function(opts) {
  11367. var self = this;
  11368. this.el = opts.el;
  11369. this.checkbox = opts.checkbox;
  11370. this.track = opts.track;
  11371. this.handle = opts.handle;
  11372. this.openPercent = -1;
  11373. this.onChange = opts.onChange || function() {};
  11374. this.triggerThreshold = opts.triggerThreshold || 20;
  11375. this.dragStartHandler = function(e) {
  11376. self.dragStart(e);
  11377. };
  11378. this.dragHandler = function(e) {
  11379. self.drag(e);
  11380. };
  11381. this.holdHandler = function(e) {
  11382. self.hold(e);
  11383. };
  11384. this.releaseHandler = function(e) {
  11385. self.release(e);
  11386. };
  11387. this.dragStartGesture = ionic.onGesture('dragstart', this.dragStartHandler, this.el);
  11388. this.dragGesture = ionic.onGesture('drag', this.dragHandler, this.el);
  11389. this.dragHoldGesture = ionic.onGesture('hold', this.holdHandler, this.el);
  11390. this.dragReleaseGesture = ionic.onGesture('release', this.releaseHandler, this.el);
  11391. },
  11392. destroy: function() {
  11393. ionic.offGesture(this.dragStartGesture, 'dragstart', this.dragStartGesture);
  11394. ionic.offGesture(this.dragGesture, 'drag', this.dragGesture);
  11395. ionic.offGesture(this.dragHoldGesture, 'hold', this.holdHandler);
  11396. ionic.offGesture(this.dragReleaseGesture, 'release', this.releaseHandler);
  11397. },
  11398. tap: function() {
  11399. if(this.el.getAttribute('disabled') !== 'disabled') {
  11400. this.val( !this.checkbox.checked );
  11401. }
  11402. },
  11403. dragStart: function(e) {
  11404. if(this.checkbox.disabled) return;
  11405. this._dragInfo = {
  11406. width: this.el.offsetWidth,
  11407. left: this.el.offsetLeft,
  11408. right: this.el.offsetLeft + this.el.offsetWidth,
  11409. triggerX: this.el.offsetWidth / 2,
  11410. initialState: this.checkbox.checked
  11411. };
  11412. // Stop any parent dragging
  11413. e.gesture.srcEvent.preventDefault();
  11414. // Trigger hold styles
  11415. this.hold(e);
  11416. },
  11417. drag: function(e) {
  11418. var self = this;
  11419. if(!this._dragInfo) { return; }
  11420. // Stop any parent dragging
  11421. e.gesture.srcEvent.preventDefault();
  11422. ionic.requestAnimationFrame(function () {
  11423. if (!self._dragInfo) { return; }
  11424. var px = e.gesture.touches[0].pageX - self._dragInfo.left;
  11425. var mx = self._dragInfo.width - self.triggerThreshold;
  11426. // The initial state was on, so "tend towards" on
  11427. if(self._dragInfo.initialState) {
  11428. if(px < self.triggerThreshold) {
  11429. self.setOpenPercent(0);
  11430. } else if(px > self._dragInfo.triggerX) {
  11431. self.setOpenPercent(100);
  11432. }
  11433. } else {
  11434. // The initial state was off, so "tend towards" off
  11435. if(px < self._dragInfo.triggerX) {
  11436. self.setOpenPercent(0);
  11437. } else if(px > mx) {
  11438. self.setOpenPercent(100);
  11439. }
  11440. }
  11441. });
  11442. },
  11443. endDrag: function() {
  11444. this._dragInfo = null;
  11445. },
  11446. hold: function() {
  11447. this.el.classList.add('dragging');
  11448. },
  11449. release: function(e) {
  11450. this.el.classList.remove('dragging');
  11451. this.endDrag(e);
  11452. },
  11453. setOpenPercent: function(openPercent) {
  11454. // only make a change if the new open percent has changed
  11455. if(this.openPercent < 0 || (openPercent < (this.openPercent - 3) || openPercent > (this.openPercent + 3) ) ) {
  11456. this.openPercent = openPercent;
  11457. if(openPercent === 0) {
  11458. this.val(false);
  11459. } else if(openPercent === 100) {
  11460. this.val(true);
  11461. } else {
  11462. var openPixel = Math.round( (openPercent / 100) * this.track.offsetWidth - (this.handle.offsetWidth) );
  11463. openPixel = (openPixel < 1 ? 0 : openPixel);
  11464. this.handle.style[ionic.CSS.TRANSFORM] = 'translate3d(' + openPixel + 'px,0,0)';
  11465. }
  11466. }
  11467. },
  11468. val: function(value) {
  11469. if(value === true || value === false) {
  11470. if(this.handle.style[ionic.CSS.TRANSFORM] !== "") {
  11471. this.handle.style[ionic.CSS.TRANSFORM] = "";
  11472. }
  11473. this.checkbox.checked = value;
  11474. this.openPercent = (value ? 100 : 0);
  11475. this.onChange && this.onChange();
  11476. }
  11477. return this.checkbox.checked;
  11478. }
  11479. });
  11480. })(ionic);
  11481. })();