swiper.js 237 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354
  1. /**
  2. * Swiper 3.4.2
  3. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4. *
  5. * http://www.idangero.us/swiper/
  6. *
  7. * Copyright 2017, Vladimir Kharlampidi
  8. * The iDangero.us
  9. * http://www.idangero.us/
  10. *
  11. * Licensed under MIT
  12. *
  13. * Released on: March 10, 2017
  14. */
  15. (function () {
  16. 'use strict';
  17. var $;
  18. /*===========================
  19. Swiper
  20. ===========================*/
  21. var Swiper = function (container, params) {
  22. if (!(this instanceof Swiper)) return new Swiper(container, params);
  23. var defaults = {
  24. direction: 'horizontal',
  25. touchEventsTarget: 'container',
  26. initialSlide: 0,
  27. speed: 300,
  28. // autoplay
  29. autoplay: false,
  30. autoplayDisableOnInteraction: true,
  31. autoplayStopOnLast: false,
  32. // To support iOS's swipe-to-go-back gesture (when being used in-app, with UIWebView).
  33. iOSEdgeSwipeDetection: false,
  34. iOSEdgeSwipeThreshold: 20,
  35. // Free mode
  36. freeMode: false,
  37. freeModeMomentum: true,
  38. freeModeMomentumRatio: 1,
  39. freeModeMomentumBounce: true,
  40. freeModeMomentumBounceRatio: 1,
  41. freeModeMomentumVelocityRatio: 1,
  42. freeModeSticky: false,
  43. freeModeMinimumVelocity: 0.02,
  44. // Autoheight
  45. autoHeight: false,
  46. // Set wrapper width
  47. setWrapperSize: false,
  48. // Virtual Translate
  49. virtualTranslate: false,
  50. // Effects
  51. effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
  52. coverflow: {
  53. rotate: 50,
  54. stretch: 0,
  55. depth: 100,
  56. modifier: 1,
  57. slideShadows : true
  58. },
  59. flip: {
  60. slideShadows : true,
  61. limitRotation: true
  62. },
  63. cube: {
  64. slideShadows: true,
  65. shadow: true,
  66. shadowOffset: 20,
  67. shadowScale: 0.94
  68. },
  69. fade: {
  70. crossFade: false
  71. },
  72. // Parallax
  73. parallax: false,
  74. // Zoom
  75. zoom: false,
  76. zoomMax: 3,
  77. zoomMin: 1,
  78. zoomToggle: true,
  79. // Scrollbar
  80. scrollbar: null,
  81. scrollbarHide: true,
  82. scrollbarDraggable: false,
  83. scrollbarSnapOnRelease: false,
  84. // Keyboard Mousewheel
  85. keyboardControl: false,
  86. mousewheelControl: false,
  87. mousewheelReleaseOnEdges: false,
  88. mousewheelInvert: false,
  89. mousewheelForceToAxis: false,
  90. mousewheelSensitivity: 1,
  91. mousewheelEventsTarged: 'container',
  92. // Hash Navigation
  93. hashnav: false,
  94. hashnavWatchState: false,
  95. // History
  96. history: false,
  97. // Commong Nav State
  98. replaceState: false,
  99. // Breakpoints
  100. breakpoints: undefined,
  101. // Slides grid
  102. spaceBetween: 0,
  103. slidesPerView: 1,
  104. slidesPerColumn: 1,
  105. slidesPerColumnFill: 'column',
  106. slidesPerGroup: 1,
  107. centeredSlides: false,
  108. slidesOffsetBefore: 0, // in px
  109. slidesOffsetAfter: 0, // in px
  110. // Round length
  111. roundLengths: false,
  112. // Touches
  113. touchRatio: 1,
  114. touchAngle: 45,
  115. simulateTouch: true,
  116. shortSwipes: true,
  117. longSwipes: true,
  118. longSwipesRatio: 0.5,
  119. longSwipesMs: 300,
  120. followFinger: true,
  121. onlyExternal: false,
  122. threshold: 0,
  123. touchMoveStopPropagation: true,
  124. touchReleaseOnEdges: false,
  125. // Unique Navigation Elements
  126. uniqueNavElements: true,
  127. // Pagination
  128. pagination: null,
  129. paginationElement: 'span',
  130. paginationClickable: false,
  131. paginationHide: false,
  132. paginationBulletRender: null,
  133. paginationProgressRender: null,
  134. paginationFractionRender: null,
  135. paginationCustomRender: null,
  136. paginationType: 'bullets', // 'bullets' or 'progress' or 'fraction' or 'custom'
  137. // Resistance
  138. resistance: true,
  139. resistanceRatio: 0.85,
  140. // Next/prev buttons
  141. nextButton: null,
  142. prevButton: null,
  143. // Progress
  144. watchSlidesProgress: false,
  145. watchSlidesVisibility: false,
  146. // Cursor
  147. grabCursor: false,
  148. // Clicks
  149. preventClicks: true,
  150. preventClicksPropagation: true,
  151. slideToClickedSlide: false,
  152. // Lazy Loading
  153. lazyLoading: false,
  154. lazyLoadingInPrevNext: false,
  155. lazyLoadingInPrevNextAmount: 1,
  156. lazyLoadingOnTransitionStart: false,
  157. // Images
  158. preloadImages: true,
  159. updateOnImagesReady: true,
  160. // loop
  161. loop: false,
  162. loopAdditionalSlides: 0,
  163. loopedSlides: null,
  164. // Control
  165. control: undefined,
  166. controlInverse: false,
  167. controlBy: 'slide', //or 'container'
  168. normalizeSlideIndex: true,
  169. // Swiping/no swiping
  170. allowSwipeToPrev: true,
  171. allowSwipeToNext: true,
  172. swipeHandler: null, //'.swipe-handler',
  173. noSwiping: true,
  174. noSwipingClass: 'swiper-no-swiping',
  175. // Passive Listeners
  176. passiveListeners: true,
  177. // NS
  178. containerModifierClass: 'swiper-container-', // NEW
  179. slideClass: 'swiper-slide',
  180. slideActiveClass: 'swiper-slide-active',
  181. slideDuplicateActiveClass: 'swiper-slide-duplicate-active',
  182. slideVisibleClass: 'swiper-slide-visible',
  183. slideDuplicateClass: 'swiper-slide-duplicate',
  184. slideNextClass: 'swiper-slide-next',
  185. slideDuplicateNextClass: 'swiper-slide-duplicate-next',
  186. slidePrevClass: 'swiper-slide-prev',
  187. slideDuplicatePrevClass: 'swiper-slide-duplicate-prev',
  188. wrapperClass: 'swiper-wrapper',
  189. bulletClass: 'swiper-pagination-bullet',
  190. bulletActiveClass: 'swiper-pagination-bullet-active',
  191. buttonDisabledClass: 'swiper-button-disabled',
  192. paginationCurrentClass: 'swiper-pagination-current',
  193. paginationTotalClass: 'swiper-pagination-total',
  194. paginationHiddenClass: 'swiper-pagination-hidden',
  195. paginationProgressbarClass: 'swiper-pagination-progressbar',
  196. paginationClickableClass: 'swiper-pagination-clickable', // NEW
  197. paginationModifierClass: 'swiper-pagination-', // NEW
  198. lazyLoadingClass: 'swiper-lazy',
  199. lazyStatusLoadingClass: 'swiper-lazy-loading',
  200. lazyStatusLoadedClass: 'swiper-lazy-loaded',
  201. lazyPreloaderClass: 'swiper-lazy-preloader',
  202. notificationClass: 'swiper-notification',
  203. preloaderClass: 'preloader',
  204. zoomContainerClass: 'swiper-zoom-container',
  205. // Observer
  206. observer: false,
  207. observeParents: false,
  208. // Accessibility
  209. a11y: false,
  210. prevSlideMessage: 'Previous slide',
  211. nextSlideMessage: 'Next slide',
  212. firstSlideMessage: 'This is the first slide',
  213. lastSlideMessage: 'This is the last slide',
  214. paginationBulletMessage: 'Go to slide {{index}}',
  215. // Callbacks
  216. runCallbacksOnInit: true
  217. /*
  218. Callbacks:
  219. onInit: function (swiper)
  220. onDestroy: function (swiper)
  221. onBeforeResize: function (swiper)
  222. onAfterResize: function (swiper)
  223. onClick: function (swiper, e)
  224. onTap: function (swiper, e)
  225. onDoubleTap: function (swiper, e)
  226. onSliderMove: function (swiper, e)
  227. onSlideChangeStart: function (swiper)
  228. onSlideChangeEnd: function (swiper)
  229. onTransitionStart: function (swiper)
  230. onTransitionEnd: function (swiper)
  231. onImagesReady: function (swiper)
  232. onProgress: function (swiper, progress)
  233. onTouchStart: function (swiper, e)
  234. onTouchMove: function (swiper, e)
  235. onTouchMoveOpposite: function (swiper, e)
  236. onTouchEnd: function (swiper, e)
  237. onReachBeginning: function (swiper)
  238. onReachEnd: function (swiper)
  239. onSetTransition: function (swiper, duration)
  240. onSetTranslate: function (swiper, translate)
  241. onAutoplayStart: function (swiper)
  242. onAutoplayStop: function (swiper),
  243. onLazyImageLoad: function (swiper, slide, image)
  244. onLazyImageReady: function (swiper, slide, image)
  245. onKeyPress: function (swiper, keyCode)
  246. */
  247. };
  248. var initialVirtualTranslate = params && params.virtualTranslate;
  249. params = params || {};
  250. var originalParams = {};
  251. for (var param in params) {
  252. if (typeof params[param] === 'object' && params[param] !== null && !(params[param].nodeType || params[param] === window || params[param] === document || (typeof Dom7 !== 'undefined' && params[param] instanceof Dom7) || (typeof jQuery !== 'undefined' && params[param] instanceof jQuery))) {
  253. originalParams[param] = {};
  254. for (var deepParam in params[param]) {
  255. originalParams[param][deepParam] = params[param][deepParam];
  256. }
  257. }
  258. else {
  259. originalParams[param] = params[param];
  260. }
  261. }
  262. for (var def in defaults) {
  263. if (typeof params[def] === 'undefined') {
  264. params[def] = defaults[def];
  265. }
  266. else if (typeof params[def] === 'object') {
  267. for (var deepDef in defaults[def]) {
  268. if (typeof params[def][deepDef] === 'undefined') {
  269. params[def][deepDef] = defaults[def][deepDef];
  270. }
  271. }
  272. }
  273. }
  274. // Swiper
  275. var s = this;
  276. // Params
  277. s.params = params;
  278. s.originalParams = originalParams;
  279. // Classname
  280. s.classNames = [];
  281. /*=========================
  282. Dom Library and plugins
  283. ===========================*/
  284. if (typeof $ !== 'undefined' && typeof Dom7 !== 'undefined'){
  285. $ = Dom7;
  286. }
  287. if (typeof $ === 'undefined') {
  288. if (typeof Dom7 === 'undefined') {
  289. $ = window.Dom7 || window.Zepto || window.jQuery;
  290. }
  291. else {
  292. $ = Dom7;
  293. }
  294. if (!$) return;
  295. }
  296. // Export it to Swiper instance
  297. s.$ = $;
  298. /*=========================
  299. Breakpoints
  300. ===========================*/
  301. s.currentBreakpoint = undefined;
  302. s.getActiveBreakpoint = function () {
  303. //Get breakpoint for window width
  304. if (!s.params.breakpoints) return false;
  305. var breakpoint = false;
  306. var points = [], point;
  307. for ( point in s.params.breakpoints ) {
  308. if (s.params.breakpoints.hasOwnProperty(point)) {
  309. points.push(point);
  310. }
  311. }
  312. points.sort(function (a, b) {
  313. return parseInt(a, 10) > parseInt(b, 10);
  314. });
  315. for (var i = 0; i < points.length; i++) {
  316. point = points[i];
  317. if (point >= window.innerWidth && !breakpoint) {
  318. breakpoint = point;
  319. }
  320. }
  321. return breakpoint || 'max';
  322. };
  323. s.setBreakpoint = function () {
  324. //Set breakpoint for window width and update parameters
  325. var breakpoint = s.getActiveBreakpoint();
  326. if (breakpoint && s.currentBreakpoint !== breakpoint) {
  327. var breakPointsParams = breakpoint in s.params.breakpoints ? s.params.breakpoints[breakpoint] : s.originalParams;
  328. var needsReLoop = s.params.loop && (breakPointsParams.slidesPerView !== s.params.slidesPerView);
  329. for ( var param in breakPointsParams ) {
  330. s.params[param] = breakPointsParams[param];
  331. }
  332. s.currentBreakpoint = breakpoint;
  333. if(needsReLoop && s.destroyLoop) {
  334. s.reLoop(true);
  335. }
  336. }
  337. };
  338. // Set breakpoint on load
  339. if (s.params.breakpoints) {
  340. s.setBreakpoint();
  341. }
  342. /*=========================
  343. Preparation - Define Container, Wrapper and Pagination
  344. ===========================*/
  345. s.container = $(container);
  346. if (s.container.length === 0) return;
  347. if (s.container.length > 1) {
  348. var swipers = [];
  349. s.container.each(function () {
  350. var container = this;
  351. swipers.push(new Swiper(this, params));
  352. });
  353. return swipers;
  354. }
  355. // Save instance in container HTML Element and in data
  356. s.container[0].swiper = s;
  357. s.container.data('swiper', s);
  358. s.classNames.push(s.params.containerModifierClass + s.params.direction);
  359. if (s.params.freeMode) {
  360. s.classNames.push(s.params.containerModifierClass + 'free-mode');
  361. }
  362. if (!s.support.flexbox) {
  363. s.classNames.push(s.params.containerModifierClass + 'no-flexbox');
  364. s.params.slidesPerColumn = 1;
  365. }
  366. if (s.params.autoHeight) {
  367. s.classNames.push(s.params.containerModifierClass + 'autoheight');
  368. }
  369. // Enable slides progress when required
  370. if (s.params.parallax || s.params.watchSlidesVisibility) {
  371. s.params.watchSlidesProgress = true;
  372. }
  373. // Max resistance when touchReleaseOnEdges
  374. if (s.params.touchReleaseOnEdges) {
  375. s.params.resistanceRatio = 0;
  376. }
  377. // Coverflow / 3D
  378. if (['cube', 'coverflow', 'flip'].indexOf(s.params.effect) >= 0) {
  379. if (s.support.transforms3d) {
  380. s.params.watchSlidesProgress = true;
  381. s.classNames.push(s.params.containerModifierClass + '3d');
  382. }
  383. else {
  384. s.params.effect = 'slide';
  385. }
  386. }
  387. if (s.params.effect !== 'slide') {
  388. s.classNames.push(s.params.containerModifierClass + s.params.effect);
  389. }
  390. if (s.params.effect === 'cube') {
  391. s.params.resistanceRatio = 0;
  392. s.params.slidesPerView = 1;
  393. s.params.slidesPerColumn = 1;
  394. s.params.slidesPerGroup = 1;
  395. s.params.centeredSlides = false;
  396. s.params.spaceBetween = 0;
  397. s.params.virtualTranslate = true;
  398. }
  399. if (s.params.effect === 'fade' || s.params.effect === 'flip') {
  400. s.params.slidesPerView = 1;
  401. s.params.slidesPerColumn = 1;
  402. s.params.slidesPerGroup = 1;
  403. s.params.watchSlidesProgress = true;
  404. s.params.spaceBetween = 0;
  405. if (typeof initialVirtualTranslate === 'undefined') {
  406. s.params.virtualTranslate = true;
  407. }
  408. }
  409. // Grab Cursor
  410. if (s.params.grabCursor && s.support.touch) {
  411. s.params.grabCursor = false;
  412. }
  413. // Wrapper
  414. s.wrapper = s.container.children('.' + s.params.wrapperClass);
  415. // Pagination
  416. if (s.params.pagination) {
  417. s.paginationContainer = $(s.params.pagination);
  418. if (s.params.uniqueNavElements && typeof s.params.pagination === 'string' && s.paginationContainer.length > 1 && s.container.find(s.params.pagination).length === 1) {
  419. s.paginationContainer = s.container.find(s.params.pagination);
  420. }
  421. if (s.params.paginationType === 'bullets' && s.params.paginationClickable) {
  422. s.paginationContainer.addClass(s.params.paginationModifierClass + 'clickable');
  423. }
  424. else {
  425. s.params.paginationClickable = false;
  426. }
  427. s.paginationContainer.addClass(s.params.paginationModifierClass + s.params.paginationType);
  428. }
  429. // Next/Prev Buttons
  430. if (s.params.nextButton || s.params.prevButton) {
  431. if (s.params.nextButton) {
  432. s.nextButton = $(s.params.nextButton);
  433. if (s.params.uniqueNavElements && typeof s.params.nextButton === 'string' && s.nextButton.length > 1 && s.container.find(s.params.nextButton).length === 1) {
  434. s.nextButton = s.container.find(s.params.nextButton);
  435. }
  436. }
  437. if (s.params.prevButton) {
  438. s.prevButton = $(s.params.prevButton);
  439. if (s.params.uniqueNavElements && typeof s.params.prevButton === 'string' && s.prevButton.length > 1 && s.container.find(s.params.prevButton).length === 1) {
  440. s.prevButton = s.container.find(s.params.prevButton);
  441. }
  442. }
  443. }
  444. // Is Horizontal
  445. s.isHorizontal = function () {
  446. return s.params.direction === 'horizontal';
  447. };
  448. // s.isH = isH;
  449. // RTL
  450. s.rtl = s.isHorizontal() && (s.container[0].dir.toLowerCase() === 'rtl' || s.container.css('direction') === 'rtl');
  451. if (s.rtl) {
  452. s.classNames.push(s.params.containerModifierClass + 'rtl');
  453. }
  454. // Wrong RTL support
  455. if (s.rtl) {
  456. s.wrongRTL = s.wrapper.css('display') === '-webkit-box';
  457. }
  458. // Columns
  459. if (s.params.slidesPerColumn > 1) {
  460. s.classNames.push(s.params.containerModifierClass + 'multirow');
  461. }
  462. // Check for Android
  463. if (s.device.android) {
  464. s.classNames.push(s.params.containerModifierClass + 'android');
  465. }
  466. // Add classes
  467. s.container.addClass(s.classNames.join(' '));
  468. // Translate
  469. s.translate = 0;
  470. // Progress
  471. s.progress = 0;
  472. // Velocity
  473. s.velocity = 0;
  474. /*=========================
  475. Locks, unlocks
  476. ===========================*/
  477. s.lockSwipeToNext = function () {
  478. s.params.allowSwipeToNext = false;
  479. if (s.params.allowSwipeToPrev === false && s.params.grabCursor) {
  480. s.unsetGrabCursor();
  481. }
  482. };
  483. s.lockSwipeToPrev = function () {
  484. s.params.allowSwipeToPrev = false;
  485. if (s.params.allowSwipeToNext === false && s.params.grabCursor) {
  486. s.unsetGrabCursor();
  487. }
  488. };
  489. s.lockSwipes = function () {
  490. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = false;
  491. if (s.params.grabCursor) s.unsetGrabCursor();
  492. };
  493. s.unlockSwipeToNext = function () {
  494. s.params.allowSwipeToNext = true;
  495. if (s.params.allowSwipeToPrev === true && s.params.grabCursor) {
  496. s.setGrabCursor();
  497. }
  498. };
  499. s.unlockSwipeToPrev = function () {
  500. s.params.allowSwipeToPrev = true;
  501. if (s.params.allowSwipeToNext === true && s.params.grabCursor) {
  502. s.setGrabCursor();
  503. }
  504. };
  505. s.unlockSwipes = function () {
  506. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = true;
  507. if (s.params.grabCursor) s.setGrabCursor();
  508. };
  509. /*=========================
  510. Round helper
  511. ===========================*/
  512. function round(a) {
  513. return Math.floor(a);
  514. }
  515. /*=========================
  516. Set grab cursor
  517. ===========================*/
  518. s.setGrabCursor = function(moving) {
  519. s.container[0].style.cursor = 'move';
  520. s.container[0].style.cursor = moving ? '-webkit-grabbing' : '-webkit-grab';
  521. s.container[0].style.cursor = moving ? '-moz-grabbin' : '-moz-grab';
  522. s.container[0].style.cursor = moving ? 'grabbing': 'grab';
  523. };
  524. s.unsetGrabCursor = function () {
  525. s.container[0].style.cursor = '';
  526. };
  527. if (s.params.grabCursor) {
  528. s.setGrabCursor();
  529. }
  530. /*=========================
  531. Update on Images Ready
  532. ===========================*/
  533. s.imagesToLoad = [];
  534. s.imagesLoaded = 0;
  535. s.loadImage = function (imgElement, src, srcset, sizes, checkForComplete, callback) {
  536. var image;
  537. function onReady () {
  538. if (callback) callback();
  539. }
  540. if (!imgElement.complete || !checkForComplete) {
  541. if (src) {
  542. image = new window.Image();
  543. image.onload = onReady;
  544. image.onerror = onReady;
  545. if (sizes) {
  546. image.sizes = sizes;
  547. }
  548. if (srcset) {
  549. image.srcset = srcset;
  550. }
  551. if (src) {
  552. image.src = src;
  553. }
  554. } else {
  555. onReady();
  556. }
  557. } else {//image already loaded...
  558. onReady();
  559. }
  560. };
  561. s.preloadImages = function () {
  562. s.imagesToLoad = s.container.find('img');
  563. function _onReady() {
  564. if (typeof s === 'undefined' || s === null || !s) return;
  565. if (s.imagesLoaded !== undefined) s.imagesLoaded++;
  566. if (s.imagesLoaded === s.imagesToLoad.length) {
  567. if (s.params.updateOnImagesReady) s.update();
  568. s.emit('onImagesReady', s);
  569. }
  570. }
  571. for (var i = 0; i < s.imagesToLoad.length; i++) {
  572. s.loadImage(s.imagesToLoad[i], (s.imagesToLoad[i].currentSrc || s.imagesToLoad[i].getAttribute('src')), (s.imagesToLoad[i].srcset || s.imagesToLoad[i].getAttribute('srcset')), s.imagesToLoad[i].sizes || s.imagesToLoad[i].getAttribute('sizes'), true, _onReady);
  573. }
  574. };
  575. /*=========================
  576. Autoplay
  577. ===========================*/
  578. s.autoplayTimeoutId = undefined;
  579. s.autoplaying = false;
  580. s.autoplayPaused = false;
  581. function autoplay() {
  582. var autoplayDelay = s.params.autoplay;
  583. var activeSlide = s.slides.eq(s.activeIndex);
  584. if (activeSlide.attr('data-swiper-autoplay')) {
  585. autoplayDelay = activeSlide.attr('data-swiper-autoplay') || s.params.autoplay;
  586. }
  587. s.autoplayTimeoutId = setTimeout(function () {
  588. if (s.params.loop) {
  589. s.fixLoop();
  590. s._slideNext();
  591. s.emit('onAutoplay', s);
  592. }
  593. else {
  594. if (!s.isEnd) {
  595. s._slideNext();
  596. s.emit('onAutoplay', s);
  597. }
  598. else {
  599. if (!params.autoplayStopOnLast) {
  600. s._slideTo(0);
  601. s.emit('onAutoplay', s);
  602. }
  603. else {
  604. s.stopAutoplay();
  605. }
  606. }
  607. }
  608. }, autoplayDelay);
  609. }
  610. s.startAutoplay = function () {
  611. if (typeof s.autoplayTimeoutId !== 'undefined') return false;
  612. if (!s.params.autoplay) return false;
  613. if (s.autoplaying) return false;
  614. s.autoplaying = true;
  615. s.emit('onAutoplayStart', s);
  616. autoplay();
  617. };
  618. s.stopAutoplay = function (internal) {
  619. if (!s.autoplayTimeoutId) return;
  620. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  621. s.autoplaying = false;
  622. s.autoplayTimeoutId = undefined;
  623. s.emit('onAutoplayStop', s);
  624. };
  625. s.pauseAutoplay = function (speed) {
  626. if (s.autoplayPaused) return;
  627. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  628. s.autoplayPaused = true;
  629. if (speed === 0) {
  630. s.autoplayPaused = false;
  631. autoplay();
  632. }
  633. else {
  634. s.wrapper.transitionEnd(function () {
  635. if (!s) return;
  636. s.autoplayPaused = false;
  637. if (!s.autoplaying) {
  638. s.stopAutoplay();
  639. }
  640. else {
  641. autoplay();
  642. }
  643. });
  644. }
  645. };
  646. /*=========================
  647. Min/Max Translate
  648. ===========================*/
  649. s.minTranslate = function () {
  650. return (-s.snapGrid[0]);
  651. };
  652. s.maxTranslate = function () {
  653. return (-s.snapGrid[s.snapGrid.length - 1]);
  654. };
  655. /*=========================
  656. Slider/slides sizes
  657. ===========================*/
  658. s.updateAutoHeight = function () {
  659. var activeSlides = [];
  660. var newHeight = 0;
  661. var i;
  662. // Find slides currently in view
  663. if(s.params.slidesPerView !== 'auto' && s.params.slidesPerView > 1) {
  664. for (i = 0; i < Math.ceil(s.params.slidesPerView); i++) {
  665. var index = s.activeIndex + i;
  666. if(index > s.slides.length) break;
  667. activeSlides.push(s.slides.eq(index)[0]);
  668. }
  669. } else {
  670. activeSlides.push(s.slides.eq(s.activeIndex)[0]);
  671. }
  672. // Find new height from heighest slide in view
  673. for (i = 0; i < activeSlides.length; i++) {
  674. if (typeof activeSlides[i] !== 'undefined') {
  675. var height = activeSlides[i].offsetHeight;
  676. newHeight = height > newHeight ? height : newHeight;
  677. }
  678. }
  679. // Update Height
  680. if (newHeight) s.wrapper.css('height', newHeight + 'px');
  681. };
  682. s.updateContainerSize = function () {
  683. var width, height;
  684. if (typeof s.params.width !== 'undefined') {
  685. width = s.params.width;
  686. }
  687. else {
  688. width = s.container[0].clientWidth;
  689. }
  690. if (typeof s.params.height !== 'undefined') {
  691. height = s.params.height;
  692. }
  693. else {
  694. height = s.container[0].clientHeight;
  695. }
  696. if (width === 0 && s.isHorizontal() || height === 0 && !s.isHorizontal()) {
  697. return;
  698. }
  699. //Subtract paddings
  700. width = width - parseInt(s.container.css('padding-left'), 10) - parseInt(s.container.css('padding-right'), 10);
  701. height = height - parseInt(s.container.css('padding-top'), 10) - parseInt(s.container.css('padding-bottom'), 10);
  702. // Store values
  703. s.width = width;
  704. s.height = height;
  705. s.size = s.isHorizontal() ? s.width : s.height;
  706. };
  707. s.updateSlidesSize = function () {
  708. s.slides = s.wrapper.children('.' + s.params.slideClass);
  709. s.snapGrid = [];
  710. s.slidesGrid = [];
  711. s.slidesSizesGrid = [];
  712. var spaceBetween = s.params.spaceBetween,
  713. slidePosition = -s.params.slidesOffsetBefore,
  714. i,
  715. prevSlideSize = 0,
  716. index = 0;
  717. if (typeof s.size === 'undefined') return;
  718. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  719. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s.size;
  720. }
  721. s.virtualSize = -spaceBetween;
  722. // reset margins
  723. if (s.rtl) s.slides.css({marginLeft: '', marginTop: ''});
  724. else s.slides.css({marginRight: '', marginBottom: ''});
  725. var slidesNumberEvenToRows;
  726. if (s.params.slidesPerColumn > 1) {
  727. if (Math.floor(s.slides.length / s.params.slidesPerColumn) === s.slides.length / s.params.slidesPerColumn) {
  728. slidesNumberEvenToRows = s.slides.length;
  729. }
  730. else {
  731. slidesNumberEvenToRows = Math.ceil(s.slides.length / s.params.slidesPerColumn) * s.params.slidesPerColumn;
  732. }
  733. if (s.params.slidesPerView !== 'auto' && s.params.slidesPerColumnFill === 'row') {
  734. slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, s.params.slidesPerView * s.params.slidesPerColumn);
  735. }
  736. }
  737. // Calc slides
  738. var slideSize;
  739. var slidesPerColumn = s.params.slidesPerColumn;
  740. var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
  741. var numFullColumns = slidesPerRow - (s.params.slidesPerColumn * slidesPerRow - s.slides.length);
  742. for (i = 0; i < s.slides.length; i++) {
  743. slideSize = 0;
  744. var slide = s.slides.eq(i);
  745. if (s.params.slidesPerColumn > 1) {
  746. // Set slides order
  747. var newSlideOrderIndex;
  748. var column, row;
  749. if (s.params.slidesPerColumnFill === 'column') {
  750. column = Math.floor(i / slidesPerColumn);
  751. row = i - column * slidesPerColumn;
  752. if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn-1)) {
  753. if (++row >= slidesPerColumn) {
  754. row = 0;
  755. column++;
  756. }
  757. }
  758. newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
  759. slide
  760. .css({
  761. '-webkit-box-ordinal-group': newSlideOrderIndex,
  762. '-moz-box-ordinal-group': newSlideOrderIndex,
  763. '-ms-flex-order': newSlideOrderIndex,
  764. '-webkit-order': newSlideOrderIndex,
  765. 'order': newSlideOrderIndex
  766. });
  767. }
  768. else {
  769. row = Math.floor(i / slidesPerRow);
  770. column = i - row * slidesPerRow;
  771. }
  772. slide
  773. .css(
  774. 'margin-' + (s.isHorizontal() ? 'top' : 'left'),
  775. (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px')
  776. )
  777. .attr('data-swiper-column', column)
  778. .attr('data-swiper-row', row);
  779. }
  780. if (slide.css('display') === 'none') continue;
  781. if (s.params.slidesPerView === 'auto') {
  782. slideSize = s.isHorizontal() ? slide.outerWidth(true) : slide.outerHeight(true);
  783. if (s.params.roundLengths) slideSize = round(slideSize);
  784. }
  785. else {
  786. slideSize = (s.size - (s.params.slidesPerView - 1) * spaceBetween) / s.params.slidesPerView;
  787. if (s.params.roundLengths) slideSize = round(slideSize);
  788. if (s.isHorizontal()) {
  789. s.slides[i].style.width = slideSize + 'px';
  790. }
  791. else {
  792. s.slides[i].style.height = slideSize + 'px';
  793. }
  794. }
  795. s.slides[i].swiperSlideSize = slideSize;
  796. s.slidesSizesGrid.push(slideSize);
  797. if (s.params.centeredSlides) {
  798. slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
  799. if(prevSlideSize === 0 && i !== 0) slidePosition = slidePosition - s.size / 2 - spaceBetween;
  800. if (i === 0) slidePosition = slidePosition - s.size / 2 - spaceBetween;
  801. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  802. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  803. s.slidesGrid.push(slidePosition);
  804. }
  805. else {
  806. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  807. s.slidesGrid.push(slidePosition);
  808. slidePosition = slidePosition + slideSize + spaceBetween;
  809. }
  810. s.virtualSize += slideSize + spaceBetween;
  811. prevSlideSize = slideSize;
  812. index ++;
  813. }
  814. s.virtualSize = Math.max(s.virtualSize, s.size) + s.params.slidesOffsetAfter;
  815. var newSlidesGrid;
  816. if (
  817. s.rtl && s.wrongRTL && (s.params.effect === 'slide' || s.params.effect === 'coverflow')) {
  818. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  819. }
  820. if (!s.support.flexbox || s.params.setWrapperSize) {
  821. if (s.isHorizontal()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  822. else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
  823. }
  824. if (s.params.slidesPerColumn > 1) {
  825. s.virtualSize = (slideSize + s.params.spaceBetween) * slidesNumberEvenToRows;
  826. s.virtualSize = Math.ceil(s.virtualSize / s.params.slidesPerColumn) - s.params.spaceBetween;
  827. if (s.isHorizontal()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  828. else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
  829. if (s.params.centeredSlides) {
  830. newSlidesGrid = [];
  831. for (i = 0; i < s.snapGrid.length; i++) {
  832. if (s.snapGrid[i] < s.virtualSize + s.snapGrid[0]) newSlidesGrid.push(s.snapGrid[i]);
  833. }
  834. s.snapGrid = newSlidesGrid;
  835. }
  836. }
  837. // Remove last grid elements depending on width
  838. if (!s.params.centeredSlides) {
  839. newSlidesGrid = [];
  840. for (i = 0; i < s.snapGrid.length; i++) {
  841. if (s.snapGrid[i] <= s.virtualSize - s.size) {
  842. newSlidesGrid.push(s.snapGrid[i]);
  843. }
  844. }
  845. s.snapGrid = newSlidesGrid;
  846. if (Math.floor(s.virtualSize - s.size) - Math.floor(s.snapGrid[s.snapGrid.length - 1]) > 1) {
  847. s.snapGrid.push(s.virtualSize - s.size);
  848. }
  849. }
  850. if (s.snapGrid.length === 0) s.snapGrid = [0];
  851. if (s.params.spaceBetween !== 0) {
  852. if (s.isHorizontal()) {
  853. if (s.rtl) s.slides.css({marginLeft: spaceBetween + 'px'});
  854. else s.slides.css({marginRight: spaceBetween + 'px'});
  855. }
  856. else s.slides.css({marginBottom: spaceBetween + 'px'});
  857. }
  858. if (s.params.watchSlidesProgress) {
  859. s.updateSlidesOffset();
  860. }
  861. };
  862. s.updateSlidesOffset = function () {
  863. for (var i = 0; i < s.slides.length; i++) {
  864. s.slides[i].swiperSlideOffset = s.isHorizontal() ? s.slides[i].offsetLeft : s.slides[i].offsetTop;
  865. }
  866. };
  867. /*=========================
  868. Dynamic Slides Per View
  869. ===========================*/
  870. s.currentSlidesPerView = function () {
  871. var spv = 1, i, j;
  872. if (s.params.centeredSlides) {
  873. var size = s.slides[s.activeIndex].swiperSlideSize;
  874. var breakLoop;
  875. for (i = s.activeIndex + 1; i < s.slides.length; i++) {
  876. if (s.slides[i] && !breakLoop) {
  877. size += s.slides[i].swiperSlideSize;
  878. spv ++;
  879. if (size > s.size) breakLoop = true;
  880. }
  881. }
  882. for (j = s.activeIndex - 1; j >= 0; j--) {
  883. if (s.slides[j] && !breakLoop) {
  884. size += s.slides[j].swiperSlideSize;
  885. spv ++;
  886. if (size > s.size) breakLoop = true;
  887. }
  888. }
  889. }
  890. else {
  891. for (i = s.activeIndex + 1; i < s.slides.length; i++) {
  892. if (s.slidesGrid[i] - s.slidesGrid[s.activeIndex] < s.size) {
  893. spv++;
  894. }
  895. }
  896. }
  897. return spv;
  898. };
  899. /*=========================
  900. Slider/slides progress
  901. ===========================*/
  902. s.updateSlidesProgress = function (translate) {
  903. if (typeof translate === 'undefined') {
  904. translate = s.translate || 0;
  905. }
  906. if (s.slides.length === 0) return;
  907. if (typeof s.slides[0].swiperSlideOffset === 'undefined') s.updateSlidesOffset();
  908. var offsetCenter = -translate;
  909. if (s.rtl) offsetCenter = translate;
  910. // Visible Slides
  911. s.slides.removeClass(s.params.slideVisibleClass);
  912. for (var i = 0; i < s.slides.length; i++) {
  913. var slide = s.slides[i];
  914. var slideProgress = (offsetCenter + (s.params.centeredSlides ? s.minTranslate() : 0) - slide.swiperSlideOffset) / (slide.swiperSlideSize + s.params.spaceBetween);
  915. if (s.params.watchSlidesVisibility) {
  916. var slideBefore = -(offsetCenter - slide.swiperSlideOffset);
  917. var slideAfter = slideBefore + s.slidesSizesGrid[i];
  918. var isVisible =
  919. (slideBefore >= 0 && slideBefore < s.size) ||
  920. (slideAfter > 0 && slideAfter <= s.size) ||
  921. (slideBefore <= 0 && slideAfter >= s.size);
  922. if (isVisible) {
  923. s.slides.eq(i).addClass(s.params.slideVisibleClass);
  924. }
  925. }
  926. slide.progress = s.rtl ? -slideProgress : slideProgress;
  927. }
  928. };
  929. s.updateProgress = function (translate) {
  930. if (typeof translate === 'undefined') {
  931. translate = s.translate || 0;
  932. }
  933. var translatesDiff = s.maxTranslate() - s.minTranslate();
  934. var wasBeginning = s.isBeginning;
  935. var wasEnd = s.isEnd;
  936. if (translatesDiff === 0) {
  937. s.progress = 0;
  938. s.isBeginning = s.isEnd = true;
  939. }
  940. else {
  941. s.progress = (translate - s.minTranslate()) / (translatesDiff);
  942. s.isBeginning = s.progress <= 0;
  943. s.isEnd = s.progress >= 1;
  944. }
  945. if (s.isBeginning && !wasBeginning) s.emit('onReachBeginning', s);
  946. if (s.isEnd && !wasEnd) s.emit('onReachEnd', s);
  947. if (s.params.watchSlidesProgress) s.updateSlidesProgress(translate);
  948. s.emit('onProgress', s, s.progress);
  949. };
  950. s.updateActiveIndex = function () {
  951. var translate = s.rtl ? s.translate : -s.translate;
  952. var newActiveIndex, i, snapIndex;
  953. for (i = 0; i < s.slidesGrid.length; i ++) {
  954. if (typeof s.slidesGrid[i + 1] !== 'undefined') {
  955. if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1] - (s.slidesGrid[i + 1] - s.slidesGrid[i]) / 2) {
  956. newActiveIndex = i;
  957. }
  958. else if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1]) {
  959. newActiveIndex = i + 1;
  960. }
  961. }
  962. else {
  963. if (translate >= s.slidesGrid[i]) {
  964. newActiveIndex = i;
  965. }
  966. }
  967. }
  968. // Normalize slideIndex
  969. if(s.params.normalizeSlideIndex){
  970. if (newActiveIndex < 0 || typeof newActiveIndex === 'undefined') newActiveIndex = 0;
  971. }
  972. // for (i = 0; i < s.slidesGrid.length; i++) {
  973. // if (- translate >= s.slidesGrid[i]) {
  974. // newActiveIndex = i;
  975. // }
  976. // }
  977. snapIndex = Math.floor(newActiveIndex / s.params.slidesPerGroup);
  978. if (snapIndex >= s.snapGrid.length) snapIndex = s.snapGrid.length - 1;
  979. if (newActiveIndex === s.activeIndex) {
  980. return;
  981. }
  982. s.snapIndex = snapIndex;
  983. s.previousIndex = s.activeIndex;
  984. s.activeIndex = newActiveIndex;
  985. s.updateClasses();
  986. s.updateRealIndex();
  987. };
  988. s.updateRealIndex = function(){
  989. s.realIndex = parseInt(s.slides.eq(s.activeIndex).attr('data-swiper-slide-index') || s.activeIndex, 10);
  990. };
  991. /*=========================
  992. Classes
  993. ===========================*/
  994. s.updateClasses = function () {
  995. s.slides.removeClass(s.params.slideActiveClass + ' ' + s.params.slideNextClass + ' ' + s.params.slidePrevClass + ' ' + s.params.slideDuplicateActiveClass + ' ' + s.params.slideDuplicateNextClass + ' ' + s.params.slideDuplicatePrevClass);
  996. var activeSlide = s.slides.eq(s.activeIndex);
  997. // Active classes
  998. activeSlide.addClass(s.params.slideActiveClass);
  999. if (params.loop) {
  1000. // Duplicate to all looped slides
  1001. if (activeSlide.hasClass(s.params.slideDuplicateClass)) {
  1002. s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + s.realIndex + '"]').addClass(s.params.slideDuplicateActiveClass);
  1003. }
  1004. else {
  1005. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + s.realIndex + '"]').addClass(s.params.slideDuplicateActiveClass);
  1006. }
  1007. }
  1008. // Next Slide
  1009. var nextSlide = activeSlide.next('.' + s.params.slideClass).addClass(s.params.slideNextClass);
  1010. if (s.params.loop && nextSlide.length === 0) {
  1011. nextSlide = s.slides.eq(0);
  1012. nextSlide.addClass(s.params.slideNextClass);
  1013. }
  1014. // Prev Slide
  1015. var prevSlide = activeSlide.prev('.' + s.params.slideClass).addClass(s.params.slidePrevClass);
  1016. if (s.params.loop && prevSlide.length === 0) {
  1017. prevSlide = s.slides.eq(-1);
  1018. prevSlide.addClass(s.params.slidePrevClass);
  1019. }
  1020. if (params.loop) {
  1021. // Duplicate to all looped slides
  1022. if (nextSlide.hasClass(s.params.slideDuplicateClass)) {
  1023. s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + nextSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicateNextClass);
  1024. }
  1025. else {
  1026. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + nextSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicateNextClass);
  1027. }
  1028. if (prevSlide.hasClass(s.params.slideDuplicateClass)) {
  1029. s.wrapper.children('.' + s.params.slideClass + ':not(.' + s.params.slideDuplicateClass + ')[data-swiper-slide-index="' + prevSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicatePrevClass);
  1030. }
  1031. else {
  1032. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + prevSlide.attr('data-swiper-slide-index') + '"]').addClass(s.params.slideDuplicatePrevClass);
  1033. }
  1034. }
  1035. // Pagination
  1036. if (s.paginationContainer && s.paginationContainer.length > 0) {
  1037. // Current/Total
  1038. var current,
  1039. total = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  1040. if (s.params.loop) {
  1041. current = Math.ceil((s.activeIndex - s.loopedSlides)/s.params.slidesPerGroup);
  1042. if (current > s.slides.length - 1 - s.loopedSlides * 2) {
  1043. current = current - (s.slides.length - s.loopedSlides * 2);
  1044. }
  1045. if (current > total - 1) current = current - total;
  1046. if (current < 0 && s.params.paginationType !== 'bullets') current = total + current;
  1047. }
  1048. else {
  1049. if (typeof s.snapIndex !== 'undefined') {
  1050. current = s.snapIndex;
  1051. }
  1052. else {
  1053. current = s.activeIndex || 0;
  1054. }
  1055. }
  1056. // Types
  1057. if (s.params.paginationType === 'bullets' && s.bullets && s.bullets.length > 0) {
  1058. s.bullets.removeClass(s.params.bulletActiveClass);
  1059. if (s.paginationContainer.length > 1) {
  1060. s.bullets.each(function () {
  1061. if ($(this).index() === current) $(this).addClass(s.params.bulletActiveClass);
  1062. });
  1063. }
  1064. else {
  1065. s.bullets.eq(current).addClass(s.params.bulletActiveClass);
  1066. }
  1067. }
  1068. if (s.params.paginationType === 'fraction') {
  1069. s.paginationContainer.find('.' + s.params.paginationCurrentClass).text(current + 1);
  1070. s.paginationContainer.find('.' + s.params.paginationTotalClass).text(total);
  1071. }
  1072. if (s.params.paginationType === 'progress') {
  1073. var scale = (current + 1) / total,
  1074. scaleX = scale,
  1075. scaleY = 1;
  1076. if (!s.isHorizontal()) {
  1077. scaleY = scale;
  1078. scaleX = 1;
  1079. }
  1080. s.paginationContainer.find('.' + s.params.paginationProgressbarClass).transform('translate3d(0,0,0) scaleX(' + scaleX + ') scaleY(' + scaleY + ')').transition(s.params.speed);
  1081. }
  1082. if (s.params.paginationType === 'custom' && s.params.paginationCustomRender) {
  1083. s.paginationContainer.html(s.params.paginationCustomRender(s, current + 1, total));
  1084. s.emit('onPaginationRendered', s, s.paginationContainer[0]);
  1085. }
  1086. }
  1087. // Next/active buttons
  1088. if (!s.params.loop) {
  1089. if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) {
  1090. if (s.isBeginning) {
  1091. s.prevButton.addClass(s.params.buttonDisabledClass);
  1092. if (s.params.a11y && s.a11y) s.a11y.disable(s.prevButton);
  1093. }
  1094. else {
  1095. s.prevButton.removeClass(s.params.buttonDisabledClass);
  1096. if (s.params.a11y && s.a11y) s.a11y.enable(s.prevButton);
  1097. }
  1098. }
  1099. if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) {
  1100. if (s.isEnd) {
  1101. s.nextButton.addClass(s.params.buttonDisabledClass);
  1102. if (s.params.a11y && s.a11y) s.a11y.disable(s.nextButton);
  1103. }
  1104. else {
  1105. s.nextButton.removeClass(s.params.buttonDisabledClass);
  1106. if (s.params.a11y && s.a11y) s.a11y.enable(s.nextButton);
  1107. }
  1108. }
  1109. }
  1110. };
  1111. /*=========================
  1112. Pagination
  1113. ===========================*/
  1114. s.updatePagination = function () {
  1115. if (!s.params.pagination) return;
  1116. if (s.paginationContainer && s.paginationContainer.length > 0) {
  1117. var paginationHTML = '';
  1118. if (s.params.paginationType === 'bullets') {
  1119. var numberOfBullets = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  1120. for (var i = 0; i < numberOfBullets; i++) {
  1121. if (s.params.paginationBulletRender) {
  1122. paginationHTML += s.params.paginationBulletRender(s, i, s.params.bulletClass);
  1123. }
  1124. else {
  1125. paginationHTML += '<' + s.params.paginationElement+' class="' + s.params.bulletClass + '"></' + s.params.paginationElement + '>';
  1126. }
  1127. }
  1128. s.paginationContainer.html(paginationHTML);
  1129. s.bullets = s.paginationContainer.find('.' + s.params.bulletClass);
  1130. if (s.params.paginationClickable && s.params.a11y && s.a11y) {
  1131. s.a11y.initPagination();
  1132. }
  1133. }
  1134. if (s.params.paginationType === 'fraction') {
  1135. if (s.params.paginationFractionRender) {
  1136. paginationHTML = s.params.paginationFractionRender(s, s.params.paginationCurrentClass, s.params.paginationTotalClass);
  1137. }
  1138. else {
  1139. paginationHTML =
  1140. '<span class="' + s.params.paginationCurrentClass + '"></span>' +
  1141. ' / ' +
  1142. '<span class="' + s.params.paginationTotalClass+'"></span>';
  1143. }
  1144. s.paginationContainer.html(paginationHTML);
  1145. }
  1146. if (s.params.paginationType === 'progress') {
  1147. if (s.params.paginationProgressRender) {
  1148. paginationHTML = s.params.paginationProgressRender(s, s.params.paginationProgressbarClass);
  1149. }
  1150. else {
  1151. paginationHTML = '<span class="' + s.params.paginationProgressbarClass + '"></span>';
  1152. }
  1153. s.paginationContainer.html(paginationHTML);
  1154. }
  1155. if (s.params.paginationType !== 'custom') {
  1156. s.emit('onPaginationRendered', s, s.paginationContainer[0]);
  1157. }
  1158. }
  1159. };
  1160. /*=========================
  1161. Common update method
  1162. ===========================*/
  1163. s.update = function (updateTranslate) {
  1164. if (!s) return;
  1165. s.updateContainerSize();
  1166. s.updateSlidesSize();
  1167. s.updateProgress();
  1168. s.updatePagination();
  1169. s.updateClasses();
  1170. if (s.params.scrollbar && s.scrollbar) {
  1171. s.scrollbar.set();
  1172. }
  1173. var newTranslate;
  1174. function forceSetTranslate() {
  1175. var translate = s.rtl ? -s.translate : s.translate;
  1176. newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  1177. s.setWrapperTranslate(newTranslate);
  1178. s.updateActiveIndex();
  1179. s.updateClasses();
  1180. }
  1181. if (updateTranslate) {
  1182. var translated;
  1183. if (s.controller && s.controller.spline) {
  1184. s.controller.spline = undefined;
  1185. }
  1186. if (s.params.freeMode) {
  1187. forceSetTranslate();
  1188. if (s.params.autoHeight) {
  1189. s.updateAutoHeight();
  1190. }
  1191. }
  1192. else {
  1193. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  1194. translated = s.slideTo(s.slides.length - 1, 0, false, true);
  1195. }
  1196. else {
  1197. translated = s.slideTo(s.activeIndex, 0, false, true);
  1198. }
  1199. if (!translated) {
  1200. forceSetTranslate();
  1201. }
  1202. }
  1203. }
  1204. else if (s.params.autoHeight) {
  1205. s.updateAutoHeight();
  1206. }
  1207. };
  1208. /*=========================
  1209. Resize Handler
  1210. ===========================*/
  1211. s.onResize = function (forceUpdatePagination) {
  1212. if (s.params.onBeforeResize) s.params.onBeforeResize(s);
  1213. //Breakpoints
  1214. if (s.params.breakpoints) {
  1215. s.setBreakpoint();
  1216. }
  1217. // Disable locks on resize
  1218. var allowSwipeToPrev = s.params.allowSwipeToPrev;
  1219. var allowSwipeToNext = s.params.allowSwipeToNext;
  1220. s.params.allowSwipeToPrev = s.params.allowSwipeToNext = true;
  1221. s.updateContainerSize();
  1222. s.updateSlidesSize();
  1223. if (s.params.slidesPerView === 'auto' || s.params.freeMode || forceUpdatePagination) s.updatePagination();
  1224. if (s.params.scrollbar && s.scrollbar) {
  1225. s.scrollbar.set();
  1226. }
  1227. if (s.controller && s.controller.spline) {
  1228. s.controller.spline = undefined;
  1229. }
  1230. var slideChangedBySlideTo = false;
  1231. if (s.params.freeMode) {
  1232. var newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  1233. s.setWrapperTranslate(newTranslate);
  1234. s.updateActiveIndex();
  1235. s.updateClasses();
  1236. if (s.params.autoHeight) {
  1237. s.updateAutoHeight();
  1238. }
  1239. }
  1240. else {
  1241. s.updateClasses();
  1242. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  1243. slideChangedBySlideTo = s.slideTo(s.slides.length - 1, 0, false, true);
  1244. }
  1245. else {
  1246. slideChangedBySlideTo = s.slideTo(s.activeIndex, 0, false, true);
  1247. }
  1248. }
  1249. if (s.params.lazyLoading && !slideChangedBySlideTo && s.lazy) {
  1250. s.lazy.load();
  1251. }
  1252. // Return locks after resize
  1253. s.params.allowSwipeToPrev = allowSwipeToPrev;
  1254. s.params.allowSwipeToNext = allowSwipeToNext;
  1255. if (s.params.onAfterResize) s.params.onAfterResize(s);
  1256. };
  1257. /*=========================
  1258. Events
  1259. ===========================*/
  1260. //Define Touch Events
  1261. s.touchEventsDesktop = {start: 'mousedown', move: 'mousemove', end: 'mouseup'};
  1262. if (window.navigator.pointerEnabled) s.touchEventsDesktop = {start: 'pointerdown', move: 'pointermove', end: 'pointerup'};
  1263. else if (window.navigator.msPointerEnabled) s.touchEventsDesktop = {start: 'MSPointerDown', move: 'MSPointerMove', end: 'MSPointerUp'};
  1264. s.touchEvents = {
  1265. start : s.support.touch || !s.params.simulateTouch ? 'touchstart' : s.touchEventsDesktop.start,
  1266. move : s.support.touch || !s.params.simulateTouch ? 'touchmove' : s.touchEventsDesktop.move,
  1267. end : s.support.touch || !s.params.simulateTouch ? 'touchend' : s.touchEventsDesktop.end
  1268. };
  1269. // WP8 Touch Events Fix
  1270. if (window.navigator.pointerEnabled || window.navigator.msPointerEnabled) {
  1271. (s.params.touchEventsTarget === 'container' ? s.container : s.wrapper).addClass('swiper-wp8-' + s.params.direction);
  1272. }
  1273. // Attach/detach events
  1274. s.initEvents = function (detach) {
  1275. var actionDom = detach ? 'off' : 'on';
  1276. var action = detach ? 'removeEventListener' : 'addEventListener';
  1277. var touchEventsTarget = s.params.touchEventsTarget === 'container' ? s.container[0] : s.wrapper[0];
  1278. var target = s.support.touch ? touchEventsTarget : document;
  1279. var moveCapture = s.params.nested ? true : false;
  1280. //Touch Events
  1281. if (s.browser.ie) {
  1282. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  1283. target[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  1284. target[action](s.touchEvents.end, s.onTouchEnd, false);
  1285. }
  1286. else {
  1287. if (s.support.touch) {
  1288. var passiveListener = s.touchEvents.start === 'touchstart' && s.support.passiveListener && s.params.passiveListeners ? {passive: true, capture: false} : false;
  1289. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, passiveListener);
  1290. touchEventsTarget[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  1291. touchEventsTarget[action](s.touchEvents.end, s.onTouchEnd, passiveListener);
  1292. }
  1293. if ((params.simulateTouch && !s.device.ios && !s.device.android) || (params.simulateTouch && !s.support.touch && s.device.ios)) {
  1294. touchEventsTarget[action]('mousedown', s.onTouchStart, false);
  1295. document[action]('mousemove', s.onTouchMove, moveCapture);
  1296. document[action]('mouseup', s.onTouchEnd, false);
  1297. }
  1298. }
  1299. window[action]('resize', s.onResize);
  1300. // Next, Prev, Index
  1301. if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) {
  1302. s.nextButton[actionDom]('click', s.onClickNext);
  1303. if (s.params.a11y && s.a11y) s.nextButton[actionDom]('keydown', s.a11y.onEnterKey);
  1304. }
  1305. if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) {
  1306. s.prevButton[actionDom]('click', s.onClickPrev);
  1307. if (s.params.a11y && s.a11y) s.prevButton[actionDom]('keydown', s.a11y.onEnterKey);
  1308. }
  1309. if (s.params.pagination && s.params.paginationClickable) {
  1310. s.paginationContainer[actionDom]('click', '.' + s.params.bulletClass, s.onClickIndex);
  1311. if (s.params.a11y && s.a11y) s.paginationContainer[actionDom]('keydown', '.' + s.params.bulletClass, s.a11y.onEnterKey);
  1312. }
  1313. // Prevent Links Clicks
  1314. if (s.params.preventClicks || s.params.preventClicksPropagation) touchEventsTarget[action]('click', s.preventClicks, true);
  1315. };
  1316. s.attachEvents = function () {
  1317. s.initEvents();
  1318. };
  1319. s.detachEvents = function () {
  1320. s.initEvents(true);
  1321. };
  1322. /*=========================
  1323. Handle Clicks
  1324. ===========================*/
  1325. // Prevent Clicks
  1326. s.allowClick = true;
  1327. s.preventClicks = function (e) {
  1328. if (!s.allowClick) {
  1329. if (s.params.preventClicks) e.preventDefault();
  1330. if (s.params.preventClicksPropagation && s.animating) {
  1331. e.stopPropagation();
  1332. e.stopImmediatePropagation();
  1333. }
  1334. }
  1335. };
  1336. // Clicks
  1337. s.onClickNext = function (e) {
  1338. e.preventDefault();
  1339. if (s.isEnd && !s.params.loop) return;
  1340. s.slideNext();
  1341. };
  1342. s.onClickPrev = function (e) {
  1343. e.preventDefault();
  1344. if (s.isBeginning && !s.params.loop) return;
  1345. s.slidePrev();
  1346. };
  1347. s.onClickIndex = function (e) {
  1348. e.preventDefault();
  1349. var index = $(this).index() * s.params.slidesPerGroup;
  1350. if (s.params.loop) index = index + s.loopedSlides;
  1351. s.slideTo(index);
  1352. };
  1353. /*=========================
  1354. Handle Touches
  1355. ===========================*/
  1356. function findElementInEvent(e, selector) {
  1357. var el = $(e.target);
  1358. if (!el.is(selector)) {
  1359. if (typeof selector === 'string') {
  1360. el = el.parents(selector);
  1361. }
  1362. else if (selector.nodeType) {
  1363. var found;
  1364. el.parents().each(function (index, _el) {
  1365. if (_el === selector) found = selector;
  1366. });
  1367. if (!found) return undefined;
  1368. else return selector;
  1369. }
  1370. }
  1371. if (el.length === 0) {
  1372. return undefined;
  1373. }
  1374. return el[0];
  1375. }
  1376. s.updateClickedSlide = function (e) {
  1377. var slide = findElementInEvent(e, '.' + s.params.slideClass);
  1378. var slideFound = false;
  1379. if (slide) {
  1380. for (var i = 0; i < s.slides.length; i++) {
  1381. if (s.slides[i] === slide) slideFound = true;
  1382. }
  1383. }
  1384. if (slide && slideFound) {
  1385. s.clickedSlide = slide;
  1386. s.clickedIndex = $(slide).index();
  1387. }
  1388. else {
  1389. s.clickedSlide = undefined;
  1390. s.clickedIndex = undefined;
  1391. return;
  1392. }
  1393. if (s.params.slideToClickedSlide && s.clickedIndex !== undefined && s.clickedIndex !== s.activeIndex) {
  1394. var slideToIndex = s.clickedIndex,
  1395. realIndex,
  1396. duplicatedSlides,
  1397. slidesPerView = s.params.slidesPerView === 'auto' ? s.currentSlidesPerView() : s.params.slidesPerView;
  1398. if (s.params.loop) {
  1399. if (s.animating) return;
  1400. realIndex = parseInt($(s.clickedSlide).attr('data-swiper-slide-index'), 10);
  1401. if (s.params.centeredSlides) {
  1402. if ((slideToIndex < s.loopedSlides - slidesPerView/2) || (slideToIndex > s.slides.length - s.loopedSlides + slidesPerView/2)) {
  1403. s.fixLoop();
  1404. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.' + s.params.slideDuplicateClass + ')').eq(0).index();
  1405. setTimeout(function () {
  1406. s.slideTo(slideToIndex);
  1407. }, 0);
  1408. }
  1409. else {
  1410. s.slideTo(slideToIndex);
  1411. }
  1412. }
  1413. else {
  1414. if (slideToIndex > s.slides.length - slidesPerView) {
  1415. s.fixLoop();
  1416. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.' + s.params.slideDuplicateClass + ')').eq(0).index();
  1417. setTimeout(function () {
  1418. s.slideTo(slideToIndex);
  1419. }, 0);
  1420. }
  1421. else {
  1422. s.slideTo(slideToIndex);
  1423. }
  1424. }
  1425. }
  1426. else {
  1427. s.slideTo(slideToIndex);
  1428. }
  1429. }
  1430. };
  1431. var isTouched,
  1432. isMoved,
  1433. allowTouchCallbacks,
  1434. touchStartTime,
  1435. isScrolling,
  1436. currentTranslate,
  1437. startTranslate,
  1438. allowThresholdMove,
  1439. // Form elements to match
  1440. formElements = 'input, select, textarea, button, video',
  1441. // Last click time
  1442. lastClickTime = Date.now(), clickTimeout,
  1443. //Velocities
  1444. velocities = [],
  1445. allowMomentumBounce;
  1446. // Animating Flag
  1447. s.animating = false;
  1448. // Touches information
  1449. s.touches = {
  1450. startX: 0,
  1451. startY: 0,
  1452. currentX: 0,
  1453. currentY: 0,
  1454. diff: 0
  1455. };
  1456. // Touch handlers
  1457. var isTouchEvent, startMoving;
  1458. s.onTouchStart = function (e) {
  1459. if (e.originalEvent) e = e.originalEvent;
  1460. isTouchEvent = e.type === 'touchstart';
  1461. if (!isTouchEvent && 'which' in e && e.which === 3) return;
  1462. if (s.params.noSwiping && findElementInEvent(e, '.' + s.params.noSwipingClass)) {
  1463. s.allowClick = true;
  1464. return;
  1465. }
  1466. if (s.params.swipeHandler) {
  1467. if (!findElementInEvent(e, s.params.swipeHandler)) return;
  1468. }
  1469. var startX = s.touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  1470. var startY = s.touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  1471. // Do NOT start if iOS edge swipe is detected. Otherwise iOS app (UIWebView) cannot swipe-to-go-back anymore
  1472. if(s.device.ios && s.params.iOSEdgeSwipeDetection && startX <= s.params.iOSEdgeSwipeThreshold) {
  1473. return;
  1474. }
  1475. isTouched = true;
  1476. isMoved = false;
  1477. allowTouchCallbacks = true;
  1478. isScrolling = undefined;
  1479. startMoving = undefined;
  1480. s.touches.startX = startX;
  1481. s.touches.startY = startY;
  1482. touchStartTime = Date.now();
  1483. s.allowClick = true;
  1484. s.updateContainerSize();
  1485. s.swipeDirection = undefined;
  1486. if (s.params.threshold > 0) allowThresholdMove = false;
  1487. if (e.type !== 'touchstart') {
  1488. var preventDefault = true;
  1489. if ($(e.target).is(formElements)) preventDefault = false;
  1490. if (document.activeElement && $(document.activeElement).is(formElements)) {
  1491. document.activeElement.blur();
  1492. }
  1493. if (preventDefault) {
  1494. e.preventDefault();
  1495. }
  1496. }
  1497. s.emit('onTouchStart', s, e);
  1498. };
  1499. s.onTouchMove = function (e) {
  1500. if (e.originalEvent) e = e.originalEvent;
  1501. if (isTouchEvent && e.type === 'mousemove') return;
  1502. if (e.preventedByNestedSwiper) {
  1503. s.touches.startX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1504. s.touches.startY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1505. return;
  1506. }
  1507. if (s.params.onlyExternal) {
  1508. // isMoved = true;
  1509. s.allowClick = false;
  1510. if (isTouched) {
  1511. s.touches.startX = s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1512. s.touches.startY = s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1513. touchStartTime = Date.now();
  1514. }
  1515. return;
  1516. }
  1517. if (isTouchEvent && s.params.touchReleaseOnEdges && !s.params.loop) {
  1518. if (!s.isHorizontal()) {
  1519. // Vertical
  1520. if (
  1521. (s.touches.currentY < s.touches.startY && s.translate <= s.maxTranslate()) ||
  1522. (s.touches.currentY > s.touches.startY && s.translate >= s.minTranslate())
  1523. ) {
  1524. return;
  1525. }
  1526. }
  1527. else {
  1528. if (
  1529. (s.touches.currentX < s.touches.startX && s.translate <= s.maxTranslate()) ||
  1530. (s.touches.currentX > s.touches.startX && s.translate >= s.minTranslate())
  1531. ) {
  1532. return;
  1533. }
  1534. }
  1535. }
  1536. if (isTouchEvent && document.activeElement) {
  1537. if (e.target === document.activeElement && $(e.target).is(formElements)) {
  1538. isMoved = true;
  1539. s.allowClick = false;
  1540. return;
  1541. }
  1542. }
  1543. if (allowTouchCallbacks) {
  1544. s.emit('onTouchMove', s, e);
  1545. }
  1546. if (e.targetTouches && e.targetTouches.length > 1) return;
  1547. s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1548. s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1549. if (typeof isScrolling === 'undefined') {
  1550. var touchAngle;
  1551. if (s.isHorizontal() && s.touches.currentY === s.touches.startY || !s.isHorizontal() && s.touches.currentX === s.touches.startX) {
  1552. isScrolling = false;
  1553. }
  1554. else {
  1555. touchAngle = Math.atan2(Math.abs(s.touches.currentY - s.touches.startY), Math.abs(s.touches.currentX - s.touches.startX)) * 180 / Math.PI;
  1556. isScrolling = s.isHorizontal() ? touchAngle > s.params.touchAngle : (90 - touchAngle > s.params.touchAngle);
  1557. }
  1558. }
  1559. if (isScrolling) {
  1560. s.emit('onTouchMoveOpposite', s, e);
  1561. }
  1562. if (typeof startMoving === 'undefined') {
  1563. if (s.touches.currentX !== s.touches.startX || s.touches.currentY !== s.touches.startY) {
  1564. startMoving = true;
  1565. }
  1566. }
  1567. if (!isTouched) return;
  1568. if (isScrolling) {
  1569. isTouched = false;
  1570. return;
  1571. }
  1572. if (!startMoving) {
  1573. return;
  1574. }
  1575. s.allowClick = false;
  1576. s.emit('onSliderMove', s, e);
  1577. e.preventDefault();
  1578. if (s.params.touchMoveStopPropagation && !s.params.nested) {
  1579. e.stopPropagation();
  1580. }
  1581. if (!isMoved) {
  1582. if (params.loop) {
  1583. s.fixLoop();
  1584. }
  1585. startTranslate = s.getWrapperTranslate();
  1586. s.setWrapperTransition(0);
  1587. if (s.animating) {
  1588. s.wrapper.trigger('webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd msTransitionEnd');
  1589. }
  1590. if (s.params.autoplay && s.autoplaying) {
  1591. if (s.params.autoplayDisableOnInteraction) {
  1592. s.stopAutoplay();
  1593. }
  1594. else {
  1595. s.pauseAutoplay();
  1596. }
  1597. }
  1598. allowMomentumBounce = false;
  1599. //Grab Cursor
  1600. if (s.params.grabCursor && (s.params.allowSwipeToNext === true || s.params.allowSwipeToPrev === true)) {
  1601. s.setGrabCursor(true);
  1602. }
  1603. }
  1604. isMoved = true;
  1605. var diff = s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1606. diff = diff * s.params.touchRatio;
  1607. if (s.rtl) diff = -diff;
  1608. s.swipeDirection = diff > 0 ? 'prev' : 'next';
  1609. currentTranslate = diff + startTranslate;
  1610. var disableParentSwiper = true;
  1611. if ((diff > 0 && currentTranslate > s.minTranslate())) {
  1612. disableParentSwiper = false;
  1613. if (s.params.resistance) currentTranslate = s.minTranslate() - 1 + Math.pow(-s.minTranslate() + startTranslate + diff, s.params.resistanceRatio);
  1614. }
  1615. else if (diff < 0 && currentTranslate < s.maxTranslate()) {
  1616. disableParentSwiper = false;
  1617. if (s.params.resistance) currentTranslate = s.maxTranslate() + 1 - Math.pow(s.maxTranslate() - startTranslate - diff, s.params.resistanceRatio);
  1618. }
  1619. if (disableParentSwiper) {
  1620. e.preventedByNestedSwiper = true;
  1621. }
  1622. // Directions locks
  1623. if (!s.params.allowSwipeToNext && s.swipeDirection === 'next' && currentTranslate < startTranslate) {
  1624. currentTranslate = startTranslate;
  1625. }
  1626. if (!s.params.allowSwipeToPrev && s.swipeDirection === 'prev' && currentTranslate > startTranslate) {
  1627. currentTranslate = startTranslate;
  1628. }
  1629. // Threshold
  1630. if (s.params.threshold > 0) {
  1631. if (Math.abs(diff) > s.params.threshold || allowThresholdMove) {
  1632. if (!allowThresholdMove) {
  1633. allowThresholdMove = true;
  1634. s.touches.startX = s.touches.currentX;
  1635. s.touches.startY = s.touches.currentY;
  1636. currentTranslate = startTranslate;
  1637. s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1638. return;
  1639. }
  1640. }
  1641. else {
  1642. currentTranslate = startTranslate;
  1643. return;
  1644. }
  1645. }
  1646. if (!s.params.followFinger) return;
  1647. // Update active index in free mode
  1648. if (s.params.freeMode || s.params.watchSlidesProgress) {
  1649. s.updateActiveIndex();
  1650. }
  1651. if (s.params.freeMode) {
  1652. //Velocity
  1653. if (velocities.length === 0) {
  1654. velocities.push({
  1655. position: s.touches[s.isHorizontal() ? 'startX' : 'startY'],
  1656. time: touchStartTime
  1657. });
  1658. }
  1659. velocities.push({
  1660. position: s.touches[s.isHorizontal() ? 'currentX' : 'currentY'],
  1661. time: (new window.Date()).getTime()
  1662. });
  1663. }
  1664. // Update progress
  1665. s.updateProgress(currentTranslate);
  1666. // Update translate
  1667. s.setWrapperTranslate(currentTranslate);
  1668. };
  1669. s.onTouchEnd = function (e) {
  1670. if (e.originalEvent) e = e.originalEvent;
  1671. if (allowTouchCallbacks) {
  1672. s.emit('onTouchEnd', s, e);
  1673. }
  1674. allowTouchCallbacks = false;
  1675. if (!isTouched) return;
  1676. //Return Grab Cursor
  1677. if (s.params.grabCursor && isMoved && isTouched && (s.params.allowSwipeToNext === true || s.params.allowSwipeToPrev === true)) {
  1678. s.setGrabCursor(false);
  1679. }
  1680. // Time diff
  1681. var touchEndTime = Date.now();
  1682. var timeDiff = touchEndTime - touchStartTime;
  1683. // Tap, doubleTap, Click
  1684. if (s.allowClick) {
  1685. s.updateClickedSlide(e);
  1686. s.emit('onTap', s, e);
  1687. if (timeDiff < 300 && (touchEndTime - lastClickTime) > 300) {
  1688. if (clickTimeout) clearTimeout(clickTimeout);
  1689. clickTimeout = setTimeout(function () {
  1690. if (!s) return;
  1691. if (s.params.paginationHide && s.paginationContainer.length > 0 && !$(e.target).hasClass(s.params.bulletClass)) {
  1692. s.paginationContainer.toggleClass(s.params.paginationHiddenClass);
  1693. }
  1694. s.emit('onClick', s, e);
  1695. }, 300);
  1696. }
  1697. if (timeDiff < 300 && (touchEndTime - lastClickTime) < 300) {
  1698. if (clickTimeout) clearTimeout(clickTimeout);
  1699. s.emit('onDoubleTap', s, e);
  1700. }
  1701. }
  1702. lastClickTime = Date.now();
  1703. setTimeout(function () {
  1704. if (s) s.allowClick = true;
  1705. }, 0);
  1706. if (!isTouched || !isMoved || !s.swipeDirection || s.touches.diff === 0 || currentTranslate === startTranslate) {
  1707. isTouched = isMoved = false;
  1708. return;
  1709. }
  1710. isTouched = isMoved = false;
  1711. var currentPos;
  1712. if (s.params.followFinger) {
  1713. currentPos = s.rtl ? s.translate : -s.translate;
  1714. }
  1715. else {
  1716. currentPos = -currentTranslate;
  1717. }
  1718. if (s.params.freeMode) {
  1719. if (currentPos < -s.minTranslate()) {
  1720. s.slideTo(s.activeIndex);
  1721. return;
  1722. }
  1723. else if (currentPos > -s.maxTranslate()) {
  1724. if (s.slides.length < s.snapGrid.length) {
  1725. s.slideTo(s.snapGrid.length - 1);
  1726. }
  1727. else {
  1728. s.slideTo(s.slides.length - 1);
  1729. }
  1730. return;
  1731. }
  1732. if (s.params.freeModeMomentum) {
  1733. if (velocities.length > 1) {
  1734. var lastMoveEvent = velocities.pop(), velocityEvent = velocities.pop();
  1735. var distance = lastMoveEvent.position - velocityEvent.position;
  1736. var time = lastMoveEvent.time - velocityEvent.time;
  1737. s.velocity = distance / time;
  1738. s.velocity = s.velocity / 2;
  1739. if (Math.abs(s.velocity) < s.params.freeModeMinimumVelocity) {
  1740. s.velocity = 0;
  1741. }
  1742. // this implies that the user stopped moving a finger then released.
  1743. // There would be no events with distance zero, so the last event is stale.
  1744. if (time > 150 || (new window.Date().getTime() - lastMoveEvent.time) > 300) {
  1745. s.velocity = 0;
  1746. }
  1747. } else {
  1748. s.velocity = 0;
  1749. }
  1750. s.velocity = s.velocity * s.params.freeModeMomentumVelocityRatio;
  1751. velocities.length = 0;
  1752. var momentumDuration = 1000 * s.params.freeModeMomentumRatio;
  1753. var momentumDistance = s.velocity * momentumDuration;
  1754. var newPosition = s.translate + momentumDistance;
  1755. if (s.rtl) newPosition = - newPosition;
  1756. var doBounce = false;
  1757. var afterBouncePosition;
  1758. var bounceAmount = Math.abs(s.velocity) * 20 * s.params.freeModeMomentumBounceRatio;
  1759. if (newPosition < s.maxTranslate()) {
  1760. if (s.params.freeModeMomentumBounce) {
  1761. if (newPosition + s.maxTranslate() < -bounceAmount) {
  1762. newPosition = s.maxTranslate() - bounceAmount;
  1763. }
  1764. afterBouncePosition = s.maxTranslate();
  1765. doBounce = true;
  1766. allowMomentumBounce = true;
  1767. }
  1768. else {
  1769. newPosition = s.maxTranslate();
  1770. }
  1771. }
  1772. else if (newPosition > s.minTranslate()) {
  1773. if (s.params.freeModeMomentumBounce) {
  1774. if (newPosition - s.minTranslate() > bounceAmount) {
  1775. newPosition = s.minTranslate() + bounceAmount;
  1776. }
  1777. afterBouncePosition = s.minTranslate();
  1778. doBounce = true;
  1779. allowMomentumBounce = true;
  1780. }
  1781. else {
  1782. newPosition = s.minTranslate();
  1783. }
  1784. }
  1785. else if (s.params.freeModeSticky) {
  1786. var j = 0,
  1787. nextSlide;
  1788. for (j = 0; j < s.snapGrid.length; j += 1) {
  1789. if (s.snapGrid[j] > -newPosition) {
  1790. nextSlide = j;
  1791. break;
  1792. }
  1793. }
  1794. if (Math.abs(s.snapGrid[nextSlide] - newPosition) < Math.abs(s.snapGrid[nextSlide - 1] - newPosition) || s.swipeDirection === 'next') {
  1795. newPosition = s.snapGrid[nextSlide];
  1796. } else {
  1797. newPosition = s.snapGrid[nextSlide - 1];
  1798. }
  1799. if (!s.rtl) newPosition = - newPosition;
  1800. }
  1801. //Fix duration
  1802. if (s.velocity !== 0) {
  1803. if (s.rtl) {
  1804. momentumDuration = Math.abs((-newPosition - s.translate) / s.velocity);
  1805. }
  1806. else {
  1807. momentumDuration = Math.abs((newPosition - s.translate) / s.velocity);
  1808. }
  1809. }
  1810. else if (s.params.freeModeSticky) {
  1811. s.slideReset();
  1812. return;
  1813. }
  1814. if (s.params.freeModeMomentumBounce && doBounce) {
  1815. s.updateProgress(afterBouncePosition);
  1816. s.setWrapperTransition(momentumDuration);
  1817. s.setWrapperTranslate(newPosition);
  1818. s.onTransitionStart();
  1819. s.animating = true;
  1820. s.wrapper.transitionEnd(function () {
  1821. if (!s || !allowMomentumBounce) return;
  1822. s.emit('onMomentumBounce', s);
  1823. s.setWrapperTransition(s.params.speed);
  1824. s.setWrapperTranslate(afterBouncePosition);
  1825. s.wrapper.transitionEnd(function () {
  1826. if (!s) return;
  1827. s.onTransitionEnd();
  1828. });
  1829. });
  1830. } else if (s.velocity) {
  1831. s.updateProgress(newPosition);
  1832. s.setWrapperTransition(momentumDuration);
  1833. s.setWrapperTranslate(newPosition);
  1834. s.onTransitionStart();
  1835. if (!s.animating) {
  1836. s.animating = true;
  1837. s.wrapper.transitionEnd(function () {
  1838. if (!s) return;
  1839. s.onTransitionEnd();
  1840. });
  1841. }
  1842. } else {
  1843. s.updateProgress(newPosition);
  1844. }
  1845. s.updateActiveIndex();
  1846. }
  1847. if (!s.params.freeModeMomentum || timeDiff >= s.params.longSwipesMs) {
  1848. s.updateProgress();
  1849. s.updateActiveIndex();
  1850. }
  1851. return;
  1852. }
  1853. // Find current slide
  1854. var i, stopIndex = 0, groupSize = s.slidesSizesGrid[0];
  1855. for (i = 0; i < s.slidesGrid.length; i += s.params.slidesPerGroup) {
  1856. if (typeof s.slidesGrid[i + s.params.slidesPerGroup] !== 'undefined') {
  1857. if (currentPos >= s.slidesGrid[i] && currentPos < s.slidesGrid[i + s.params.slidesPerGroup]) {
  1858. stopIndex = i;
  1859. groupSize = s.slidesGrid[i + s.params.slidesPerGroup] - s.slidesGrid[i];
  1860. }
  1861. }
  1862. else {
  1863. if (currentPos >= s.slidesGrid[i]) {
  1864. stopIndex = i;
  1865. groupSize = s.slidesGrid[s.slidesGrid.length - 1] - s.slidesGrid[s.slidesGrid.length - 2];
  1866. }
  1867. }
  1868. }
  1869. // Find current slide size
  1870. var ratio = (currentPos - s.slidesGrid[stopIndex]) / groupSize;
  1871. if (timeDiff > s.params.longSwipesMs) {
  1872. // Long touches
  1873. if (!s.params.longSwipes) {
  1874. s.slideTo(s.activeIndex);
  1875. return;
  1876. }
  1877. if (s.swipeDirection === 'next') {
  1878. if (ratio >= s.params.longSwipesRatio) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1879. else s.slideTo(stopIndex);
  1880. }
  1881. if (s.swipeDirection === 'prev') {
  1882. if (ratio > (1 - s.params.longSwipesRatio)) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1883. else s.slideTo(stopIndex);
  1884. }
  1885. }
  1886. else {
  1887. // Short swipes
  1888. if (!s.params.shortSwipes) {
  1889. s.slideTo(s.activeIndex);
  1890. return;
  1891. }
  1892. if (s.swipeDirection === 'next') {
  1893. s.slideTo(stopIndex + s.params.slidesPerGroup);
  1894. }
  1895. if (s.swipeDirection === 'prev') {
  1896. s.slideTo(stopIndex);
  1897. }
  1898. }
  1899. };
  1900. /*=========================
  1901. Transitions
  1902. ===========================*/
  1903. s._slideTo = function (slideIndex, speed) {
  1904. return s.slideTo(slideIndex, speed, true, true);
  1905. };
  1906. s.slideTo = function (slideIndex, speed, runCallbacks, internal) {
  1907. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1908. if (typeof slideIndex === 'undefined') slideIndex = 0;
  1909. if (slideIndex < 0) slideIndex = 0;
  1910. s.snapIndex = Math.floor(slideIndex / s.params.slidesPerGroup);
  1911. if (s.snapIndex >= s.snapGrid.length) s.snapIndex = s.snapGrid.length - 1;
  1912. var translate = - s.snapGrid[s.snapIndex];
  1913. // Stop autoplay
  1914. if (s.params.autoplay && s.autoplaying) {
  1915. if (internal || !s.params.autoplayDisableOnInteraction) {
  1916. s.pauseAutoplay(speed);
  1917. }
  1918. else {
  1919. s.stopAutoplay();
  1920. }
  1921. }
  1922. // Update progress
  1923. s.updateProgress(translate);
  1924. // Normalize slideIndex
  1925. if(s.params.normalizeSlideIndex){
  1926. for (var i = 0; i < s.slidesGrid.length; i++) {
  1927. if (- Math.floor(translate * 100) >= Math.floor(s.slidesGrid[i] * 100)) {
  1928. slideIndex = i;
  1929. }
  1930. }
  1931. }
  1932. // Directions locks
  1933. if (!s.params.allowSwipeToNext && translate < s.translate && translate < s.minTranslate()) {
  1934. return false;
  1935. }
  1936. if (!s.params.allowSwipeToPrev && translate > s.translate && translate > s.maxTranslate()) {
  1937. if ((s.activeIndex || 0) !== slideIndex ) return false;
  1938. }
  1939. // Update Index
  1940. if (typeof speed === 'undefined') speed = s.params.speed;
  1941. s.previousIndex = s.activeIndex || 0;
  1942. s.activeIndex = slideIndex;
  1943. s.updateRealIndex();
  1944. if ((s.rtl && -translate === s.translate) || (!s.rtl && translate === s.translate)) {
  1945. // Update Height
  1946. if (s.params.autoHeight) {
  1947. s.updateAutoHeight();
  1948. }
  1949. s.updateClasses();
  1950. if (s.params.effect !== 'slide') {
  1951. s.setWrapperTranslate(translate);
  1952. }
  1953. return false;
  1954. }
  1955. s.updateClasses();
  1956. s.onTransitionStart(runCallbacks);
  1957. if (speed === 0 || s.browser.lteIE9) {
  1958. s.setWrapperTranslate(translate);
  1959. s.setWrapperTransition(0);
  1960. s.onTransitionEnd(runCallbacks);
  1961. }
  1962. else {
  1963. s.setWrapperTranslate(translate);
  1964. s.setWrapperTransition(speed);
  1965. if (!s.animating) {
  1966. s.animating = true;
  1967. s.wrapper.transitionEnd(function () {
  1968. if (!s) return;
  1969. s.onTransitionEnd(runCallbacks);
  1970. });
  1971. }
  1972. }
  1973. return true;
  1974. };
  1975. s.onTransitionStart = function (runCallbacks) {
  1976. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1977. if (s.params.autoHeight) {
  1978. s.updateAutoHeight();
  1979. }
  1980. if (s.lazy) s.lazy.onTransitionStart();
  1981. if (runCallbacks) {
  1982. s.emit('onTransitionStart', s);
  1983. if (s.activeIndex !== s.previousIndex) {
  1984. s.emit('onSlideChangeStart', s);
  1985. if (s.activeIndex > s.previousIndex) {
  1986. s.emit('onSlideNextStart', s);
  1987. }
  1988. else {
  1989. s.emit('onSlidePrevStart', s);
  1990. }
  1991. }
  1992. }
  1993. };
  1994. s.onTransitionEnd = function (runCallbacks) {
  1995. s.animating = false;
  1996. s.setWrapperTransition(0);
  1997. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1998. if (s.lazy) s.lazy.onTransitionEnd();
  1999. if (runCallbacks) {
  2000. s.emit('onTransitionEnd', s);
  2001. if (s.activeIndex !== s.previousIndex) {
  2002. s.emit('onSlideChangeEnd', s);
  2003. if (s.activeIndex > s.previousIndex) {
  2004. s.emit('onSlideNextEnd', s);
  2005. }
  2006. else {
  2007. s.emit('onSlidePrevEnd', s);
  2008. }
  2009. }
  2010. }
  2011. if (s.params.history && s.history) {
  2012. s.history.setHistory(s.params.history, s.activeIndex);
  2013. }
  2014. if (s.params.hashnav && s.hashnav) {
  2015. s.hashnav.setHash();
  2016. }
  2017. };
  2018. s.slideNext = function (runCallbacks, speed, internal) {
  2019. if (s.params.loop) {
  2020. if (s.animating) return false;
  2021. s.fixLoop();
  2022. var clientLeft = s.container[0].clientLeft;
  2023. return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  2024. }
  2025. else return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  2026. };
  2027. s._slideNext = function (speed) {
  2028. return s.slideNext(true, speed, true);
  2029. };
  2030. s.slidePrev = function (runCallbacks, speed, internal) {
  2031. if (s.params.loop) {
  2032. if (s.animating) return false;
  2033. s.fixLoop();
  2034. var clientLeft = s.container[0].clientLeft;
  2035. return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  2036. }
  2037. else return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  2038. };
  2039. s._slidePrev = function (speed) {
  2040. return s.slidePrev(true, speed, true);
  2041. };
  2042. s.slideReset = function (runCallbacks, speed, internal) {
  2043. return s.slideTo(s.activeIndex, speed, runCallbacks);
  2044. };
  2045. s.disableTouchControl = function () {
  2046. s.params.onlyExternal = true;
  2047. return true;
  2048. };
  2049. s.enableTouchControl = function () {
  2050. s.params.onlyExternal = false;
  2051. return true;
  2052. };
  2053. /*=========================
  2054. Translate/transition helpers
  2055. ===========================*/
  2056. s.setWrapperTransition = function (duration, byController) {
  2057. s.wrapper.transition(duration);
  2058. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  2059. s.effects[s.params.effect].setTransition(duration);
  2060. }
  2061. if (s.params.parallax && s.parallax) {
  2062. s.parallax.setTransition(duration);
  2063. }
  2064. if (s.params.scrollbar && s.scrollbar) {
  2065. s.scrollbar.setTransition(duration);
  2066. }
  2067. if (s.params.control && s.controller) {
  2068. s.controller.setTransition(duration, byController);
  2069. }
  2070. s.emit('onSetTransition', s, duration);
  2071. };
  2072. s.setWrapperTranslate = function (translate, updateActiveIndex, byController) {
  2073. var x = 0, y = 0, z = 0;
  2074. if (s.isHorizontal()) {
  2075. x = s.rtl ? -translate : translate;
  2076. }
  2077. else {
  2078. y = translate;
  2079. }
  2080. if (s.params.roundLengths) {
  2081. x = round(x);
  2082. y = round(y);
  2083. }
  2084. if (!s.params.virtualTranslate) {
  2085. if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)');
  2086. else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)');
  2087. }
  2088. s.translate = s.isHorizontal() ? x : y;
  2089. // Check if we need to update progress
  2090. var progress;
  2091. var translatesDiff = s.maxTranslate() - s.minTranslate();
  2092. if (translatesDiff === 0) {
  2093. progress = 0;
  2094. }
  2095. else {
  2096. progress = (translate - s.minTranslate()) / (translatesDiff);
  2097. }
  2098. if (progress !== s.progress) {
  2099. s.updateProgress(translate);
  2100. }
  2101. if (updateActiveIndex) s.updateActiveIndex();
  2102. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  2103. s.effects[s.params.effect].setTranslate(s.translate);
  2104. }
  2105. if (s.params.parallax && s.parallax) {
  2106. s.parallax.setTranslate(s.translate);
  2107. }
  2108. if (s.params.scrollbar && s.scrollbar) {
  2109. s.scrollbar.setTranslate(s.translate);
  2110. }
  2111. if (s.params.control && s.controller) {
  2112. s.controller.setTranslate(s.translate, byController);
  2113. }
  2114. s.emit('onSetTranslate', s, s.translate);
  2115. };
  2116. s.getTranslate = function (el, axis) {
  2117. var matrix, curTransform, curStyle, transformMatrix;
  2118. // automatic axis detection
  2119. if (typeof axis === 'undefined') {
  2120. axis = 'x';
  2121. }
  2122. if (s.params.virtualTranslate) {
  2123. return s.rtl ? -s.translate : s.translate;
  2124. }
  2125. curStyle = window.getComputedStyle(el, null);
  2126. if (window.WebKitCSSMatrix) {
  2127. curTransform = curStyle.transform || curStyle.webkitTransform;
  2128. if (curTransform.split(',').length > 6) {
  2129. curTransform = curTransform.split(', ').map(function(a){
  2130. return a.replace(',','.');
  2131. }).join(', ');
  2132. }
  2133. // Some old versions of Webkit choke when 'none' is passed; pass
  2134. // empty string instead in this case
  2135. transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
  2136. }
  2137. else {
  2138. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  2139. matrix = transformMatrix.toString().split(',');
  2140. }
  2141. if (axis === 'x') {
  2142. //Latest Chrome and webkits Fix
  2143. if (window.WebKitCSSMatrix)
  2144. curTransform = transformMatrix.m41;
  2145. //Crazy IE10 Matrix
  2146. else if (matrix.length === 16)
  2147. curTransform = parseFloat(matrix[12]);
  2148. //Normal Browsers
  2149. else
  2150. curTransform = parseFloat(matrix[4]);
  2151. }
  2152. if (axis === 'y') {
  2153. //Latest Chrome and webkits Fix
  2154. if (window.WebKitCSSMatrix)
  2155. curTransform = transformMatrix.m42;
  2156. //Crazy IE10 Matrix
  2157. else if (matrix.length === 16)
  2158. curTransform = parseFloat(matrix[13]);
  2159. //Normal Browsers
  2160. else
  2161. curTransform = parseFloat(matrix[5]);
  2162. }
  2163. if (s.rtl && curTransform) curTransform = -curTransform;
  2164. return curTransform || 0;
  2165. };
  2166. s.getWrapperTranslate = function (axis) {
  2167. if (typeof axis === 'undefined') {
  2168. axis = s.isHorizontal() ? 'x' : 'y';
  2169. }
  2170. return s.getTranslate(s.wrapper[0], axis);
  2171. };
  2172. /*=========================
  2173. Observer
  2174. ===========================*/
  2175. s.observers = [];
  2176. function initObserver(target, options) {
  2177. options = options || {};
  2178. // create an observer instance
  2179. var ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
  2180. var observer = new ObserverFunc(function (mutations) {
  2181. mutations.forEach(function (mutation) {
  2182. s.onResize(true);
  2183. s.emit('onObserverUpdate', s, mutation);
  2184. });
  2185. });
  2186. observer.observe(target, {
  2187. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  2188. childList: typeof options.childList === 'undefined' ? true : options.childList,
  2189. characterData: typeof options.characterData === 'undefined' ? true : options.characterData
  2190. });
  2191. s.observers.push(observer);
  2192. }
  2193. s.initObservers = function () {
  2194. if (s.params.observeParents) {
  2195. var containerParents = s.container.parents();
  2196. for (var i = 0; i < containerParents.length; i++) {
  2197. initObserver(containerParents[i]);
  2198. }
  2199. }
  2200. // Observe container
  2201. initObserver(s.container[0], {childList: false});
  2202. // Observe wrapper
  2203. initObserver(s.wrapper[0], {attributes: false});
  2204. };
  2205. s.disconnectObservers = function () {
  2206. for (var i = 0; i < s.observers.length; i++) {
  2207. s.observers[i].disconnect();
  2208. }
  2209. s.observers = [];
  2210. };
  2211. /*=========================
  2212. Loop
  2213. ===========================*/
  2214. // Create looped slides
  2215. s.createLoop = function () {
  2216. // Remove duplicated slides
  2217. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  2218. var slides = s.wrapper.children('.' + s.params.slideClass);
  2219. if(s.params.slidesPerView === 'auto' && !s.params.loopedSlides) s.params.loopedSlides = slides.length;
  2220. s.loopedSlides = parseInt(s.params.loopedSlides || s.params.slidesPerView, 10);
  2221. s.loopedSlides = s.loopedSlides + s.params.loopAdditionalSlides;
  2222. if (s.loopedSlides > slides.length) {
  2223. s.loopedSlides = slides.length;
  2224. }
  2225. var prependSlides = [], appendSlides = [], i;
  2226. slides.each(function (index, el) {
  2227. var slide = $(this);
  2228. if (index < s.loopedSlides) appendSlides.push(el);
  2229. if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el);
  2230. slide.attr('data-swiper-slide-index', index);
  2231. });
  2232. for (i = 0; i < appendSlides.length; i++) {
  2233. s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  2234. }
  2235. for (i = prependSlides.length - 1; i >= 0; i--) {
  2236. s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  2237. }
  2238. };
  2239. s.destroyLoop = function () {
  2240. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  2241. s.slides.removeAttr('data-swiper-slide-index');
  2242. };
  2243. s.reLoop = function (updatePosition) {
  2244. var oldIndex = s.activeIndex - s.loopedSlides;
  2245. s.destroyLoop();
  2246. s.createLoop();
  2247. s.updateSlidesSize();
  2248. if (updatePosition) {
  2249. s.slideTo(oldIndex + s.loopedSlides, 0, false);
  2250. }
  2251. };
  2252. s.fixLoop = function () {
  2253. var newIndex;
  2254. //Fix For Negative Oversliding
  2255. if (s.activeIndex < s.loopedSlides) {
  2256. newIndex = s.slides.length - s.loopedSlides * 3 + s.activeIndex;
  2257. newIndex = newIndex + s.loopedSlides;
  2258. s.slideTo(newIndex, 0, false, true);
  2259. }
  2260. //Fix For Positive Oversliding
  2261. else if ((s.params.slidesPerView === 'auto' && s.activeIndex >= s.loopedSlides * 2) || (s.activeIndex > s.slides.length - s.params.slidesPerView * 2)) {
  2262. newIndex = -s.slides.length + s.activeIndex + s.loopedSlides;
  2263. newIndex = newIndex + s.loopedSlides;
  2264. s.slideTo(newIndex, 0, false, true);
  2265. }
  2266. };
  2267. /*=========================
  2268. Append/Prepend/Remove Slides
  2269. ===========================*/
  2270. s.appendSlide = function (slides) {
  2271. if (s.params.loop) {
  2272. s.destroyLoop();
  2273. }
  2274. if (typeof slides === 'object' && slides.length) {
  2275. for (var i = 0; i < slides.length; i++) {
  2276. if (slides[i]) s.wrapper.append(slides[i]);
  2277. }
  2278. }
  2279. else {
  2280. s.wrapper.append(slides);
  2281. }
  2282. if (s.params.loop) {
  2283. s.createLoop();
  2284. }
  2285. if (!(s.params.observer && s.support.observer)) {
  2286. s.update(true);
  2287. }
  2288. };
  2289. s.prependSlide = function (slides) {
  2290. if (s.params.loop) {
  2291. s.destroyLoop();
  2292. }
  2293. var newActiveIndex = s.activeIndex + 1;
  2294. if (typeof slides === 'object' && slides.length) {
  2295. for (var i = 0; i < slides.length; i++) {
  2296. if (slides[i]) s.wrapper.prepend(slides[i]);
  2297. }
  2298. newActiveIndex = s.activeIndex + slides.length;
  2299. }
  2300. else {
  2301. s.wrapper.prepend(slides);
  2302. }
  2303. if (s.params.loop) {
  2304. s.createLoop();
  2305. }
  2306. if (!(s.params.observer && s.support.observer)) {
  2307. s.update(true);
  2308. }
  2309. s.slideTo(newActiveIndex, 0, false);
  2310. };
  2311. s.removeSlide = function (slidesIndexes) {
  2312. if (s.params.loop) {
  2313. s.destroyLoop();
  2314. s.slides = s.wrapper.children('.' + s.params.slideClass);
  2315. }
  2316. var newActiveIndex = s.activeIndex,
  2317. indexToRemove;
  2318. if (typeof slidesIndexes === 'object' && slidesIndexes.length) {
  2319. for (var i = 0; i < slidesIndexes.length; i++) {
  2320. indexToRemove = slidesIndexes[i];
  2321. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  2322. if (indexToRemove < newActiveIndex) newActiveIndex--;
  2323. }
  2324. newActiveIndex = Math.max(newActiveIndex, 0);
  2325. }
  2326. else {
  2327. indexToRemove = slidesIndexes;
  2328. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  2329. if (indexToRemove < newActiveIndex) newActiveIndex--;
  2330. newActiveIndex = Math.max(newActiveIndex, 0);
  2331. }
  2332. if (s.params.loop) {
  2333. s.createLoop();
  2334. }
  2335. if (!(s.params.observer && s.support.observer)) {
  2336. s.update(true);
  2337. }
  2338. if (s.params.loop) {
  2339. s.slideTo(newActiveIndex + s.loopedSlides, 0, false);
  2340. }
  2341. else {
  2342. s.slideTo(newActiveIndex, 0, false);
  2343. }
  2344. };
  2345. s.removeAllSlides = function () {
  2346. var slidesIndexes = [];
  2347. for (var i = 0; i < s.slides.length; i++) {
  2348. slidesIndexes.push(i);
  2349. }
  2350. s.removeSlide(slidesIndexes);
  2351. };
  2352. /*=========================
  2353. Effects
  2354. ===========================*/
  2355. s.effects = {
  2356. fade: {
  2357. setTranslate: function () {
  2358. for (var i = 0; i < s.slides.length; i++) {
  2359. var slide = s.slides.eq(i);
  2360. var offset = slide[0].swiperSlideOffset;
  2361. var tx = -offset;
  2362. if (!s.params.virtualTranslate) tx = tx - s.translate;
  2363. var ty = 0;
  2364. if (!s.isHorizontal()) {
  2365. ty = tx;
  2366. tx = 0;
  2367. }
  2368. var slideOpacity = s.params.fade.crossFade ?
  2369. Math.max(1 - Math.abs(slide[0].progress), 0) :
  2370. 1 + Math.min(Math.max(slide[0].progress, -1), 0);
  2371. slide
  2372. .css({
  2373. opacity: slideOpacity
  2374. })
  2375. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px)');
  2376. }
  2377. },
  2378. setTransition: function (duration) {
  2379. s.slides.transition(duration);
  2380. if (s.params.virtualTranslate && duration !== 0) {
  2381. var eventTriggered = false;
  2382. s.slides.transitionEnd(function () {
  2383. if (eventTriggered) return;
  2384. if (!s) return;
  2385. eventTriggered = true;
  2386. s.animating = false;
  2387. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  2388. for (var i = 0; i < triggerEvents.length; i++) {
  2389. s.wrapper.trigger(triggerEvents[i]);
  2390. }
  2391. });
  2392. }
  2393. }
  2394. },
  2395. flip: {
  2396. setTranslate: function () {
  2397. for (var i = 0; i < s.slides.length; i++) {
  2398. var slide = s.slides.eq(i);
  2399. var progress = slide[0].progress;
  2400. if (s.params.flip.limitRotation) {
  2401. progress = Math.max(Math.min(slide[0].progress, 1), -1);
  2402. }
  2403. var offset = slide[0].swiperSlideOffset;
  2404. var rotate = -180 * progress,
  2405. rotateY = rotate,
  2406. rotateX = 0,
  2407. tx = -offset,
  2408. ty = 0;
  2409. if (!s.isHorizontal()) {
  2410. ty = tx;
  2411. tx = 0;
  2412. rotateX = -rotateY;
  2413. rotateY = 0;
  2414. }
  2415. else if (s.rtl) {
  2416. rotateY = -rotateY;
  2417. }
  2418. slide[0].style.zIndex = -Math.abs(Math.round(progress)) + s.slides.length;
  2419. if (s.params.flip.slideShadows) {
  2420. //Set shadows
  2421. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2422. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2423. if (shadowBefore.length === 0) {
  2424. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2425. slide.append(shadowBefore);
  2426. }
  2427. if (shadowAfter.length === 0) {
  2428. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2429. slide.append(shadowAfter);
  2430. }
  2431. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  2432. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  2433. }
  2434. slide
  2435. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)');
  2436. }
  2437. },
  2438. setTransition: function (duration) {
  2439. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2440. if (s.params.virtualTranslate && duration !== 0) {
  2441. var eventTriggered = false;
  2442. s.slides.eq(s.activeIndex).transitionEnd(function () {
  2443. if (eventTriggered) return;
  2444. if (!s) return;
  2445. if (!$(this).hasClass(s.params.slideActiveClass)) return;
  2446. eventTriggered = true;
  2447. s.animating = false;
  2448. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  2449. for (var i = 0; i < triggerEvents.length; i++) {
  2450. s.wrapper.trigger(triggerEvents[i]);
  2451. }
  2452. });
  2453. }
  2454. }
  2455. },
  2456. cube: {
  2457. setTranslate: function () {
  2458. var wrapperRotate = 0, cubeShadow;
  2459. if (s.params.cube.shadow) {
  2460. if (s.isHorizontal()) {
  2461. cubeShadow = s.wrapper.find('.swiper-cube-shadow');
  2462. if (cubeShadow.length === 0) {
  2463. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  2464. s.wrapper.append(cubeShadow);
  2465. }
  2466. cubeShadow.css({height: s.width + 'px'});
  2467. }
  2468. else {
  2469. cubeShadow = s.container.find('.swiper-cube-shadow');
  2470. if (cubeShadow.length === 0) {
  2471. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  2472. s.container.append(cubeShadow);
  2473. }
  2474. }
  2475. }
  2476. for (var i = 0; i < s.slides.length; i++) {
  2477. var slide = s.slides.eq(i);
  2478. var slideAngle = i * 90;
  2479. var round = Math.floor(slideAngle / 360);
  2480. if (s.rtl) {
  2481. slideAngle = -slideAngle;
  2482. round = Math.floor(-slideAngle / 360);
  2483. }
  2484. var progress = Math.max(Math.min(slide[0].progress, 1), -1);
  2485. var tx = 0, ty = 0, tz = 0;
  2486. if (i % 4 === 0) {
  2487. tx = - round * 4 * s.size;
  2488. tz = 0;
  2489. }
  2490. else if ((i - 1) % 4 === 0) {
  2491. tx = 0;
  2492. tz = - round * 4 * s.size;
  2493. }
  2494. else if ((i - 2) % 4 === 0) {
  2495. tx = s.size + round * 4 * s.size;
  2496. tz = s.size;
  2497. }
  2498. else if ((i - 3) % 4 === 0) {
  2499. tx = - s.size;
  2500. tz = 3 * s.size + s.size * 4 * round;
  2501. }
  2502. if (s.rtl) {
  2503. tx = -tx;
  2504. }
  2505. if (!s.isHorizontal()) {
  2506. ty = tx;
  2507. tx = 0;
  2508. }
  2509. var transform = 'rotateX(' + (s.isHorizontal() ? 0 : -slideAngle) + 'deg) rotateY(' + (s.isHorizontal() ? slideAngle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)';
  2510. if (progress <= 1 && progress > -1) {
  2511. wrapperRotate = i * 90 + progress * 90;
  2512. if (s.rtl) wrapperRotate = -i * 90 - progress * 90;
  2513. }
  2514. slide.transform(transform);
  2515. if (s.params.cube.slideShadows) {
  2516. //Set shadows
  2517. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2518. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2519. if (shadowBefore.length === 0) {
  2520. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2521. slide.append(shadowBefore);
  2522. }
  2523. if (shadowAfter.length === 0) {
  2524. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2525. slide.append(shadowAfter);
  2526. }
  2527. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  2528. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  2529. }
  2530. }
  2531. s.wrapper.css({
  2532. '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2533. '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2534. '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2535. 'transform-origin': '50% 50% -' + (s.size / 2) + 'px'
  2536. });
  2537. if (s.params.cube.shadow) {
  2538. if (s.isHorizontal()) {
  2539. 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) + ')');
  2540. }
  2541. else {
  2542. var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
  2543. var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
  2544. var scale1 = s.params.cube.shadowScale,
  2545. scale2 = s.params.cube.shadowScale / multiplier,
  2546. offset = s.params.cube.shadowOffset;
  2547. cubeShadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotateX(-90deg)');
  2548. }
  2549. }
  2550. var zFactor = (s.isSafari || s.isUiWebView) ? (-s.size / 2) : 0;
  2551. s.wrapper.transform('translate3d(0px,0,' + zFactor + 'px) rotateX(' + (s.isHorizontal() ? 0 : wrapperRotate) + 'deg) rotateY(' + (s.isHorizontal() ? -wrapperRotate : 0) + 'deg)');
  2552. },
  2553. setTransition: function (duration) {
  2554. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2555. if (s.params.cube.shadow && !s.isHorizontal()) {
  2556. s.container.find('.swiper-cube-shadow').transition(duration);
  2557. }
  2558. }
  2559. },
  2560. coverflow: {
  2561. setTranslate: function () {
  2562. var transform = s.translate;
  2563. var center = s.isHorizontal() ? -transform + s.width / 2 : -transform + s.height / 2;
  2564. var rotate = s.isHorizontal() ? s.params.coverflow.rotate: -s.params.coverflow.rotate;
  2565. var translate = s.params.coverflow.depth;
  2566. //Each slide offset from center
  2567. for (var i = 0, length = s.slides.length; i < length; i++) {
  2568. var slide = s.slides.eq(i);
  2569. var slideSize = s.slidesSizesGrid[i];
  2570. var slideOffset = slide[0].swiperSlideOffset;
  2571. var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier;
  2572. var rotateY = s.isHorizontal() ? rotate * offsetMultiplier : 0;
  2573. var rotateX = s.isHorizontal() ? 0 : rotate * offsetMultiplier;
  2574. // var rotateZ = 0
  2575. var translateZ = -translate * Math.abs(offsetMultiplier);
  2576. var translateY = s.isHorizontal() ? 0 : s.params.coverflow.stretch * (offsetMultiplier);
  2577. var translateX = s.isHorizontal() ? s.params.coverflow.stretch * (offsetMultiplier) : 0;
  2578. //Fix for ultra small values
  2579. if (Math.abs(translateX) < 0.001) translateX = 0;
  2580. if (Math.abs(translateY) < 0.001) translateY = 0;
  2581. if (Math.abs(translateZ) < 0.001) translateZ = 0;
  2582. if (Math.abs(rotateY) < 0.001) rotateY = 0;
  2583. if (Math.abs(rotateX) < 0.001) rotateX = 0;
  2584. var slideTransform = 'translate3d(' + translateX + 'px,' + translateY + 'px,' + translateZ + 'px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)';
  2585. slide.transform(slideTransform);
  2586. slide[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
  2587. if (s.params.coverflow.slideShadows) {
  2588. //Set shadows
  2589. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2590. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2591. if (shadowBefore.length === 0) {
  2592. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2593. slide.append(shadowBefore);
  2594. }
  2595. if (shadowAfter.length === 0) {
  2596. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2597. slide.append(shadowAfter);
  2598. }
  2599. if (shadowBefore.length) shadowBefore[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
  2600. if (shadowAfter.length) shadowAfter[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0;
  2601. }
  2602. }
  2603. //Set correct perspective for IE10
  2604. if (s.browser.ie) {
  2605. var ws = s.wrapper[0].style;
  2606. ws.perspectiveOrigin = center + 'px 50%';
  2607. }
  2608. },
  2609. setTransition: function (duration) {
  2610. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2611. }
  2612. }
  2613. };
  2614. /*=========================
  2615. Images Lazy Loading
  2616. ===========================*/
  2617. s.lazy = {
  2618. initialImageLoaded: false,
  2619. loadImageInSlide: function (index, loadInDuplicate) {
  2620. if (typeof index === 'undefined') return;
  2621. if (typeof loadInDuplicate === 'undefined') loadInDuplicate = true;
  2622. if (s.slides.length === 0) return;
  2623. var slide = s.slides.eq(index);
  2624. var img = slide.find('.' + s.params.lazyLoadingClass + ':not(.' + s.params.lazyStatusLoadedClass + '):not(.' + s.params.lazyStatusLoadingClass + ')');
  2625. if (slide.hasClass(s.params.lazyLoadingClass) && !slide.hasClass(s.params.lazyStatusLoadedClass) && !slide.hasClass(s.params.lazyStatusLoadingClass)) {
  2626. img = img.add(slide[0]);
  2627. }
  2628. if (img.length === 0) return;
  2629. img.each(function () {
  2630. var _img = $(this);
  2631. _img.addClass(s.params.lazyStatusLoadingClass);
  2632. var background = _img.attr('data-background');
  2633. var src = _img.attr('data-src'),
  2634. srcset = _img.attr('data-srcset'),
  2635. sizes = _img.attr('data-sizes');
  2636. s.loadImage(_img[0], (src || background), srcset, sizes, false, function () {
  2637. if (typeof s === 'undefined' || s === null || !s) return;
  2638. if (background) {
  2639. _img.css('background-image', 'url("' + background + '")');
  2640. _img.removeAttr('data-background');
  2641. }
  2642. else {
  2643. if (srcset) {
  2644. _img.attr('srcset', srcset);
  2645. _img.removeAttr('data-srcset');
  2646. }
  2647. if (sizes) {
  2648. _img.attr('sizes', sizes);
  2649. _img.removeAttr('data-sizes');
  2650. }
  2651. if (src) {
  2652. _img.attr('src', src);
  2653. _img.removeAttr('data-src');
  2654. }
  2655. }
  2656. _img.addClass(s.params.lazyStatusLoadedClass).removeClass(s.params.lazyStatusLoadingClass);
  2657. slide.find('.' + s.params.lazyPreloaderClass + ', .' + s.params.preloaderClass).remove();
  2658. if (s.params.loop && loadInDuplicate) {
  2659. var slideOriginalIndex = slide.attr('data-swiper-slide-index');
  2660. if (slide.hasClass(s.params.slideDuplicateClass)) {
  2661. var originalSlide = s.wrapper.children('[data-swiper-slide-index="' + slideOriginalIndex + '"]:not(.' + s.params.slideDuplicateClass + ')');
  2662. s.lazy.loadImageInSlide(originalSlide.index(), false);
  2663. }
  2664. else {
  2665. var duplicatedSlide = s.wrapper.children('.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + slideOriginalIndex + '"]');
  2666. s.lazy.loadImageInSlide(duplicatedSlide.index(), false);
  2667. }
  2668. }
  2669. s.emit('onLazyImageReady', s, slide[0], _img[0]);
  2670. });
  2671. s.emit('onLazyImageLoad', s, slide[0], _img[0]);
  2672. });
  2673. },
  2674. load: function () {
  2675. var i;
  2676. var slidesPerView = s.params.slidesPerView;
  2677. if (slidesPerView === 'auto') {
  2678. slidesPerView = 0;
  2679. }
  2680. if (!s.lazy.initialImageLoaded) s.lazy.initialImageLoaded = true;
  2681. if (s.params.watchSlidesVisibility) {
  2682. s.wrapper.children('.' + s.params.slideVisibleClass).each(function () {
  2683. s.lazy.loadImageInSlide($(this).index());
  2684. });
  2685. }
  2686. else {
  2687. if (slidesPerView > 1) {
  2688. for (i = s.activeIndex; i < s.activeIndex + slidesPerView ; i++) {
  2689. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2690. }
  2691. }
  2692. else {
  2693. s.lazy.loadImageInSlide(s.activeIndex);
  2694. }
  2695. }
  2696. if (s.params.lazyLoadingInPrevNext) {
  2697. if (slidesPerView > 1 || (s.params.lazyLoadingInPrevNextAmount && s.params.lazyLoadingInPrevNextAmount > 1)) {
  2698. var amount = s.params.lazyLoadingInPrevNextAmount;
  2699. var spv = slidesPerView;
  2700. var maxIndex = Math.min(s.activeIndex + spv + Math.max(amount, spv), s.slides.length);
  2701. var minIndex = Math.max(s.activeIndex - Math.max(spv, amount), 0);
  2702. // Next Slides
  2703. for (i = s.activeIndex + slidesPerView; i < maxIndex; i++) {
  2704. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2705. }
  2706. // Prev Slides
  2707. for (i = minIndex; i < s.activeIndex ; i++) {
  2708. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2709. }
  2710. }
  2711. else {
  2712. var nextSlide = s.wrapper.children('.' + s.params.slideNextClass);
  2713. if (nextSlide.length > 0) s.lazy.loadImageInSlide(nextSlide.index());
  2714. var prevSlide = s.wrapper.children('.' + s.params.slidePrevClass);
  2715. if (prevSlide.length > 0) s.lazy.loadImageInSlide(prevSlide.index());
  2716. }
  2717. }
  2718. },
  2719. onTransitionStart: function () {
  2720. if (s.params.lazyLoading) {
  2721. if (s.params.lazyLoadingOnTransitionStart || (!s.params.lazyLoadingOnTransitionStart && !s.lazy.initialImageLoaded)) {
  2722. s.lazy.load();
  2723. }
  2724. }
  2725. },
  2726. onTransitionEnd: function () {
  2727. if (s.params.lazyLoading && !s.params.lazyLoadingOnTransitionStart) {
  2728. s.lazy.load();
  2729. }
  2730. }
  2731. };
  2732. /*=========================
  2733. Scrollbar
  2734. ===========================*/
  2735. s.scrollbar = {
  2736. isTouched: false,
  2737. setDragPosition: function (e) {
  2738. var sb = s.scrollbar;
  2739. var x = 0, y = 0;
  2740. var translate;
  2741. var pointerPosition = s.isHorizontal() ?
  2742. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageX : e.pageX || e.clientX) :
  2743. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageY : e.pageY || e.clientY) ;
  2744. var position = (pointerPosition) - sb.track.offset()[s.isHorizontal() ? 'left' : 'top'] - sb.dragSize / 2;
  2745. var positionMin = -s.minTranslate() * sb.moveDivider;
  2746. var positionMax = -s.maxTranslate() * sb.moveDivider;
  2747. if (position < positionMin) {
  2748. position = positionMin;
  2749. }
  2750. else if (position > positionMax) {
  2751. position = positionMax;
  2752. }
  2753. position = -position / sb.moveDivider;
  2754. s.updateProgress(position);
  2755. s.setWrapperTranslate(position, true);
  2756. },
  2757. dragStart: function (e) {
  2758. var sb = s.scrollbar;
  2759. sb.isTouched = true;
  2760. e.preventDefault();
  2761. e.stopPropagation();
  2762. sb.setDragPosition(e);
  2763. clearTimeout(sb.dragTimeout);
  2764. sb.track.transition(0);
  2765. if (s.params.scrollbarHide) {
  2766. sb.track.css('opacity', 1);
  2767. }
  2768. s.wrapper.transition(100);
  2769. sb.drag.transition(100);
  2770. s.emit('onScrollbarDragStart', s);
  2771. },
  2772. dragMove: function (e) {
  2773. var sb = s.scrollbar;
  2774. if (!sb.isTouched) return;
  2775. if (e.preventDefault) e.preventDefault();
  2776. else e.returnValue = false;
  2777. sb.setDragPosition(e);
  2778. s.wrapper.transition(0);
  2779. sb.track.transition(0);
  2780. sb.drag.transition(0);
  2781. s.emit('onScrollbarDragMove', s);
  2782. },
  2783. dragEnd: function (e) {
  2784. var sb = s.scrollbar;
  2785. if (!sb.isTouched) return;
  2786. sb.isTouched = false;
  2787. if (s.params.scrollbarHide) {
  2788. clearTimeout(sb.dragTimeout);
  2789. sb.dragTimeout = setTimeout(function () {
  2790. sb.track.css('opacity', 0);
  2791. sb.track.transition(400);
  2792. }, 1000);
  2793. }
  2794. s.emit('onScrollbarDragEnd', s);
  2795. if (s.params.scrollbarSnapOnRelease) {
  2796. s.slideReset();
  2797. }
  2798. },
  2799. draggableEvents: (function () {
  2800. if ((s.params.simulateTouch === false && !s.support.touch)) return s.touchEventsDesktop;
  2801. else return s.touchEvents;
  2802. })(),
  2803. enableDraggable: function () {
  2804. var sb = s.scrollbar;
  2805. var target = s.support.touch ? sb.track : document;
  2806. $(sb.track).on(sb.draggableEvents.start, sb.dragStart);
  2807. $(target).on(sb.draggableEvents.move, sb.dragMove);
  2808. $(target).on(sb.draggableEvents.end, sb.dragEnd);
  2809. },
  2810. disableDraggable: function () {
  2811. var sb = s.scrollbar;
  2812. var target = s.support.touch ? sb.track : document;
  2813. $(sb.track).off(sb.draggableEvents.start, sb.dragStart);
  2814. $(target).off(sb.draggableEvents.move, sb.dragMove);
  2815. $(target).off(sb.draggableEvents.end, sb.dragEnd);
  2816. },
  2817. set: function () {
  2818. if (!s.params.scrollbar) return;
  2819. var sb = s.scrollbar;
  2820. sb.track = $(s.params.scrollbar);
  2821. if (s.params.uniqueNavElements && typeof s.params.scrollbar === 'string' && sb.track.length > 1 && s.container.find(s.params.scrollbar).length === 1) {
  2822. sb.track = s.container.find(s.params.scrollbar);
  2823. }
  2824. sb.drag = sb.track.find('.swiper-scrollbar-drag');
  2825. if (sb.drag.length === 0) {
  2826. sb.drag = $('<div class="swiper-scrollbar-drag"></div>');
  2827. sb.track.append(sb.drag);
  2828. }
  2829. sb.drag[0].style.width = '';
  2830. sb.drag[0].style.height = '';
  2831. sb.trackSize = s.isHorizontal() ? sb.track[0].offsetWidth : sb.track[0].offsetHeight;
  2832. sb.divider = s.size / s.virtualSize;
  2833. sb.moveDivider = sb.divider * (sb.trackSize / s.size);
  2834. sb.dragSize = sb.trackSize * sb.divider;
  2835. if (s.isHorizontal()) {
  2836. sb.drag[0].style.width = sb.dragSize + 'px';
  2837. }
  2838. else {
  2839. sb.drag[0].style.height = sb.dragSize + 'px';
  2840. }
  2841. if (sb.divider >= 1) {
  2842. sb.track[0].style.display = 'none';
  2843. }
  2844. else {
  2845. sb.track[0].style.display = '';
  2846. }
  2847. if (s.params.scrollbarHide) {
  2848. sb.track[0].style.opacity = 0;
  2849. }
  2850. },
  2851. setTranslate: function () {
  2852. if (!s.params.scrollbar) return;
  2853. var diff;
  2854. var sb = s.scrollbar;
  2855. var translate = s.translate || 0;
  2856. var newPos;
  2857. var newSize = sb.dragSize;
  2858. newPos = (sb.trackSize - sb.dragSize) * s.progress;
  2859. if (s.rtl && s.isHorizontal()) {
  2860. newPos = -newPos;
  2861. if (newPos > 0) {
  2862. newSize = sb.dragSize - newPos;
  2863. newPos = 0;
  2864. }
  2865. else if (-newPos + sb.dragSize > sb.trackSize) {
  2866. newSize = sb.trackSize + newPos;
  2867. }
  2868. }
  2869. else {
  2870. if (newPos < 0) {
  2871. newSize = sb.dragSize + newPos;
  2872. newPos = 0;
  2873. }
  2874. else if (newPos + sb.dragSize > sb.trackSize) {
  2875. newSize = sb.trackSize - newPos;
  2876. }
  2877. }
  2878. if (s.isHorizontal()) {
  2879. if (s.support.transforms3d) {
  2880. sb.drag.transform('translate3d(' + (newPos) + 'px, 0, 0)');
  2881. }
  2882. else {
  2883. sb.drag.transform('translateX(' + (newPos) + 'px)');
  2884. }
  2885. sb.drag[0].style.width = newSize + 'px';
  2886. }
  2887. else {
  2888. if (s.support.transforms3d) {
  2889. sb.drag.transform('translate3d(0px, ' + (newPos) + 'px, 0)');
  2890. }
  2891. else {
  2892. sb.drag.transform('translateY(' + (newPos) + 'px)');
  2893. }
  2894. sb.drag[0].style.height = newSize + 'px';
  2895. }
  2896. if (s.params.scrollbarHide) {
  2897. clearTimeout(sb.timeout);
  2898. sb.track[0].style.opacity = 1;
  2899. sb.timeout = setTimeout(function () {
  2900. sb.track[0].style.opacity = 0;
  2901. sb.track.transition(400);
  2902. }, 1000);
  2903. }
  2904. },
  2905. setTransition: function (duration) {
  2906. if (!s.params.scrollbar) return;
  2907. s.scrollbar.drag.transition(duration);
  2908. }
  2909. };
  2910. /*=========================
  2911. Controller
  2912. ===========================*/
  2913. s.controller = {
  2914. LinearSpline: function (x, y) {
  2915. var binarySearch = (function() {
  2916. var maxIndex, minIndex, guess;
  2917. return function(array, val) {
  2918. minIndex = -1;
  2919. maxIndex = array.length;
  2920. while (maxIndex - minIndex > 1)
  2921. if (array[guess = maxIndex + minIndex >> 1] <= val) {
  2922. minIndex = guess;
  2923. } else {
  2924. maxIndex = guess;
  2925. }
  2926. return maxIndex;
  2927. };
  2928. })();
  2929. this.x = x;
  2930. this.y = y;
  2931. this.lastIndex = x.length - 1;
  2932. // Given an x value (x2), return the expected y2 value:
  2933. // (x1,y1) is the known point before given value,
  2934. // (x3,y3) is the known point after given value.
  2935. var i1, i3;
  2936. var l = this.x.length;
  2937. this.interpolate = function (x2) {
  2938. if (!x2) return 0;
  2939. // Get the indexes of x1 and x3 (the array indexes before and after given x2):
  2940. i3 = binarySearch(this.x, x2);
  2941. i1 = i3 - 1;
  2942. // We have our indexes i1 & i3, so we can calculate already:
  2943. // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
  2944. return ((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1]) + this.y[i1];
  2945. };
  2946. },
  2947. //xxx: for now i will just save one spline function to to
  2948. getInterpolateFunction: function(c){
  2949. if(!s.controller.spline) s.controller.spline = s.params.loop ?
  2950. new s.controller.LinearSpline(s.slidesGrid, c.slidesGrid) :
  2951. new s.controller.LinearSpline(s.snapGrid, c.snapGrid);
  2952. },
  2953. setTranslate: function (translate, byController) {
  2954. var controlled = s.params.control;
  2955. var multiplier, controlledTranslate;
  2956. function setControlledTranslate(c) {
  2957. // this will create an Interpolate function based on the snapGrids
  2958. // x is the Grid of the scrolled scroller and y will be the controlled scroller
  2959. // it makes sense to create this only once and recall it for the interpolation
  2960. // the function does a lot of value caching for performance
  2961. translate = c.rtl && c.params.direction === 'horizontal' ? -s.translate : s.translate;
  2962. if (s.params.controlBy === 'slide') {
  2963. s.controller.getInterpolateFunction(c);
  2964. // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
  2965. // but it did not work out
  2966. controlledTranslate = -s.controller.spline.interpolate(-translate);
  2967. }
  2968. if(!controlledTranslate || s.params.controlBy === 'container'){
  2969. multiplier = (c.maxTranslate() - c.minTranslate()) / (s.maxTranslate() - s.minTranslate());
  2970. controlledTranslate = (translate - s.minTranslate()) * multiplier + c.minTranslate();
  2971. }
  2972. if (s.params.controlInverse) {
  2973. controlledTranslate = c.maxTranslate() - controlledTranslate;
  2974. }
  2975. c.updateProgress(controlledTranslate);
  2976. c.setWrapperTranslate(controlledTranslate, false, s);
  2977. c.updateActiveIndex();
  2978. }
  2979. if (Array.isArray(controlled)) {
  2980. for (var i = 0; i < controlled.length; i++) {
  2981. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  2982. setControlledTranslate(controlled[i]);
  2983. }
  2984. }
  2985. }
  2986. else if (controlled instanceof Swiper && byController !== controlled) {
  2987. setControlledTranslate(controlled);
  2988. }
  2989. },
  2990. setTransition: function (duration, byController) {
  2991. var controlled = s.params.control;
  2992. var i;
  2993. function setControlledTransition(c) {
  2994. c.setWrapperTransition(duration, s);
  2995. if (duration !== 0) {
  2996. c.onTransitionStart();
  2997. c.wrapper.transitionEnd(function(){
  2998. if (!controlled) return;
  2999. if (c.params.loop && s.params.controlBy === 'slide') {
  3000. c.fixLoop();
  3001. }
  3002. c.onTransitionEnd();
  3003. });
  3004. }
  3005. }
  3006. if (Array.isArray(controlled)) {
  3007. for (i = 0; i < controlled.length; i++) {
  3008. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  3009. setControlledTransition(controlled[i]);
  3010. }
  3011. }
  3012. }
  3013. else if (controlled instanceof Swiper && byController !== controlled) {
  3014. setControlledTransition(controlled);
  3015. }
  3016. }
  3017. };
  3018. /*=========================
  3019. Hash Navigation
  3020. ===========================*/
  3021. s.hashnav = {
  3022. onHashCange: function (e, a) {
  3023. var newHash = document.location.hash.replace('#', '');
  3024. var activeSlideHash = s.slides.eq(s.activeIndex).attr('data-hash');
  3025. if (newHash !== activeSlideHash) {
  3026. s.slideTo(s.wrapper.children('.' + s.params.slideClass + '[data-hash="' + (newHash) + '"]').index());
  3027. }
  3028. },
  3029. attachEvents: function (detach) {
  3030. var action = detach ? 'off' : 'on';
  3031. $(window)[action]('hashchange', s.hashnav.onHashCange);
  3032. },
  3033. setHash: function () {
  3034. if (!s.hashnav.initialized || !s.params.hashnav) return;
  3035. if (s.params.replaceState && window.history && window.history.replaceState) {
  3036. window.history.replaceState(null, null, ('#' + s.slides.eq(s.activeIndex).attr('data-hash') || ''));
  3037. } else {
  3038. var slide = s.slides.eq(s.activeIndex);
  3039. var hash = slide.attr('data-hash') || slide.attr('data-history');
  3040. document.location.hash = hash || '';
  3041. }
  3042. },
  3043. init: function () {
  3044. if (!s.params.hashnav || s.params.history) return;
  3045. s.hashnav.initialized = true;
  3046. var hash = document.location.hash.replace('#', '');
  3047. if (hash) {
  3048. var speed = 0;
  3049. for (var i = 0, length = s.slides.length; i < length; i++) {
  3050. var slide = s.slides.eq(i);
  3051. var slideHash = slide.attr('data-hash') || slide.attr('data-history');
  3052. if (slideHash === hash && !slide.hasClass(s.params.slideDuplicateClass)) {
  3053. var index = slide.index();
  3054. s.slideTo(index, speed, s.params.runCallbacksOnInit, true);
  3055. }
  3056. }
  3057. }
  3058. if (s.params.hashnavWatchState) s.hashnav.attachEvents();
  3059. },
  3060. destroy: function () {
  3061. if (s.params.hashnavWatchState) s.hashnav.attachEvents(true);
  3062. }
  3063. };
  3064. /*=========================
  3065. History Api with fallback to Hashnav
  3066. ===========================*/
  3067. s.history = {
  3068. init: function () {
  3069. if (!s.params.history) return;
  3070. if (!window.history || !window.history.pushState) {
  3071. s.params.history = false;
  3072. s.params.hashnav = true;
  3073. return;
  3074. }
  3075. s.history.initialized = true;
  3076. this.paths = this.getPathValues();
  3077. if (!this.paths.key && !this.paths.value) return;
  3078. this.scrollToSlide(0, this.paths.value, s.params.runCallbacksOnInit);
  3079. if (!s.params.replaceState) {
  3080. window.addEventListener('popstate', this.setHistoryPopState);
  3081. }
  3082. },
  3083. setHistoryPopState: function() {
  3084. s.history.paths = s.history.getPathValues();
  3085. s.history.scrollToSlide(s.params.speed, s.history.paths.value, false);
  3086. },
  3087. getPathValues: function() {
  3088. var pathArray = window.location.pathname.slice(1).split('/');
  3089. var total = pathArray.length;
  3090. var key = pathArray[total - 2];
  3091. var value = pathArray[total - 1];
  3092. return { key: key, value: value };
  3093. },
  3094. setHistory: function (key, index) {
  3095. if (!s.history.initialized || !s.params.history) return;
  3096. var slide = s.slides.eq(index);
  3097. var value = this.slugify(slide.attr('data-history'));
  3098. if (!window.location.pathname.includes(key)) {
  3099. value = key + '/' + value;
  3100. }
  3101. if (s.params.replaceState) {
  3102. window.history.replaceState(null, null, value);
  3103. } else {
  3104. window.history.pushState(null, null, value);
  3105. }
  3106. },
  3107. slugify: function(text) {
  3108. return text.toString().toLowerCase()
  3109. .replace(/\s+/g, '-')
  3110. .replace(/[^\w\-]+/g, '')
  3111. .replace(/\-\-+/g, '-')
  3112. .replace(/^-+/, '')
  3113. .replace(/-+$/, '');
  3114. },
  3115. scrollToSlide: function(speed, value, runCallbacks) {
  3116. if (value) {
  3117. for (var i = 0, length = s.slides.length; i < length; i++) {
  3118. var slide = s.slides.eq(i);
  3119. var slideHistory = this.slugify(slide.attr('data-history'));
  3120. if (slideHistory === value && !slide.hasClass(s.params.slideDuplicateClass)) {
  3121. var index = slide.index();
  3122. s.slideTo(index, speed, runCallbacks);
  3123. }
  3124. }
  3125. } else {
  3126. s.slideTo(0, speed, runCallbacks);
  3127. }
  3128. }
  3129. };
  3130. /*=========================
  3131. Keyboard Control
  3132. ===========================*/
  3133. function handleKeyboard(e) {
  3134. if (e.originalEvent) e = e.originalEvent; //jquery fix
  3135. var kc = e.keyCode || e.charCode;
  3136. // Directions locks
  3137. if (!s.params.allowSwipeToNext && (s.isHorizontal() && kc === 39 || !s.isHorizontal() && kc === 40)) {
  3138. return false;
  3139. }
  3140. if (!s.params.allowSwipeToPrev && (s.isHorizontal() && kc === 37 || !s.isHorizontal() && kc === 38)) {
  3141. return false;
  3142. }
  3143. if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
  3144. return;
  3145. }
  3146. if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) {
  3147. return;
  3148. }
  3149. if (kc === 37 || kc === 39 || kc === 38 || kc === 40) {
  3150. var inView = false;
  3151. //Check that swiper should be inside of visible area of window
  3152. if (s.container.parents('.' + s.params.slideClass).length > 0 && s.container.parents('.' + s.params.slideActiveClass).length === 0) {
  3153. return;
  3154. }
  3155. var windowScroll = {
  3156. left: window.pageXOffset,
  3157. top: window.pageYOffset
  3158. };
  3159. var windowWidth = window.innerWidth;
  3160. var windowHeight = window.innerHeight;
  3161. var swiperOffset = s.container.offset();
  3162. if (s.rtl) swiperOffset.left = swiperOffset.left - s.container[0].scrollLeft;
  3163. var swiperCoord = [
  3164. [swiperOffset.left, swiperOffset.top],
  3165. [swiperOffset.left + s.width, swiperOffset.top],
  3166. [swiperOffset.left, swiperOffset.top + s.height],
  3167. [swiperOffset.left + s.width, swiperOffset.top + s.height]
  3168. ];
  3169. for (var i = 0; i < swiperCoord.length; i++) {
  3170. var point = swiperCoord[i];
  3171. if (
  3172. point[0] >= windowScroll.left && point[0] <= windowScroll.left + windowWidth &&
  3173. point[1] >= windowScroll.top && point[1] <= windowScroll.top + windowHeight
  3174. ) {
  3175. inView = true;
  3176. }
  3177. }
  3178. if (!inView) return;
  3179. }
  3180. if (s.isHorizontal()) {
  3181. if (kc === 37 || kc === 39) {
  3182. if (e.preventDefault) e.preventDefault();
  3183. else e.returnValue = false;
  3184. }
  3185. if ((kc === 39 && !s.rtl) || (kc === 37 && s.rtl)) s.slideNext();
  3186. if ((kc === 37 && !s.rtl) || (kc === 39 && s.rtl)) s.slidePrev();
  3187. }
  3188. else {
  3189. if (kc === 38 || kc === 40) {
  3190. if (e.preventDefault) e.preventDefault();
  3191. else e.returnValue = false;
  3192. }
  3193. if (kc === 40) s.slideNext();
  3194. if (kc === 38) s.slidePrev();
  3195. }
  3196. s.emit('onKeyPress', s, kc);
  3197. }
  3198. s.disableKeyboardControl = function () {
  3199. s.params.keyboardControl = false;
  3200. $(document).off('keydown', handleKeyboard);
  3201. };
  3202. s.enableKeyboardControl = function () {
  3203. s.params.keyboardControl = true;
  3204. $(document).on('keydown', handleKeyboard);
  3205. };
  3206. /*=========================
  3207. Mousewheel Control
  3208. ===========================*/
  3209. s.mousewheel = {
  3210. event: false,
  3211. lastScrollTime: (new window.Date()).getTime()
  3212. };
  3213. function isEventSupported() {
  3214. var eventName = 'onwheel';
  3215. var isSupported = eventName in document;
  3216. if (!isSupported) {
  3217. var element = document.createElement('div');
  3218. element.setAttribute(eventName, 'return;');
  3219. isSupported = typeof element[eventName] === 'function';
  3220. }
  3221. if (!isSupported &&
  3222. document.implementation &&
  3223. document.implementation.hasFeature &&
  3224. // always returns true in newer browsers as per the standard.
  3225. // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
  3226. document.implementation.hasFeature('', '') !== true ) {
  3227. // This is the only way to test support for the `wheel` event in IE9+.
  3228. isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
  3229. }
  3230. return isSupported;
  3231. }
  3232. /**
  3233. * Mouse wheel (and 2-finger trackpad) support on the web sucks. It is
  3234. * complicated, thus this doc is long and (hopefully) detailed enough to answer
  3235. * your questions.
  3236. *
  3237. * If you need to react to the mouse wheel in a predictable way, this code is
  3238. * like your bestest friend. * hugs *
  3239. *
  3240. * As of today, there are 4 DOM event types you can listen to:
  3241. *
  3242. * 'wheel' -- Chrome(31+), FF(17+), IE(9+)
  3243. * 'mousewheel' -- Chrome, IE(6+), Opera, Safari
  3244. * 'MozMousePixelScroll' -- FF(3.5 only!) (2010-2013) -- don't bother!
  3245. * 'DOMMouseScroll' -- FF(0.9.7+) since 2003
  3246. *
  3247. * So what to do? The is the best:
  3248. *
  3249. * normalizeWheel.getEventType();
  3250. *
  3251. * In your event callback, use this code to get sane interpretation of the
  3252. * deltas. This code will return an object with properties:
  3253. *
  3254. * spinX -- normalized spin speed (use for zoom) - x plane
  3255. * spinY -- " - y plane
  3256. * pixelX -- normalized distance (to pixels) - x plane
  3257. * pixelY -- " - y plane
  3258. *
  3259. * Wheel values are provided by the browser assuming you are using the wheel to
  3260. * scroll a web page by a number of lines or pixels (or pages). Values can vary
  3261. * significantly on different platforms and browsers, forgetting that you can
  3262. * scroll at different speeds. Some devices (like trackpads) emit more events
  3263. * at smaller increments with fine granularity, and some emit massive jumps with
  3264. * linear speed or acceleration.
  3265. *
  3266. * This code does its best to normalize the deltas for you:
  3267. *
  3268. * - spin is trying to normalize how far the wheel was spun (or trackpad
  3269. * dragged). This is super useful for zoom support where you want to
  3270. * throw away the chunky scroll steps on the PC and make those equal to
  3271. * the slow and smooth tiny steps on the Mac. Key data: This code tries to
  3272. * resolve a single slow step on a wheel to 1.
  3273. *
  3274. * - pixel is normalizing the desired scroll delta in pixel units. You'll
  3275. * get the crazy differences between browsers, but at least it'll be in
  3276. * pixels!
  3277. *
  3278. * - positive value indicates scrolling DOWN/RIGHT, negative UP/LEFT. This
  3279. * should translate to positive value zooming IN, negative zooming OUT.
  3280. * This matches the newer 'wheel' event.
  3281. *
  3282. * Why are there spinX, spinY (or pixels)?
  3283. *
  3284. * - spinX is a 2-finger side drag on the trackpad, and a shift + wheel turn
  3285. * with a mouse. It results in side-scrolling in the browser by default.
  3286. *
  3287. * - spinY is what you expect -- it's the classic axis of a mouse wheel.
  3288. *
  3289. * - I dropped spinZ/pixelZ. It is supported by the DOM 3 'wheel' event and
  3290. * probably is by browsers in conjunction with fancy 3D controllers .. but
  3291. * you know.
  3292. *
  3293. * Implementation info:
  3294. *
  3295. * Examples of 'wheel' event if you scroll slowly (down) by one step with an
  3296. * average mouse:
  3297. *
  3298. * OS X + Chrome (mouse) - 4 pixel delta (wheelDelta -120)
  3299. * OS X + Safari (mouse) - N/A pixel delta (wheelDelta -12)
  3300. * OS X + Firefox (mouse) - 0.1 line delta (wheelDelta N/A)
  3301. * Win8 + Chrome (mouse) - 100 pixel delta (wheelDelta -120)
  3302. * Win8 + Firefox (mouse) - 3 line delta (wheelDelta -120)
  3303. *
  3304. * On the trackpad:
  3305. *
  3306. * OS X + Chrome (trackpad) - 2 pixel delta (wheelDelta -6)
  3307. * OS X + Firefox (trackpad) - 1 pixel delta (wheelDelta N/A)
  3308. *
  3309. * On other/older browsers.. it's more complicated as there can be multiple and
  3310. * also missing delta values.
  3311. *
  3312. * The 'wheel' event is more standard:
  3313. *
  3314. * http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents
  3315. *
  3316. * The basics is that it includes a unit, deltaMode (pixels, lines, pages), and
  3317. * deltaX, deltaY and deltaZ. Some browsers provide other values to maintain
  3318. * backward compatibility with older events. Those other values help us
  3319. * better normalize spin speed. Example of what the browsers provide:
  3320. *
  3321. * | event.wheelDelta | event.detail
  3322. * ------------------+------------------+--------------
  3323. * Safari v5/OS X | -120 | 0
  3324. * Safari v5/Win7 | -120 | 0
  3325. * Chrome v17/OS X | -120 | 0
  3326. * Chrome v17/Win7 | -120 | 0
  3327. * IE9/Win7 | -120 | undefined
  3328. * Firefox v4/OS X | undefined | 1
  3329. * Firefox v4/Win7 | undefined | 3
  3330. *
  3331. */
  3332. function normalizeWheel( /*object*/ event ) /*object*/ {
  3333. // Reasonable defaults
  3334. var PIXEL_STEP = 10;
  3335. var LINE_HEIGHT = 40;
  3336. var PAGE_HEIGHT = 800;
  3337. var sX = 0, sY = 0, // spinX, spinY
  3338. pX = 0, pY = 0; // pixelX, pixelY
  3339. // Legacy
  3340. if( 'detail' in event ) {
  3341. sY = event.detail;
  3342. }
  3343. if( 'wheelDelta' in event ) {
  3344. sY = -event.wheelDelta / 120;
  3345. }
  3346. if( 'wheelDeltaY' in event ) {
  3347. sY = -event.wheelDeltaY / 120;
  3348. }
  3349. if( 'wheelDeltaX' in event ) {
  3350. sX = -event.wheelDeltaX / 120;
  3351. }
  3352. // side scrolling on FF with DOMMouseScroll
  3353. if( 'axis' in event && event.axis === event.HORIZONTAL_AXIS ) {
  3354. sX = sY;
  3355. sY = 0;
  3356. }
  3357. pX = sX * PIXEL_STEP;
  3358. pY = sY * PIXEL_STEP;
  3359. if( 'deltaY' in event ) {
  3360. pY = event.deltaY;
  3361. }
  3362. if( 'deltaX' in event ) {
  3363. pX = event.deltaX;
  3364. }
  3365. if( (pX || pY) && event.deltaMode ) {
  3366. if( event.deltaMode === 1 ) { // delta in LINE units
  3367. pX *= LINE_HEIGHT;
  3368. pY *= LINE_HEIGHT;
  3369. } else { // delta in PAGE units
  3370. pX *= PAGE_HEIGHT;
  3371. pY *= PAGE_HEIGHT;
  3372. }
  3373. }
  3374. // Fall-back if spin cannot be determined
  3375. if( pX && !sX ) {
  3376. sX = (pX < 1) ? -1 : 1;
  3377. }
  3378. if( pY && !sY ) {
  3379. sY = (pY < 1) ? -1 : 1;
  3380. }
  3381. return {
  3382. spinX: sX,
  3383. spinY: sY,
  3384. pixelX: pX,
  3385. pixelY: pY
  3386. };
  3387. }
  3388. if (s.params.mousewheelControl) {
  3389. /**
  3390. * The best combination if you prefer spinX + spinY normalization. It favors
  3391. * the older DOMMouseScroll for Firefox, as FF does not include wheelDelta with
  3392. * 'wheel' event, making spin speed determination impossible.
  3393. */
  3394. s.mousewheel.event = (navigator.userAgent.indexOf('firefox') > -1) ?
  3395. 'DOMMouseScroll' :
  3396. isEventSupported() ?
  3397. 'wheel' : 'mousewheel';
  3398. }
  3399. function handleMousewheel(e) {
  3400. if (e.originalEvent) e = e.originalEvent; //jquery fix
  3401. var delta = 0;
  3402. var rtlFactor = s.rtl ? -1 : 1;
  3403. var data = normalizeWheel( e );
  3404. if (s.params.mousewheelForceToAxis) {
  3405. if (s.isHorizontal()) {
  3406. if (Math.abs(data.pixelX) > Math.abs(data.pixelY)) delta = data.pixelX * rtlFactor;
  3407. else return;
  3408. }
  3409. else {
  3410. if (Math.abs(data.pixelY) > Math.abs(data.pixelX)) delta = data.pixelY;
  3411. else return;
  3412. }
  3413. }
  3414. else {
  3415. delta = Math.abs(data.pixelX) > Math.abs(data.pixelY) ? - data.pixelX * rtlFactor : - data.pixelY;
  3416. }
  3417. if (delta === 0) return;
  3418. if (s.params.mousewheelInvert) delta = -delta;
  3419. if (!s.params.freeMode) {
  3420. if ((new window.Date()).getTime() - s.mousewheel.lastScrollTime > 60) {
  3421. if (delta < 0) {
  3422. if ((!s.isEnd || s.params.loop) && !s.animating) {
  3423. s.slideNext();
  3424. s.emit('onScroll', s, e);
  3425. }
  3426. else if (s.params.mousewheelReleaseOnEdges) return true;
  3427. }
  3428. else {
  3429. if ((!s.isBeginning || s.params.loop) && !s.animating) {
  3430. s.slidePrev();
  3431. s.emit('onScroll', s, e);
  3432. }
  3433. else if (s.params.mousewheelReleaseOnEdges) return true;
  3434. }
  3435. }
  3436. s.mousewheel.lastScrollTime = (new window.Date()).getTime();
  3437. }
  3438. else {
  3439. //Freemode or scrollContainer:
  3440. var position = s.getWrapperTranslate() + delta * s.params.mousewheelSensitivity;
  3441. var wasBeginning = s.isBeginning,
  3442. wasEnd = s.isEnd;
  3443. if (position >= s.minTranslate()) position = s.minTranslate();
  3444. if (position <= s.maxTranslate()) position = s.maxTranslate();
  3445. s.setWrapperTransition(0);
  3446. s.setWrapperTranslate(position);
  3447. s.updateProgress();
  3448. s.updateActiveIndex();
  3449. if (!wasBeginning && s.isBeginning || !wasEnd && s.isEnd) {
  3450. s.updateClasses();
  3451. }
  3452. if (s.params.freeModeSticky) {
  3453. clearTimeout(s.mousewheel.timeout);
  3454. s.mousewheel.timeout = setTimeout(function () {
  3455. s.slideReset();
  3456. }, 300);
  3457. }
  3458. else {
  3459. if (s.params.lazyLoading && s.lazy) {
  3460. s.lazy.load();
  3461. }
  3462. }
  3463. // Emit event
  3464. s.emit('onScroll', s, e);
  3465. // Stop autoplay
  3466. if (s.params.autoplay && s.params.autoplayDisableOnInteraction) s.stopAutoplay();
  3467. // Return page scroll on edge positions
  3468. if (position === 0 || position === s.maxTranslate()) return;
  3469. }
  3470. if (e.preventDefault) e.preventDefault();
  3471. else e.returnValue = false;
  3472. return false;
  3473. }
  3474. s.disableMousewheelControl = function () {
  3475. if (!s.mousewheel.event) return false;
  3476. var target = s.container;
  3477. if (s.params.mousewheelEventsTarged !== 'container') {
  3478. target = $(s.params.mousewheelEventsTarged);
  3479. }
  3480. target.off(s.mousewheel.event, handleMousewheel);
  3481. s.params.mousewheelControl = false;
  3482. return true;
  3483. };
  3484. s.enableMousewheelControl = function () {
  3485. if (!s.mousewheel.event) return false;
  3486. var target = s.container;
  3487. if (s.params.mousewheelEventsTarged !== 'container') {
  3488. target = $(s.params.mousewheelEventsTarged);
  3489. }
  3490. target.on(s.mousewheel.event, handleMousewheel);
  3491. s.params.mousewheelControl = true;
  3492. return true;
  3493. };
  3494. /*=========================
  3495. Parallax
  3496. ===========================*/
  3497. function setParallaxTransform(el, progress) {
  3498. el = $(el);
  3499. var p, pX, pY;
  3500. var rtlFactor = s.rtl ? -1 : 1;
  3501. p = el.attr('data-swiper-parallax') || '0';
  3502. pX = el.attr('data-swiper-parallax-x');
  3503. pY = el.attr('data-swiper-parallax-y');
  3504. if (pX || pY) {
  3505. pX = pX || '0';
  3506. pY = pY || '0';
  3507. }
  3508. else {
  3509. if (s.isHorizontal()) {
  3510. pX = p;
  3511. pY = '0';
  3512. }
  3513. else {
  3514. pY = p;
  3515. pX = '0';
  3516. }
  3517. }
  3518. if ((pX).indexOf('%') >= 0) {
  3519. pX = parseInt(pX, 10) * progress * rtlFactor + '%';
  3520. }
  3521. else {
  3522. pX = pX * progress * rtlFactor + 'px' ;
  3523. }
  3524. if ((pY).indexOf('%') >= 0) {
  3525. pY = parseInt(pY, 10) * progress + '%';
  3526. }
  3527. else {
  3528. pY = pY * progress + 'px' ;
  3529. }
  3530. el.transform('translate3d(' + pX + ', ' + pY + ',0px)');
  3531. }
  3532. s.parallax = {
  3533. setTranslate: function () {
  3534. s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  3535. setParallaxTransform(this, s.progress);
  3536. });
  3537. s.slides.each(function () {
  3538. var slide = $(this);
  3539. slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () {
  3540. var progress = Math.min(Math.max(slide[0].progress, -1), 1);
  3541. setParallaxTransform(this, progress);
  3542. });
  3543. });
  3544. },
  3545. setTransition: function (duration) {
  3546. if (typeof duration === 'undefined') duration = s.params.speed;
  3547. s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  3548. var el = $(this);
  3549. var parallaxDuration = parseInt(el.attr('data-swiper-parallax-duration'), 10) || duration;
  3550. if (duration === 0) parallaxDuration = 0;
  3551. el.transition(parallaxDuration);
  3552. });
  3553. }
  3554. };
  3555. /*=========================
  3556. Zoom
  3557. ===========================*/
  3558. s.zoom = {
  3559. // "Global" Props
  3560. scale: 1,
  3561. currentScale: 1,
  3562. isScaling: false,
  3563. gesture: {
  3564. slide: undefined,
  3565. slideWidth: undefined,
  3566. slideHeight: undefined,
  3567. image: undefined,
  3568. imageWrap: undefined,
  3569. zoomMax: s.params.zoomMax
  3570. },
  3571. image: {
  3572. isTouched: undefined,
  3573. isMoved: undefined,
  3574. currentX: undefined,
  3575. currentY: undefined,
  3576. minX: undefined,
  3577. minY: undefined,
  3578. maxX: undefined,
  3579. maxY: undefined,
  3580. width: undefined,
  3581. height: undefined,
  3582. startX: undefined,
  3583. startY: undefined,
  3584. touchesStart: {},
  3585. touchesCurrent: {}
  3586. },
  3587. velocity: {
  3588. x: undefined,
  3589. y: undefined,
  3590. prevPositionX: undefined,
  3591. prevPositionY: undefined,
  3592. prevTime: undefined
  3593. },
  3594. // Calc Scale From Multi-touches
  3595. getDistanceBetweenTouches: function (e) {
  3596. if (e.targetTouches.length < 2) return 1;
  3597. var x1 = e.targetTouches[0].pageX,
  3598. y1 = e.targetTouches[0].pageY,
  3599. x2 = e.targetTouches[1].pageX,
  3600. y2 = e.targetTouches[1].pageY;
  3601. var distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
  3602. return distance;
  3603. },
  3604. // Events
  3605. onGestureStart: function (e) {
  3606. var z = s.zoom;
  3607. if (!s.support.gestures) {
  3608. if (e.type !== 'touchstart' || e.type === 'touchstart' && e.targetTouches.length < 2) {
  3609. return;
  3610. }
  3611. z.gesture.scaleStart = z.getDistanceBetweenTouches(e);
  3612. }
  3613. if (!z.gesture.slide || !z.gesture.slide.length) {
  3614. z.gesture.slide = $(this);
  3615. if (z.gesture.slide.length === 0) z.gesture.slide = s.slides.eq(s.activeIndex);
  3616. z.gesture.image = z.gesture.slide.find('img, svg, canvas');
  3617. z.gesture.imageWrap = z.gesture.image.parent('.' + s.params.zoomContainerClass);
  3618. z.gesture.zoomMax = z.gesture.imageWrap.attr('data-swiper-zoom') || s.params.zoomMax ;
  3619. if (z.gesture.imageWrap.length === 0) {
  3620. z.gesture.image = undefined;
  3621. return;
  3622. }
  3623. }
  3624. z.gesture.image.transition(0);
  3625. z.isScaling = true;
  3626. },
  3627. onGestureChange: function (e) {
  3628. var z = s.zoom;
  3629. if (!s.support.gestures) {
  3630. if (e.type !== 'touchmove' || e.type === 'touchmove' && e.targetTouches.length < 2) {
  3631. return;
  3632. }
  3633. z.gesture.scaleMove = z.getDistanceBetweenTouches(e);
  3634. }
  3635. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3636. if (s.support.gestures) {
  3637. z.scale = e.scale * z.currentScale;
  3638. }
  3639. else {
  3640. z.scale = (z.gesture.scaleMove / z.gesture.scaleStart) * z.currentScale;
  3641. }
  3642. if (z.scale > z.gesture.zoomMax) {
  3643. z.scale = z.gesture.zoomMax - 1 + Math.pow((z.scale - z.gesture.zoomMax + 1), 0.5);
  3644. }
  3645. if (z.scale < s.params.zoomMin) {
  3646. z.scale = s.params.zoomMin + 1 - Math.pow((s.params.zoomMin - z.scale + 1), 0.5);
  3647. }
  3648. z.gesture.image.transform('translate3d(0,0,0) scale(' + z.scale + ')');
  3649. },
  3650. onGestureEnd: function (e) {
  3651. var z = s.zoom;
  3652. if (!s.support.gestures) {
  3653. if (e.type !== 'touchend' || e.type === 'touchend' && e.changedTouches.length < 2) {
  3654. return;
  3655. }
  3656. }
  3657. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3658. z.scale = Math.max(Math.min(z.scale, z.gesture.zoomMax), s.params.zoomMin);
  3659. z.gesture.image.transition(s.params.speed).transform('translate3d(0,0,0) scale(' + z.scale + ')');
  3660. z.currentScale = z.scale;
  3661. z.isScaling = false;
  3662. if (z.scale === 1) z.gesture.slide = undefined;
  3663. },
  3664. onTouchStart: function (s, e) {
  3665. var z = s.zoom;
  3666. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3667. if (z.image.isTouched) return;
  3668. if (s.device.os === 'android') e.preventDefault();
  3669. z.image.isTouched = true;
  3670. z.image.touchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  3671. z.image.touchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  3672. },
  3673. onTouchMove: function (e) {
  3674. var z = s.zoom;
  3675. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3676. s.allowClick = false;
  3677. if (!z.image.isTouched || !z.gesture.slide) return;
  3678. if (!z.image.isMoved) {
  3679. z.image.width = z.gesture.image[0].offsetWidth;
  3680. z.image.height = z.gesture.image[0].offsetHeight;
  3681. z.image.startX = s.getTranslate(z.gesture.imageWrap[0], 'x') || 0;
  3682. z.image.startY = s.getTranslate(z.gesture.imageWrap[0], 'y') || 0;
  3683. z.gesture.slideWidth = z.gesture.slide[0].offsetWidth;
  3684. z.gesture.slideHeight = z.gesture.slide[0].offsetHeight;
  3685. z.gesture.imageWrap.transition(0);
  3686. if (s.rtl) z.image.startX = -z.image.startX;
  3687. if (s.rtl) z.image.startY = -z.image.startY;
  3688. }
  3689. // Define if we need image drag
  3690. var scaledWidth = z.image.width * z.scale;
  3691. var scaledHeight = z.image.height * z.scale;
  3692. if (scaledWidth < z.gesture.slideWidth && scaledHeight < z.gesture.slideHeight) return;
  3693. z.image.minX = Math.min((z.gesture.slideWidth / 2 - scaledWidth / 2), 0);
  3694. z.image.maxX = -z.image.minX;
  3695. z.image.minY = Math.min((z.gesture.slideHeight / 2 - scaledHeight / 2), 0);
  3696. z.image.maxY = -z.image.minY;
  3697. z.image.touchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  3698. z.image.touchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  3699. if (!z.image.isMoved && !z.isScaling) {
  3700. if (s.isHorizontal() &&
  3701. (Math.floor(z.image.minX) === Math.floor(z.image.startX) && z.image.touchesCurrent.x < z.image.touchesStart.x) ||
  3702. (Math.floor(z.image.maxX) === Math.floor(z.image.startX) && z.image.touchesCurrent.x > z.image.touchesStart.x)
  3703. ) {
  3704. z.image.isTouched = false;
  3705. return;
  3706. }
  3707. else if (!s.isHorizontal() &&
  3708. (Math.floor(z.image.minY) === Math.floor(z.image.startY) && z.image.touchesCurrent.y < z.image.touchesStart.y) ||
  3709. (Math.floor(z.image.maxY) === Math.floor(z.image.startY) && z.image.touchesCurrent.y > z.image.touchesStart.y)
  3710. ) {
  3711. z.image.isTouched = false;
  3712. return;
  3713. }
  3714. }
  3715. e.preventDefault();
  3716. e.stopPropagation();
  3717. z.image.isMoved = true;
  3718. z.image.currentX = z.image.touchesCurrent.x - z.image.touchesStart.x + z.image.startX;
  3719. z.image.currentY = z.image.touchesCurrent.y - z.image.touchesStart.y + z.image.startY;
  3720. if (z.image.currentX < z.image.minX) {
  3721. z.image.currentX = z.image.minX + 1 - Math.pow((z.image.minX - z.image.currentX + 1), 0.8);
  3722. }
  3723. if (z.image.currentX > z.image.maxX) {
  3724. z.image.currentX = z.image.maxX - 1 + Math.pow((z.image.currentX - z.image.maxX + 1), 0.8);
  3725. }
  3726. if (z.image.currentY < z.image.minY) {
  3727. z.image.currentY = z.image.minY + 1 - Math.pow((z.image.minY - z.image.currentY + 1), 0.8);
  3728. }
  3729. if (z.image.currentY > z.image.maxY) {
  3730. z.image.currentY = z.image.maxY - 1 + Math.pow((z.image.currentY - z.image.maxY + 1), 0.8);
  3731. }
  3732. //Velocity
  3733. if (!z.velocity.prevPositionX) z.velocity.prevPositionX = z.image.touchesCurrent.x;
  3734. if (!z.velocity.prevPositionY) z.velocity.prevPositionY = z.image.touchesCurrent.y;
  3735. if (!z.velocity.prevTime) z.velocity.prevTime = Date.now();
  3736. z.velocity.x = (z.image.touchesCurrent.x - z.velocity.prevPositionX) / (Date.now() - z.velocity.prevTime) / 2;
  3737. z.velocity.y = (z.image.touchesCurrent.y - z.velocity.prevPositionY) / (Date.now() - z.velocity.prevTime) / 2;
  3738. if (Math.abs(z.image.touchesCurrent.x - z.velocity.prevPositionX) < 2) z.velocity.x = 0;
  3739. if (Math.abs(z.image.touchesCurrent.y - z.velocity.prevPositionY) < 2) z.velocity.y = 0;
  3740. z.velocity.prevPositionX = z.image.touchesCurrent.x;
  3741. z.velocity.prevPositionY = z.image.touchesCurrent.y;
  3742. z.velocity.prevTime = Date.now();
  3743. z.gesture.imageWrap.transform('translate3d(' + z.image.currentX + 'px, ' + z.image.currentY + 'px,0)');
  3744. },
  3745. onTouchEnd: function (s, e) {
  3746. var z = s.zoom;
  3747. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3748. if (!z.image.isTouched || !z.image.isMoved) {
  3749. z.image.isTouched = false;
  3750. z.image.isMoved = false;
  3751. return;
  3752. }
  3753. z.image.isTouched = false;
  3754. z.image.isMoved = false;
  3755. var momentumDurationX = 300;
  3756. var momentumDurationY = 300;
  3757. var momentumDistanceX = z.velocity.x * momentumDurationX;
  3758. var newPositionX = z.image.currentX + momentumDistanceX;
  3759. var momentumDistanceY = z.velocity.y * momentumDurationY;
  3760. var newPositionY = z.image.currentY + momentumDistanceY;
  3761. //Fix duration
  3762. if (z.velocity.x !== 0) momentumDurationX = Math.abs((newPositionX - z.image.currentX) / z.velocity.x);
  3763. if (z.velocity.y !== 0) momentumDurationY = Math.abs((newPositionY - z.image.currentY) / z.velocity.y);
  3764. var momentumDuration = Math.max(momentumDurationX, momentumDurationY);
  3765. z.image.currentX = newPositionX;
  3766. z.image.currentY = newPositionY;
  3767. // Define if we need image drag
  3768. var scaledWidth = z.image.width * z.scale;
  3769. var scaledHeight = z.image.height * z.scale;
  3770. z.image.minX = Math.min((z.gesture.slideWidth / 2 - scaledWidth / 2), 0);
  3771. z.image.maxX = -z.image.minX;
  3772. z.image.minY = Math.min((z.gesture.slideHeight / 2 - scaledHeight / 2), 0);
  3773. z.image.maxY = -z.image.minY;
  3774. z.image.currentX = Math.max(Math.min(z.image.currentX, z.image.maxX), z.image.minX);
  3775. z.image.currentY = Math.max(Math.min(z.image.currentY, z.image.maxY), z.image.minY);
  3776. z.gesture.imageWrap.transition(momentumDuration).transform('translate3d(' + z.image.currentX + 'px, ' + z.image.currentY + 'px,0)');
  3777. },
  3778. onTransitionEnd: function (s) {
  3779. var z = s.zoom;
  3780. if (z.gesture.slide && s.previousIndex !== s.activeIndex) {
  3781. z.gesture.image.transform('translate3d(0,0,0) scale(1)');
  3782. z.gesture.imageWrap.transform('translate3d(0,0,0)');
  3783. z.gesture.slide = z.gesture.image = z.gesture.imageWrap = undefined;
  3784. z.scale = z.currentScale = 1;
  3785. }
  3786. },
  3787. // Toggle Zoom
  3788. toggleZoom: function (s, e) {
  3789. var z = s.zoom;
  3790. if (!z.gesture.slide) {
  3791. z.gesture.slide = s.clickedSlide ? $(s.clickedSlide) : s.slides.eq(s.activeIndex);
  3792. z.gesture.image = z.gesture.slide.find('img, svg, canvas');
  3793. z.gesture.imageWrap = z.gesture.image.parent('.' + s.params.zoomContainerClass);
  3794. }
  3795. if (!z.gesture.image || z.gesture.image.length === 0) return;
  3796. var touchX, touchY, offsetX, offsetY, diffX, diffY, translateX, translateY, imageWidth, imageHeight, scaledWidth, scaledHeight, translateMinX, translateMinY, translateMaxX, translateMaxY, slideWidth, slideHeight;
  3797. if (typeof z.image.touchesStart.x === 'undefined' && e) {
  3798. touchX = e.type === 'touchend' ? e.changedTouches[0].pageX : e.pageX;
  3799. touchY = e.type === 'touchend' ? e.changedTouches[0].pageY : e.pageY;
  3800. }
  3801. else {
  3802. touchX = z.image.touchesStart.x;
  3803. touchY = z.image.touchesStart.y;
  3804. }
  3805. if (z.scale && z.scale !== 1) {
  3806. // Zoom Out
  3807. z.scale = z.currentScale = 1;
  3808. z.gesture.imageWrap.transition(300).transform('translate3d(0,0,0)');
  3809. z.gesture.image.transition(300).transform('translate3d(0,0,0) scale(1)');
  3810. z.gesture.slide = undefined;
  3811. }
  3812. else {
  3813. // Zoom In
  3814. z.scale = z.currentScale = z.gesture.imageWrap.attr('data-swiper-zoom') || s.params.zoomMax;
  3815. if (e) {
  3816. slideWidth = z.gesture.slide[0].offsetWidth;
  3817. slideHeight = z.gesture.slide[0].offsetHeight;
  3818. offsetX = z.gesture.slide.offset().left;
  3819. offsetY = z.gesture.slide.offset().top;
  3820. diffX = offsetX + slideWidth/2 - touchX;
  3821. diffY = offsetY + slideHeight/2 - touchY;
  3822. imageWidth = z.gesture.image[0].offsetWidth;
  3823. imageHeight = z.gesture.image[0].offsetHeight;
  3824. scaledWidth = imageWidth * z.scale;
  3825. scaledHeight = imageHeight * z.scale;
  3826. translateMinX = Math.min((slideWidth / 2 - scaledWidth / 2), 0);
  3827. translateMinY = Math.min((slideHeight / 2 - scaledHeight / 2), 0);
  3828. translateMaxX = -translateMinX;
  3829. translateMaxY = -translateMinY;
  3830. translateX = diffX * z.scale;
  3831. translateY = diffY * z.scale;
  3832. if (translateX < translateMinX) {
  3833. translateX = translateMinX;
  3834. }
  3835. if (translateX > translateMaxX) {
  3836. translateX = translateMaxX;
  3837. }
  3838. if (translateY < translateMinY) {
  3839. translateY = translateMinY;
  3840. }
  3841. if (translateY > translateMaxY) {
  3842. translateY = translateMaxY;
  3843. }
  3844. }
  3845. else {
  3846. translateX = 0;
  3847. translateY = 0;
  3848. }
  3849. z.gesture.imageWrap.transition(300).transform('translate3d(' + translateX + 'px, ' + translateY + 'px,0)');
  3850. z.gesture.image.transition(300).transform('translate3d(0,0,0) scale(' + z.scale + ')');
  3851. }
  3852. },
  3853. // Attach/Detach Events
  3854. attachEvents: function (detach) {
  3855. var action = detach ? 'off' : 'on';
  3856. if (s.params.zoom) {
  3857. var target = s.slides;
  3858. var passiveListener = s.touchEvents.start === 'touchstart' && s.support.passiveListener && s.params.passiveListeners ? {passive: true, capture: false} : false;
  3859. // Scale image
  3860. if (s.support.gestures) {
  3861. s.slides[action]('gesturestart', s.zoom.onGestureStart, passiveListener);
  3862. s.slides[action]('gesturechange', s.zoom.onGestureChange, passiveListener);
  3863. s.slides[action]('gestureend', s.zoom.onGestureEnd, passiveListener);
  3864. }
  3865. else if (s.touchEvents.start === 'touchstart') {
  3866. s.slides[action](s.touchEvents.start, s.zoom.onGestureStart, passiveListener);
  3867. s.slides[action](s.touchEvents.move, s.zoom.onGestureChange, passiveListener);
  3868. s.slides[action](s.touchEvents.end, s.zoom.onGestureEnd, passiveListener);
  3869. }
  3870. // Move image
  3871. s[action]('touchStart', s.zoom.onTouchStart);
  3872. s.slides.each(function (index, slide){
  3873. if ($(slide).find('.' + s.params.zoomContainerClass).length > 0) {
  3874. $(slide)[action](s.touchEvents.move, s.zoom.onTouchMove);
  3875. }
  3876. });
  3877. s[action]('touchEnd', s.zoom.onTouchEnd);
  3878. // Scale Out
  3879. s[action]('transitionEnd', s.zoom.onTransitionEnd);
  3880. if (s.params.zoomToggle) {
  3881. s.on('doubleTap', s.zoom.toggleZoom);
  3882. }
  3883. }
  3884. },
  3885. init: function () {
  3886. s.zoom.attachEvents();
  3887. },
  3888. destroy: function () {
  3889. s.zoom.attachEvents(true);
  3890. }
  3891. };
  3892. /*=========================
  3893. Plugins API. Collect all and init all plugins
  3894. ===========================*/
  3895. s._plugins = [];
  3896. for (var plugin in s.plugins) {
  3897. var p = s.plugins[plugin](s, s.params[plugin]);
  3898. if (p) s._plugins.push(p);
  3899. }
  3900. // Method to call all plugins event/method
  3901. s.callPlugins = function (eventName) {
  3902. for (var i = 0; i < s._plugins.length; i++) {
  3903. if (eventName in s._plugins[i]) {
  3904. s._plugins[i][eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3905. }
  3906. }
  3907. };
  3908. /*=========================
  3909. Events/Callbacks/Plugins Emitter
  3910. ===========================*/
  3911. function normalizeEventName (eventName) {
  3912. if (eventName.indexOf('on') !== 0) {
  3913. if (eventName[0] !== eventName[0].toUpperCase()) {
  3914. eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1);
  3915. }
  3916. else {
  3917. eventName = 'on' + eventName;
  3918. }
  3919. }
  3920. return eventName;
  3921. }
  3922. s.emitterEventListeners = {
  3923. };
  3924. s.emit = function (eventName) {
  3925. // Trigger callbacks
  3926. if (s.params[eventName]) {
  3927. s.params[eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3928. }
  3929. var i;
  3930. // Trigger events
  3931. if (s.emitterEventListeners[eventName]) {
  3932. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  3933. s.emitterEventListeners[eventName][i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3934. }
  3935. }
  3936. // Trigger plugins
  3937. if (s.callPlugins) s.callPlugins(eventName, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3938. };
  3939. s.on = function (eventName, handler) {
  3940. eventName = normalizeEventName(eventName);
  3941. if (!s.emitterEventListeners[eventName]) s.emitterEventListeners[eventName] = [];
  3942. s.emitterEventListeners[eventName].push(handler);
  3943. return s;
  3944. };
  3945. s.off = function (eventName, handler) {
  3946. var i;
  3947. eventName = normalizeEventName(eventName);
  3948. if (typeof handler === 'undefined') {
  3949. // Remove all handlers for such event
  3950. s.emitterEventListeners[eventName] = [];
  3951. return s;
  3952. }
  3953. if (!s.emitterEventListeners[eventName] || s.emitterEventListeners[eventName].length === 0) return;
  3954. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  3955. if(s.emitterEventListeners[eventName][i] === handler) s.emitterEventListeners[eventName].splice(i, 1);
  3956. }
  3957. return s;
  3958. };
  3959. s.once = function (eventName, handler) {
  3960. eventName = normalizeEventName(eventName);
  3961. var _handler = function () {
  3962. handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
  3963. s.off(eventName, _handler);
  3964. };
  3965. s.on(eventName, _handler);
  3966. return s;
  3967. };
  3968. // Accessibility tools
  3969. s.a11y = {
  3970. makeFocusable: function ($el) {
  3971. $el.attr('tabIndex', '0');
  3972. return $el;
  3973. },
  3974. addRole: function ($el, role) {
  3975. $el.attr('role', role);
  3976. return $el;
  3977. },
  3978. addLabel: function ($el, label) {
  3979. $el.attr('aria-label', label);
  3980. return $el;
  3981. },
  3982. disable: function ($el) {
  3983. $el.attr('aria-disabled', true);
  3984. return $el;
  3985. },
  3986. enable: function ($el) {
  3987. $el.attr('aria-disabled', false);
  3988. return $el;
  3989. },
  3990. onEnterKey: function (event) {
  3991. if (event.keyCode !== 13) return;
  3992. if ($(event.target).is(s.params.nextButton)) {
  3993. s.onClickNext(event);
  3994. if (s.isEnd) {
  3995. s.a11y.notify(s.params.lastSlideMessage);
  3996. }
  3997. else {
  3998. s.a11y.notify(s.params.nextSlideMessage);
  3999. }
  4000. }
  4001. else if ($(event.target).is(s.params.prevButton)) {
  4002. s.onClickPrev(event);
  4003. if (s.isBeginning) {
  4004. s.a11y.notify(s.params.firstSlideMessage);
  4005. }
  4006. else {
  4007. s.a11y.notify(s.params.prevSlideMessage);
  4008. }
  4009. }
  4010. if ($(event.target).is('.' + s.params.bulletClass)) {
  4011. $(event.target)[0].click();
  4012. }
  4013. },
  4014. liveRegion: $('<span class="' + s.params.notificationClass + '" aria-live="assertive" aria-atomic="true"></span>'),
  4015. notify: function (message) {
  4016. var notification = s.a11y.liveRegion;
  4017. if (notification.length === 0) return;
  4018. notification.html('');
  4019. notification.html(message);
  4020. },
  4021. init: function () {
  4022. // Setup accessibility
  4023. if (s.params.nextButton && s.nextButton && s.nextButton.length > 0) {
  4024. s.a11y.makeFocusable(s.nextButton);
  4025. s.a11y.addRole(s.nextButton, 'button');
  4026. s.a11y.addLabel(s.nextButton, s.params.nextSlideMessage);
  4027. }
  4028. if (s.params.prevButton && s.prevButton && s.prevButton.length > 0) {
  4029. s.a11y.makeFocusable(s.prevButton);
  4030. s.a11y.addRole(s.prevButton, 'button');
  4031. s.a11y.addLabel(s.prevButton, s.params.prevSlideMessage);
  4032. }
  4033. $(s.container).append(s.a11y.liveRegion);
  4034. },
  4035. initPagination: function () {
  4036. if (s.params.pagination && s.params.paginationClickable && s.bullets && s.bullets.length) {
  4037. s.bullets.each(function () {
  4038. var bullet = $(this);
  4039. s.a11y.makeFocusable(bullet);
  4040. s.a11y.addRole(bullet, 'button');
  4041. s.a11y.addLabel(bullet, s.params.paginationBulletMessage.replace(/{{index}}/, bullet.index() + 1));
  4042. });
  4043. }
  4044. },
  4045. destroy: function () {
  4046. if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove();
  4047. }
  4048. };
  4049. /*=========================
  4050. Init/Destroy
  4051. ===========================*/
  4052. s.init = function () {
  4053. if (s.params.loop) s.createLoop();
  4054. s.updateContainerSize();
  4055. s.updateSlidesSize();
  4056. s.updatePagination();
  4057. if (s.params.scrollbar && s.scrollbar) {
  4058. s.scrollbar.set();
  4059. if (s.params.scrollbarDraggable) {
  4060. s.scrollbar.enableDraggable();
  4061. }
  4062. }
  4063. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  4064. if (!s.params.loop) s.updateProgress();
  4065. s.effects[s.params.effect].setTranslate();
  4066. }
  4067. if (s.params.loop) {
  4068. s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit);
  4069. }
  4070. else {
  4071. s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit);
  4072. if (s.params.initialSlide === 0) {
  4073. if (s.parallax && s.params.parallax) s.parallax.setTranslate();
  4074. if (s.lazy && s.params.lazyLoading) {
  4075. s.lazy.load();
  4076. s.lazy.initialImageLoaded = true;
  4077. }
  4078. }
  4079. }
  4080. s.attachEvents();
  4081. if (s.params.observer && s.support.observer) {
  4082. s.initObservers();
  4083. }
  4084. if (s.params.preloadImages && !s.params.lazyLoading) {
  4085. s.preloadImages();
  4086. }
  4087. if (s.params.zoom && s.zoom) {
  4088. s.zoom.init();
  4089. }
  4090. if (s.params.autoplay) {
  4091. s.startAutoplay();
  4092. }
  4093. if (s.params.keyboardControl) {
  4094. if (s.enableKeyboardControl) s.enableKeyboardControl();
  4095. }
  4096. if (s.params.mousewheelControl) {
  4097. if (s.enableMousewheelControl) s.enableMousewheelControl();
  4098. }
  4099. // Deprecated hashnavReplaceState changed to replaceState for use in hashnav and history
  4100. if (s.params.hashnavReplaceState) {
  4101. s.params.replaceState = s.params.hashnavReplaceState;
  4102. }
  4103. if (s.params.history) {
  4104. if (s.history) s.history.init();
  4105. }
  4106. if (s.params.hashnav) {
  4107. if (s.hashnav) s.hashnav.init();
  4108. }
  4109. if (s.params.a11y && s.a11y) s.a11y.init();
  4110. s.emit('onInit', s);
  4111. };
  4112. // Cleanup dynamic styles
  4113. s.cleanupStyles = function () {
  4114. // Container
  4115. s.container.removeClass(s.classNames.join(' ')).removeAttr('style');
  4116. // Wrapper
  4117. s.wrapper.removeAttr('style');
  4118. // Slides
  4119. if (s.slides && s.slides.length) {
  4120. s.slides
  4121. .removeClass([
  4122. s.params.slideVisibleClass,
  4123. s.params.slideActiveClass,
  4124. s.params.slideNextClass,
  4125. s.params.slidePrevClass
  4126. ].join(' '))
  4127. .removeAttr('style')
  4128. .removeAttr('data-swiper-column')
  4129. .removeAttr('data-swiper-row');
  4130. }
  4131. // Pagination/Bullets
  4132. if (s.paginationContainer && s.paginationContainer.length) {
  4133. s.paginationContainer.removeClass(s.params.paginationHiddenClass);
  4134. }
  4135. if (s.bullets && s.bullets.length) {
  4136. s.bullets.removeClass(s.params.bulletActiveClass);
  4137. }
  4138. // Buttons
  4139. if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  4140. if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  4141. // Scrollbar
  4142. if (s.params.scrollbar && s.scrollbar) {
  4143. if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style');
  4144. if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style');
  4145. }
  4146. };
  4147. // Destroy
  4148. s.destroy = function (deleteInstance, cleanupStyles) {
  4149. // Detach evebts
  4150. s.detachEvents();
  4151. // Stop autoplay
  4152. s.stopAutoplay();
  4153. // Disable draggable
  4154. if (s.params.scrollbar && s.scrollbar) {
  4155. if (s.params.scrollbarDraggable) {
  4156. s.scrollbar.disableDraggable();
  4157. }
  4158. }
  4159. // Destroy loop
  4160. if (s.params.loop) {
  4161. s.destroyLoop();
  4162. }
  4163. // Cleanup styles
  4164. if (cleanupStyles) {
  4165. s.cleanupStyles();
  4166. }
  4167. // Disconnect observer
  4168. s.disconnectObservers();
  4169. // Destroy zoom
  4170. if (s.params.zoom && s.zoom) {
  4171. s.zoom.destroy();
  4172. }
  4173. // Disable keyboard/mousewheel
  4174. if (s.params.keyboardControl) {
  4175. if (s.disableKeyboardControl) s.disableKeyboardControl();
  4176. }
  4177. if (s.params.mousewheelControl) {
  4178. if (s.disableMousewheelControl) s.disableMousewheelControl();
  4179. }
  4180. // Disable a11y
  4181. if (s.params.a11y && s.a11y) s.a11y.destroy();
  4182. // Delete history popstate
  4183. if (s.params.history && !s.params.replaceState) {
  4184. window.removeEventListener('popstate', s.history.setHistoryPopState);
  4185. }
  4186. if (s.params.hashnav && s.hashnav) {
  4187. s.hashnav.destroy();
  4188. }
  4189. // Destroy callback
  4190. s.emit('onDestroy');
  4191. // Delete instance
  4192. if (deleteInstance !== false) s = null;
  4193. };
  4194. s.init();
  4195. // Return swiper instance
  4196. return s;
  4197. };
  4198. /*==================================================
  4199. Prototype
  4200. ====================================================*/
  4201. Swiper.prototype = {
  4202. isSafari: (function () {
  4203. var ua = window.navigator.userAgent.toLowerCase();
  4204. return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0);
  4205. })(),
  4206. isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(window.navigator.userAgent),
  4207. isArray: function (arr) {
  4208. return Object.prototype.toString.apply(arr) === '[object Array]';
  4209. },
  4210. /*==================================================
  4211. Browser
  4212. ====================================================*/
  4213. browser: {
  4214. ie: window.navigator.pointerEnabled || window.navigator.msPointerEnabled,
  4215. ieTouch: (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 1) || (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 1),
  4216. lteIE9: (function() {
  4217. // create temporary DIV
  4218. var div = document.createElement('div');
  4219. // add content to tmp DIV which is wrapped into the IE HTML conditional statement
  4220. div.innerHTML = '<!--[if lte IE 9]><i></i><![endif]-->';
  4221. // return true / false value based on what will browser render
  4222. return div.getElementsByTagName('i').length === 1;
  4223. })()
  4224. },
  4225. /*==================================================
  4226. Devices
  4227. ====================================================*/
  4228. device: (function () {
  4229. var ua = window.navigator.userAgent;
  4230. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  4231. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  4232. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  4233. var iphone = !ipad && ua.match(/(iPhone\sOS|iOS)\s([\d_]+)/);
  4234. return {
  4235. ios: ipad || iphone || ipod,
  4236. android: android
  4237. };
  4238. })(),
  4239. /*==================================================
  4240. Feature Detection
  4241. ====================================================*/
  4242. support: {
  4243. touch : (window.Modernizr && Modernizr.touch === true) || (function () {
  4244. return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
  4245. })(),
  4246. transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () {
  4247. var div = document.createElement('div').style;
  4248. return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
  4249. })(),
  4250. flexbox: (function () {
  4251. var div = document.createElement('div').style;
  4252. var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' ');
  4253. for (var i = 0; i < styles.length; i++) {
  4254. if (styles[i] in div) return true;
  4255. }
  4256. })(),
  4257. observer: (function () {
  4258. return ('MutationObserver' in window || 'WebkitMutationObserver' in window);
  4259. })(),
  4260. passiveListener: (function () {
  4261. var supportsPassive = false;
  4262. try {
  4263. var opts = Object.defineProperty({}, 'passive', {
  4264. get: function() {
  4265. supportsPassive = true;
  4266. }
  4267. });
  4268. window.addEventListener('testPassiveListener', null, opts);
  4269. } catch (e) {}
  4270. return supportsPassive;
  4271. })(),
  4272. gestures: (function () {
  4273. return 'ongesturestart' in window;
  4274. })()
  4275. },
  4276. /*==================================================
  4277. Plugins
  4278. ====================================================*/
  4279. plugins: {}
  4280. };
  4281. /*===========================
  4282. Dom7 Library
  4283. ===========================*/
  4284. var Dom7 = (function () {
  4285. var Dom7 = function (arr) {
  4286. var _this = this, i = 0;
  4287. // Create array-like object
  4288. for (i = 0; i < arr.length; i++) {
  4289. _this[i] = arr[i];
  4290. }
  4291. _this.length = arr.length;
  4292. // Return collection with methods
  4293. return this;
  4294. };
  4295. var $ = function (selector, context) {
  4296. var arr = [], i = 0;
  4297. if (selector && !context) {
  4298. if (selector instanceof Dom7) {
  4299. return selector;
  4300. }
  4301. }
  4302. if (selector) {
  4303. // String
  4304. if (typeof selector === 'string') {
  4305. var els, tempParent, html = selector.trim();
  4306. if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) {
  4307. var toCreate = 'div';
  4308. if (html.indexOf('<li') === 0) toCreate = 'ul';
  4309. if (html.indexOf('<tr') === 0) toCreate = 'tbody';
  4310. if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) toCreate = 'tr';
  4311. if (html.indexOf('<tbody') === 0) toCreate = 'table';
  4312. if (html.indexOf('<option') === 0) toCreate = 'select';
  4313. tempParent = document.createElement(toCreate);
  4314. tempParent.innerHTML = selector;
  4315. for (i = 0; i < tempParent.childNodes.length; i++) {
  4316. arr.push(tempParent.childNodes[i]);
  4317. }
  4318. }
  4319. else {
  4320. if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) {
  4321. // Pure ID selector
  4322. els = [document.getElementById(selector.split('#')[1])];
  4323. }
  4324. else {
  4325. // Other selectors
  4326. els = (context || document).querySelectorAll(selector);
  4327. }
  4328. for (i = 0; i < els.length; i++) {
  4329. if (els[i]) arr.push(els[i]);
  4330. }
  4331. }
  4332. }
  4333. // Node/element
  4334. else if (selector.nodeType || selector === window || selector === document) {
  4335. arr.push(selector);
  4336. }
  4337. //Array of elements or instance of Dom
  4338. else if (selector.length > 0 && selector[0].nodeType) {
  4339. for (i = 0; i < selector.length; i++) {
  4340. arr.push(selector[i]);
  4341. }
  4342. }
  4343. }
  4344. return new Dom7(arr);
  4345. };
  4346. Dom7.prototype = {
  4347. // Classes and attriutes
  4348. addClass: function (className) {
  4349. if (typeof className === 'undefined') {
  4350. return this;
  4351. }
  4352. var classes = className.split(' ');
  4353. for (var i = 0; i < classes.length; i++) {
  4354. for (var j = 0; j < this.length; j++) {
  4355. this[j].classList.add(classes[i]);
  4356. }
  4357. }
  4358. return this;
  4359. },
  4360. removeClass: function (className) {
  4361. var classes = className.split(' ');
  4362. for (var i = 0; i < classes.length; i++) {
  4363. for (var j = 0; j < this.length; j++) {
  4364. this[j].classList.remove(classes[i]);
  4365. }
  4366. }
  4367. return this;
  4368. },
  4369. hasClass: function (className) {
  4370. if (!this[0]) return false;
  4371. else return this[0].classList.contains(className);
  4372. },
  4373. toggleClass: function (className) {
  4374. var classes = className.split(' ');
  4375. for (var i = 0; i < classes.length; i++) {
  4376. for (var j = 0; j < this.length; j++) {
  4377. this[j].classList.toggle(classes[i]);
  4378. }
  4379. }
  4380. return this;
  4381. },
  4382. attr: function (attrs, value) {
  4383. if (arguments.length === 1 && typeof attrs === 'string') {
  4384. // Get attr
  4385. if (this[0]) return this[0].getAttribute(attrs);
  4386. else return undefined;
  4387. }
  4388. else {
  4389. // Set attrs
  4390. for (var i = 0; i < this.length; i++) {
  4391. if (arguments.length === 2) {
  4392. // String
  4393. this[i].setAttribute(attrs, value);
  4394. }
  4395. else {
  4396. // Object
  4397. for (var attrName in attrs) {
  4398. this[i][attrName] = attrs[attrName];
  4399. this[i].setAttribute(attrName, attrs[attrName]);
  4400. }
  4401. }
  4402. }
  4403. return this;
  4404. }
  4405. },
  4406. removeAttr: function (attr) {
  4407. for (var i = 0; i < this.length; i++) {
  4408. this[i].removeAttribute(attr);
  4409. }
  4410. return this;
  4411. },
  4412. data: function (key, value) {
  4413. if (typeof value === 'undefined') {
  4414. // Get value
  4415. if (this[0]) {
  4416. var dataKey = this[0].getAttribute('data-' + key);
  4417. if (dataKey) return dataKey;
  4418. else if (this[0].dom7ElementDataStorage && (key in this[0].dom7ElementDataStorage)) return this[0].dom7ElementDataStorage[key];
  4419. else return undefined;
  4420. }
  4421. else return undefined;
  4422. }
  4423. else {
  4424. // Set value
  4425. for (var i = 0; i < this.length; i++) {
  4426. var el = this[i];
  4427. if (!el.dom7ElementDataStorage) el.dom7ElementDataStorage = {};
  4428. el.dom7ElementDataStorage[key] = value;
  4429. }
  4430. return this;
  4431. }
  4432. },
  4433. // Transforms
  4434. transform : function (transform) {
  4435. for (var i = 0; i < this.length; i++) {
  4436. var elStyle = this[i].style;
  4437. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  4438. }
  4439. return this;
  4440. },
  4441. transition: function (duration) {
  4442. if (typeof duration !== 'string') {
  4443. duration = duration + 'ms';
  4444. }
  4445. for (var i = 0; i < this.length; i++) {
  4446. var elStyle = this[i].style;
  4447. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  4448. }
  4449. return this;
  4450. },
  4451. //Events
  4452. on: function (eventName, targetSelector, listener, capture) {
  4453. function handleLiveEvent(e) {
  4454. var target = e.target;
  4455. if ($(target).is(targetSelector)) listener.call(target, e);
  4456. else {
  4457. var parents = $(target).parents();
  4458. for (var k = 0; k < parents.length; k++) {
  4459. if ($(parents[k]).is(targetSelector)) listener.call(parents[k], e);
  4460. }
  4461. }
  4462. }
  4463. var events = eventName.split(' ');
  4464. var i, j;
  4465. for (i = 0; i < this.length; i++) {
  4466. if (typeof targetSelector === 'function' || targetSelector === false) {
  4467. // Usual events
  4468. if (typeof targetSelector === 'function') {
  4469. listener = arguments[1];
  4470. capture = arguments[2] || false;
  4471. }
  4472. for (j = 0; j < events.length; j++) {
  4473. this[i].addEventListener(events[j], listener, capture);
  4474. }
  4475. }
  4476. else {
  4477. //Live events
  4478. for (j = 0; j < events.length; j++) {
  4479. if (!this[i].dom7LiveListeners) this[i].dom7LiveListeners = [];
  4480. this[i].dom7LiveListeners.push({listener: listener, liveListener: handleLiveEvent});
  4481. this[i].addEventListener(events[j], handleLiveEvent, capture);
  4482. }
  4483. }
  4484. }
  4485. return this;
  4486. },
  4487. off: function (eventName, targetSelector, listener, capture) {
  4488. var events = eventName.split(' ');
  4489. for (var i = 0; i < events.length; i++) {
  4490. for (var j = 0; j < this.length; j++) {
  4491. if (typeof targetSelector === 'function' || targetSelector === false) {
  4492. // Usual events
  4493. if (typeof targetSelector === 'function') {
  4494. listener = arguments[1];
  4495. capture = arguments[2] || false;
  4496. }
  4497. this[j].removeEventListener(events[i], listener, capture);
  4498. }
  4499. else {
  4500. // Live event
  4501. if (this[j].dom7LiveListeners) {
  4502. for (var k = 0; k < this[j].dom7LiveListeners.length; k++) {
  4503. if (this[j].dom7LiveListeners[k].listener === listener) {
  4504. this[j].removeEventListener(events[i], this[j].dom7LiveListeners[k].liveListener, capture);
  4505. }
  4506. }
  4507. }
  4508. }
  4509. }
  4510. }
  4511. return this;
  4512. },
  4513. once: function (eventName, targetSelector, listener, capture) {
  4514. var dom = this;
  4515. if (typeof targetSelector === 'function') {
  4516. targetSelector = false;
  4517. listener = arguments[1];
  4518. capture = arguments[2];
  4519. }
  4520. function proxy(e) {
  4521. listener(e);
  4522. dom.off(eventName, targetSelector, proxy, capture);
  4523. }
  4524. dom.on(eventName, targetSelector, proxy, capture);
  4525. },
  4526. trigger: function (eventName, eventData) {
  4527. for (var i = 0; i < this.length; i++) {
  4528. var evt;
  4529. try {
  4530. evt = new window.CustomEvent(eventName, {detail: eventData, bubbles: true, cancelable: true});
  4531. }
  4532. catch (e) {
  4533. evt = document.createEvent('Event');
  4534. evt.initEvent(eventName, true, true);
  4535. evt.detail = eventData;
  4536. }
  4537. this[i].dispatchEvent(evt);
  4538. }
  4539. return this;
  4540. },
  4541. transitionEnd: function (callback) {
  4542. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  4543. i, j, dom = this;
  4544. function fireCallBack(e) {
  4545. /*jshint validthis:true */
  4546. if (e.target !== this) return;
  4547. callback.call(this, e);
  4548. for (i = 0; i < events.length; i++) {
  4549. dom.off(events[i], fireCallBack);
  4550. }
  4551. }
  4552. if (callback) {
  4553. for (i = 0; i < events.length; i++) {
  4554. dom.on(events[i], fireCallBack);
  4555. }
  4556. }
  4557. return this;
  4558. },
  4559. // Sizing/Styles
  4560. width: function () {
  4561. if (this[0] === window) {
  4562. return window.innerWidth;
  4563. }
  4564. else {
  4565. if (this.length > 0) {
  4566. return parseFloat(this.css('width'));
  4567. }
  4568. else {
  4569. return null;
  4570. }
  4571. }
  4572. },
  4573. outerWidth: function (includeMargins) {
  4574. if (this.length > 0) {
  4575. if (includeMargins)
  4576. return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left'));
  4577. else
  4578. return this[0].offsetWidth;
  4579. }
  4580. else return null;
  4581. },
  4582. height: function () {
  4583. if (this[0] === window) {
  4584. return window.innerHeight;
  4585. }
  4586. else {
  4587. if (this.length > 0) {
  4588. return parseFloat(this.css('height'));
  4589. }
  4590. else {
  4591. return null;
  4592. }
  4593. }
  4594. },
  4595. outerHeight: function (includeMargins) {
  4596. if (this.length > 0) {
  4597. if (includeMargins)
  4598. return this[0].offsetHeight + parseFloat(this.css('margin-top')) + parseFloat(this.css('margin-bottom'));
  4599. else
  4600. return this[0].offsetHeight;
  4601. }
  4602. else return null;
  4603. },
  4604. offset: function () {
  4605. if (this.length > 0) {
  4606. var el = this[0];
  4607. var box = el.getBoundingClientRect();
  4608. var body = document.body;
  4609. var clientTop = el.clientTop || body.clientTop || 0;
  4610. var clientLeft = el.clientLeft || body.clientLeft || 0;
  4611. var scrollTop = window.pageYOffset || el.scrollTop;
  4612. var scrollLeft = window.pageXOffset || el.scrollLeft;
  4613. return {
  4614. top: box.top + scrollTop - clientTop,
  4615. left: box.left + scrollLeft - clientLeft
  4616. };
  4617. }
  4618. else {
  4619. return null;
  4620. }
  4621. },
  4622. css: function (props, value) {
  4623. var i;
  4624. if (arguments.length === 1) {
  4625. if (typeof props === 'string') {
  4626. if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props);
  4627. }
  4628. else {
  4629. for (i = 0; i < this.length; i++) {
  4630. for (var prop in props) {
  4631. this[i].style[prop] = props[prop];
  4632. }
  4633. }
  4634. return this;
  4635. }
  4636. }
  4637. if (arguments.length === 2 && typeof props === 'string') {
  4638. for (i = 0; i < this.length; i++) {
  4639. this[i].style[props] = value;
  4640. }
  4641. return this;
  4642. }
  4643. return this;
  4644. },
  4645. //Dom manipulation
  4646. each: function (callback) {
  4647. for (var i = 0; i < this.length; i++) {
  4648. callback.call(this[i], i, this[i]);
  4649. }
  4650. return this;
  4651. },
  4652. html: function (html) {
  4653. if (typeof html === 'undefined') {
  4654. return this[0] ? this[0].innerHTML : undefined;
  4655. }
  4656. else {
  4657. for (var i = 0; i < this.length; i++) {
  4658. this[i].innerHTML = html;
  4659. }
  4660. return this;
  4661. }
  4662. },
  4663. text: function (text) {
  4664. if (typeof text === 'undefined') {
  4665. if (this[0]) {
  4666. return this[0].textContent.trim();
  4667. }
  4668. else return null;
  4669. }
  4670. else {
  4671. for (var i = 0; i < this.length; i++) {
  4672. this[i].textContent = text;
  4673. }
  4674. return this;
  4675. }
  4676. },
  4677. is: function (selector) {
  4678. if (!this[0]) return false;
  4679. var compareWith, i;
  4680. if (typeof selector === 'string') {
  4681. var el = this[0];
  4682. if (el === document) return selector === document;
  4683. if (el === window) return selector === window;
  4684. if (el.matches) return el.matches(selector);
  4685. else if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector);
  4686. else if (el.mozMatchesSelector) return el.mozMatchesSelector(selector);
  4687. else if (el.msMatchesSelector) return el.msMatchesSelector(selector);
  4688. else {
  4689. compareWith = $(selector);
  4690. for (i = 0; i < compareWith.length; i++) {
  4691. if (compareWith[i] === this[0]) return true;
  4692. }
  4693. return false;
  4694. }
  4695. }
  4696. else if (selector === document) return this[0] === document;
  4697. else if (selector === window) return this[0] === window;
  4698. else {
  4699. if (selector.nodeType || selector instanceof Dom7) {
  4700. compareWith = selector.nodeType ? [selector] : selector;
  4701. for (i = 0; i < compareWith.length; i++) {
  4702. if (compareWith[i] === this[0]) return true;
  4703. }
  4704. return false;
  4705. }
  4706. return false;
  4707. }
  4708. },
  4709. index: function () {
  4710. if (this[0]) {
  4711. var child = this[0];
  4712. var i = 0;
  4713. while ((child = child.previousSibling) !== null) {
  4714. if (child.nodeType === 1) i++;
  4715. }
  4716. return i;
  4717. }
  4718. else return undefined;
  4719. },
  4720. eq: function (index) {
  4721. if (typeof index === 'undefined') return this;
  4722. var length = this.length;
  4723. var returnIndex;
  4724. if (index > length - 1) {
  4725. return new Dom7([]);
  4726. }
  4727. if (index < 0) {
  4728. returnIndex = length + index;
  4729. if (returnIndex < 0) return new Dom7([]);
  4730. else return new Dom7([this[returnIndex]]);
  4731. }
  4732. return new Dom7([this[index]]);
  4733. },
  4734. append: function (newChild) {
  4735. var i, j;
  4736. for (i = 0; i < this.length; i++) {
  4737. if (typeof newChild === 'string') {
  4738. var tempDiv = document.createElement('div');
  4739. tempDiv.innerHTML = newChild;
  4740. while (tempDiv.firstChild) {
  4741. this[i].appendChild(tempDiv.firstChild);
  4742. }
  4743. }
  4744. else if (newChild instanceof Dom7) {
  4745. for (j = 0; j < newChild.length; j++) {
  4746. this[i].appendChild(newChild[j]);
  4747. }
  4748. }
  4749. else {
  4750. this[i].appendChild(newChild);
  4751. }
  4752. }
  4753. return this;
  4754. },
  4755. prepend: function (newChild) {
  4756. var i, j;
  4757. for (i = 0; i < this.length; i++) {
  4758. if (typeof newChild === 'string') {
  4759. var tempDiv = document.createElement('div');
  4760. tempDiv.innerHTML = newChild;
  4761. for (j = tempDiv.childNodes.length - 1; j >= 0; j--) {
  4762. this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
  4763. }
  4764. // this[i].insertAdjacentHTML('afterbegin', newChild);
  4765. }
  4766. else if (newChild instanceof Dom7) {
  4767. for (j = 0; j < newChild.length; j++) {
  4768. this[i].insertBefore(newChild[j], this[i].childNodes[0]);
  4769. }
  4770. }
  4771. else {
  4772. this[i].insertBefore(newChild, this[i].childNodes[0]);
  4773. }
  4774. }
  4775. return this;
  4776. },
  4777. insertBefore: function (selector) {
  4778. var before = $(selector);
  4779. for (var i = 0; i < this.length; i++) {
  4780. if (before.length === 1) {
  4781. before[0].parentNode.insertBefore(this[i], before[0]);
  4782. }
  4783. else if (before.length > 1) {
  4784. for (var j = 0; j < before.length; j++) {
  4785. before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]);
  4786. }
  4787. }
  4788. }
  4789. },
  4790. insertAfter: function (selector) {
  4791. var after = $(selector);
  4792. for (var i = 0; i < this.length; i++) {
  4793. if (after.length === 1) {
  4794. after[0].parentNode.insertBefore(this[i], after[0].nextSibling);
  4795. }
  4796. else if (after.length > 1) {
  4797. for (var j = 0; j < after.length; j++) {
  4798. after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling);
  4799. }
  4800. }
  4801. }
  4802. },
  4803. next: function (selector) {
  4804. if (this.length > 0) {
  4805. if (selector) {
  4806. if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) return new Dom7([this[0].nextElementSibling]);
  4807. else return new Dom7([]);
  4808. }
  4809. else {
  4810. if (this[0].nextElementSibling) return new Dom7([this[0].nextElementSibling]);
  4811. else return new Dom7([]);
  4812. }
  4813. }
  4814. else return new Dom7([]);
  4815. },
  4816. nextAll: function (selector) {
  4817. var nextEls = [];
  4818. var el = this[0];
  4819. if (!el) return new Dom7([]);
  4820. while (el.nextElementSibling) {
  4821. var next = el.nextElementSibling;
  4822. if (selector) {
  4823. if($(next).is(selector)) nextEls.push(next);
  4824. }
  4825. else nextEls.push(next);
  4826. el = next;
  4827. }
  4828. return new Dom7(nextEls);
  4829. },
  4830. prev: function (selector) {
  4831. if (this.length > 0) {
  4832. if (selector) {
  4833. if (this[0].previousElementSibling && $(this[0].previousElementSibling).is(selector)) return new Dom7([this[0].previousElementSibling]);
  4834. else return new Dom7([]);
  4835. }
  4836. else {
  4837. if (this[0].previousElementSibling) return new Dom7([this[0].previousElementSibling]);
  4838. else return new Dom7([]);
  4839. }
  4840. }
  4841. else return new Dom7([]);
  4842. },
  4843. prevAll: function (selector) {
  4844. var prevEls = [];
  4845. var el = this[0];
  4846. if (!el) return new Dom7([]);
  4847. while (el.previousElementSibling) {
  4848. var prev = el.previousElementSibling;
  4849. if (selector) {
  4850. if($(prev).is(selector)) prevEls.push(prev);
  4851. }
  4852. else prevEls.push(prev);
  4853. el = prev;
  4854. }
  4855. return new Dom7(prevEls);
  4856. },
  4857. parent: function (selector) {
  4858. var parents = [];
  4859. for (var i = 0; i < this.length; i++) {
  4860. if (selector) {
  4861. if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode);
  4862. }
  4863. else {
  4864. parents.push(this[i].parentNode);
  4865. }
  4866. }
  4867. return $($.unique(parents));
  4868. },
  4869. parents: function (selector) {
  4870. var parents = [];
  4871. for (var i = 0; i < this.length; i++) {
  4872. var parent = this[i].parentNode;
  4873. while (parent) {
  4874. if (selector) {
  4875. if ($(parent).is(selector)) parents.push(parent);
  4876. }
  4877. else {
  4878. parents.push(parent);
  4879. }
  4880. parent = parent.parentNode;
  4881. }
  4882. }
  4883. return $($.unique(parents));
  4884. },
  4885. find : function (selector) {
  4886. var foundElements = [];
  4887. for (var i = 0; i < this.length; i++) {
  4888. var found = this[i].querySelectorAll(selector);
  4889. for (var j = 0; j < found.length; j++) {
  4890. foundElements.push(found[j]);
  4891. }
  4892. }
  4893. return new Dom7(foundElements);
  4894. },
  4895. children: function (selector) {
  4896. var children = [];
  4897. for (var i = 0; i < this.length; i++) {
  4898. var childNodes = this[i].childNodes;
  4899. for (var j = 0; j < childNodes.length; j++) {
  4900. if (!selector) {
  4901. if (childNodes[j].nodeType === 1) children.push(childNodes[j]);
  4902. }
  4903. else {
  4904. if (childNodes[j].nodeType === 1 && $(childNodes[j]).is(selector)) children.push(childNodes[j]);
  4905. }
  4906. }
  4907. }
  4908. return new Dom7($.unique(children));
  4909. },
  4910. remove: function () {
  4911. for (var i = 0; i < this.length; i++) {
  4912. if (this[i].parentNode) this[i].parentNode.removeChild(this[i]);
  4913. }
  4914. return this;
  4915. },
  4916. add: function () {
  4917. var dom = this;
  4918. var i, j;
  4919. for (i = 0; i < arguments.length; i++) {
  4920. var toAdd = $(arguments[i]);
  4921. for (j = 0; j < toAdd.length; j++) {
  4922. dom[dom.length] = toAdd[j];
  4923. dom.length++;
  4924. }
  4925. }
  4926. return dom;
  4927. }
  4928. };
  4929. $.fn = Dom7.prototype;
  4930. $.unique = function (arr) {
  4931. var unique = [];
  4932. for (var i = 0; i < arr.length; i++) {
  4933. if (unique.indexOf(arr[i]) === -1) unique.push(arr[i]);
  4934. }
  4935. return unique;
  4936. };
  4937. return $;
  4938. })();
  4939. /*===========================
  4940. Get Dom libraries
  4941. ===========================*/
  4942. var swiperDomPlugins = ['jQuery', 'Zepto', 'Dom7'];
  4943. for (var i = 0; i < swiperDomPlugins.length; i++) {
  4944. if (window[swiperDomPlugins[i]]) {
  4945. addLibraryPlugin(window[swiperDomPlugins[i]]);
  4946. }
  4947. }
  4948. // Required DOM Plugins
  4949. var domLib;
  4950. if (typeof Dom7 === 'undefined') {
  4951. domLib = window.Dom7 || window.Zepto || window.jQuery;
  4952. }
  4953. else {
  4954. domLib = Dom7;
  4955. }
  4956. /*===========================
  4957. Add .swiper plugin from Dom libraries
  4958. ===========================*/
  4959. function addLibraryPlugin(lib) {
  4960. lib.fn.swiper = function (params) {
  4961. var firstInstance;
  4962. lib(this).each(function () {
  4963. var s = new Swiper(this, params);
  4964. if (!firstInstance) firstInstance = s;
  4965. });
  4966. return firstInstance;
  4967. };
  4968. }
  4969. if (domLib) {
  4970. if (!('transitionEnd' in domLib.fn)) {
  4971. domLib.fn.transitionEnd = function (callback) {
  4972. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  4973. i, j, dom = this;
  4974. function fireCallBack(e) {
  4975. /*jshint validthis:true */
  4976. if (e.target !== this) return;
  4977. callback.call(this, e);
  4978. for (i = 0; i < events.length; i++) {
  4979. dom.off(events[i], fireCallBack);
  4980. }
  4981. }
  4982. if (callback) {
  4983. for (i = 0; i < events.length; i++) {
  4984. dom.on(events[i], fireCallBack);
  4985. }
  4986. }
  4987. return this;
  4988. };
  4989. }
  4990. if (!('transform' in domLib.fn)) {
  4991. domLib.fn.transform = function (transform) {
  4992. for (var i = 0; i < this.length; i++) {
  4993. var elStyle = this[i].style;
  4994. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  4995. }
  4996. return this;
  4997. };
  4998. }
  4999. if (!('transition' in domLib.fn)) {
  5000. domLib.fn.transition = function (duration) {
  5001. if (typeof duration !== 'string') {
  5002. duration = duration + 'ms';
  5003. }
  5004. for (var i = 0; i < this.length; i++) {
  5005. var elStyle = this[i].style;
  5006. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  5007. }
  5008. return this;
  5009. };
  5010. }
  5011. if (!('outerWidth' in domLib.fn)) {
  5012. domLib.fn.outerWidth = function (includeMargins) {
  5013. if (this.length > 0) {
  5014. if (includeMargins)
  5015. return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left'));
  5016. else
  5017. return this[0].offsetWidth;
  5018. }
  5019. else return null;
  5020. };
  5021. }
  5022. }
  5023. window.Swiper = Swiper;
  5024. })();
  5025. /*===========================
  5026. Swiper AMD Export
  5027. ===========================*/
  5028. if (typeof(module) !== 'undefined')
  5029. {
  5030. module.exports = window.Swiper;
  5031. }
  5032. else if (typeof define === 'function' && define.amd) {
  5033. define([], function () {
  5034. 'use strict';
  5035. return window.Swiper;
  5036. });
  5037. }
  5038. //# sourceMappingURL=maps/swiper.js.map