swiper.js 184 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379
  1. /**
  2. * Swiper 3.3.0
  3. * Most modern mobile touch slider and framework with hardware accelerated transitions
  4. *
  5. * http://www.idangero.us/swiper/
  6. *
  7. * Copyright 2016, Vladimir Kharlampidi
  8. * The iDangero.us
  9. * http://www.idangero.us/
  10. *
  11. * Licensed under MIT
  12. *
  13. * Released on: January 10, 2016
  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. freeModeSticky: false,
  42. freeModeMinimumVelocity: 0.02,
  43. // Autoheight
  44. autoHeight: false,
  45. // Set wrapper width
  46. setWrapperSize: false,
  47. // Virtual Translate
  48. virtualTranslate: false,
  49. // Effects
  50. effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip'
  51. coverflow: {
  52. rotate: 50,
  53. stretch: 0,
  54. depth: 100,
  55. modifier: 1,
  56. slideShadows : true
  57. },
  58. flip: {
  59. slideShadows : true,
  60. limitRotation: true
  61. },
  62. cube: {
  63. slideShadows: true,
  64. shadow: true,
  65. shadowOffset: 20,
  66. shadowScale: 0.94
  67. },
  68. fade: {
  69. crossFade: false
  70. },
  71. // Parallax
  72. parallax: false,
  73. // Scrollbar
  74. scrollbar: null,
  75. scrollbarHide: true,
  76. scrollbarDraggable: false,
  77. scrollbarSnapOnRelease: false,
  78. // Keyboard Mousewheel
  79. keyboardControl: false,
  80. mousewheelControl: false,
  81. mousewheelReleaseOnEdges: false,
  82. mousewheelInvert: false,
  83. mousewheelForceToAxis: false,
  84. mousewheelSensitivity: 1,
  85. // Hash Navigation
  86. hashnav: false,
  87. // Breakpoints
  88. breakpoints: undefined,
  89. // Slides grid
  90. spaceBetween: 0,
  91. slidesPerView: 1,
  92. slidesPerColumn: 1,
  93. slidesPerColumnFill: 'column',
  94. slidesPerGroup: 1,
  95. centeredSlides: false,
  96. slidesOffsetBefore: 0, // in px
  97. slidesOffsetAfter: 0, // in px
  98. // Round length
  99. roundLengths: false,
  100. // Touches
  101. touchRatio: 1,
  102. touchAngle: 45,
  103. simulateTouch: true,
  104. shortSwipes: true,
  105. longSwipes: true,
  106. longSwipesRatio: 0.5,
  107. longSwipesMs: 300,
  108. followFinger: true,
  109. onlyExternal: false,
  110. threshold: 0,
  111. touchMoveStopPropagation: true,
  112. // Pagination
  113. pagination: null,
  114. paginationElement: 'span',
  115. paginationClickable: false,
  116. paginationHide: false,
  117. paginationBulletRender: null,
  118. paginationProgressRender: null,
  119. paginationFractionRender: null,
  120. paginationCustomRender: null,
  121. paginationType: 'bullets', // 'bullets' or 'progress' or 'fraction' or 'custom'
  122. // Resistance
  123. resistance: true,
  124. resistanceRatio: 0.85,
  125. // Next/prev buttons
  126. nextButton: null,
  127. prevButton: null,
  128. // Progress
  129. watchSlidesProgress: false,
  130. watchSlidesVisibility: false,
  131. // Cursor
  132. grabCursor: false,
  133. // Clicks
  134. preventClicks: true,
  135. preventClicksPropagation: true,
  136. slideToClickedSlide: false,
  137. // Lazy Loading
  138. lazyLoading: false,
  139. lazyLoadingInPrevNext: false,
  140. lazyLoadingInPrevNextAmount: 1,
  141. lazyLoadingOnTransitionStart: false,
  142. // Images
  143. preloadImages: true,
  144. updateOnImagesReady: true,
  145. // loop
  146. loop: false,
  147. loopAdditionalSlides: 0,
  148. loopedSlides: null,
  149. // Control
  150. control: undefined,
  151. controlInverse: false,
  152. controlBy: 'slide', //or 'container'
  153. // Swiping/no swiping
  154. allowSwipeToPrev: true,
  155. allowSwipeToNext: true,
  156. swipeHandler: null, //'.swipe-handler',
  157. noSwiping: true,
  158. noSwipingClass: 'swiper-no-swiping',
  159. // NS
  160. slideClass: 'swiper-slide',
  161. slideActiveClass: 'swiper-slide-active',
  162. slideVisibleClass: 'swiper-slide-visible',
  163. slideDuplicateClass: 'swiper-slide-duplicate',
  164. slideNextClass: 'swiper-slide-next',
  165. slidePrevClass: 'swiper-slide-prev',
  166. wrapperClass: 'swiper-wrapper',
  167. bulletClass: 'swiper-pagination-bullet',
  168. bulletActiveClass: 'swiper-pagination-bullet-active',
  169. buttonDisabledClass: 'swiper-button-disabled',
  170. paginationCurrentClass: 'swiper-pagination-current',
  171. paginationTotalClass: 'swiper-pagination-total',
  172. paginationHiddenClass: 'swiper-pagination-hidden',
  173. paginationProgressbarClass: 'swiper-pagination-progressbar',
  174. // Observer
  175. observer: false,
  176. observeParents: false,
  177. // Accessibility
  178. a11y: false,
  179. prevSlideMessage: 'Previous slide',
  180. nextSlideMessage: 'Next slide',
  181. firstSlideMessage: 'This is the first slide',
  182. lastSlideMessage: 'This is the last slide',
  183. paginationBulletMessage: 'Go to slide {{index}}',
  184. // Callbacks
  185. runCallbacksOnInit: true
  186. /*
  187. Callbacks:
  188. onInit: function (swiper)
  189. onDestroy: function (swiper)
  190. onClick: function (swiper, e)
  191. onTap: function (swiper, e)
  192. onDoubleTap: function (swiper, e)
  193. onSliderMove: function (swiper, e)
  194. onSlideChangeStart: function (swiper)
  195. onSlideChangeEnd: function (swiper)
  196. onTransitionStart: function (swiper)
  197. onTransitionEnd: function (swiper)
  198. onImagesReady: function (swiper)
  199. onProgress: function (swiper, progress)
  200. onTouchStart: function (swiper, e)
  201. onTouchMove: function (swiper, e)
  202. onTouchMoveOpposite: function (swiper, e)
  203. onTouchEnd: function (swiper, e)
  204. onReachBeginning: function (swiper)
  205. onReachEnd: function (swiper)
  206. onSetTransition: function (swiper, duration)
  207. onSetTranslate: function (swiper, translate)
  208. onAutoplayStart: function (swiper)
  209. onAutoplayStop: function (swiper),
  210. onLazyImageLoad: function (swiper, slide, image)
  211. onLazyImageReady: function (swiper, slide, image)
  212. */
  213. };
  214. var initialVirtualTranslate = params && params.virtualTranslate;
  215. params = params || {};
  216. var originalParams = {};
  217. for (var param in params) {
  218. 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))) {
  219. originalParams[param] = {};
  220. for (var deepParam in params[param]) {
  221. originalParams[param][deepParam] = params[param][deepParam];
  222. }
  223. }
  224. else {
  225. originalParams[param] = params[param];
  226. }
  227. }
  228. for (var def in defaults) {
  229. if (typeof params[def] === 'undefined') {
  230. params[def] = defaults[def];
  231. }
  232. else if (typeof params[def] === 'object') {
  233. for (var deepDef in defaults[def]) {
  234. if (typeof params[def][deepDef] === 'undefined') {
  235. params[def][deepDef] = defaults[def][deepDef];
  236. }
  237. }
  238. }
  239. }
  240. // Swiper
  241. var s = this;
  242. // Params
  243. s.params = params;
  244. s.originalParams = originalParams;
  245. // Classname
  246. s.classNames = [];
  247. /*=========================
  248. Dom Library and plugins
  249. ===========================*/
  250. if (typeof $ !== 'undefined' && typeof Dom7 !== 'undefined'){
  251. $ = Dom7;
  252. }
  253. if (typeof $ === 'undefined') {
  254. if (typeof Dom7 === 'undefined') {
  255. $ = window.Dom7 || window.Zepto || window.jQuery;
  256. }
  257. else {
  258. $ = Dom7;
  259. }
  260. if (!$) return;
  261. }
  262. // Export it to Swiper instance
  263. s.$ = $;
  264. /*=========================
  265. Breakpoints
  266. ===========================*/
  267. s.currentBreakpoint = undefined;
  268. s.getActiveBreakpoint = function () {
  269. //Get breakpoint for window width
  270. if (!s.params.breakpoints) return false;
  271. var breakpoint = false;
  272. var points = [], point;
  273. for ( point in s.params.breakpoints ) {
  274. if (s.params.breakpoints.hasOwnProperty(point)) {
  275. points.push(point);
  276. }
  277. }
  278. points.sort(function (a, b) {
  279. return parseInt(a, 10) > parseInt(b, 10);
  280. });
  281. for (var i = 0; i < points.length; i++) {
  282. point = points[i];
  283. if (point >= window.innerWidth && !breakpoint) {
  284. breakpoint = point;
  285. }
  286. }
  287. return breakpoint || 'max';
  288. };
  289. s.setBreakpoint = function () {
  290. //Set breakpoint for window width and update parameters
  291. var breakpoint = s.getActiveBreakpoint();
  292. if (breakpoint && s.currentBreakpoint !== breakpoint) {
  293. var breakPointsParams = breakpoint in s.params.breakpoints ? s.params.breakpoints[breakpoint] : s.originalParams;
  294. for ( var param in breakPointsParams ) {
  295. s.params[param] = breakPointsParams[param];
  296. }
  297. s.currentBreakpoint = breakpoint;
  298. }
  299. };
  300. // Set breakpoint on load
  301. if (s.params.breakpoints) {
  302. s.setBreakpoint();
  303. }
  304. /*=========================
  305. Preparation - Define Container, Wrapper and Pagination
  306. ===========================*/
  307. s.container = $(container);
  308. if (s.container.length === 0) return;
  309. if (s.container.length > 1) {
  310. s.container.each(function () {
  311. new Swiper(this, params);
  312. });
  313. return;
  314. }
  315. // Save instance in container HTML Element and in data
  316. s.container[0].swiper = s;
  317. s.container.data('swiper', s);
  318. s.classNames.push('swiper-container-' + s.params.direction);
  319. if (s.params.freeMode) {
  320. s.classNames.push('swiper-container-free-mode');
  321. }
  322. if (!s.support.flexbox) {
  323. s.classNames.push('swiper-container-no-flexbox');
  324. s.params.slidesPerColumn = 1;
  325. }
  326. if (s.params.autoHeight) {
  327. s.classNames.push('swiper-container-autoheight');
  328. }
  329. // Enable slides progress when required
  330. if (s.params.parallax || s.params.watchSlidesVisibility) {
  331. s.params.watchSlidesProgress = true;
  332. }
  333. // Coverflow / 3D
  334. if (['cube', 'coverflow', 'flip'].indexOf(s.params.effect) >= 0) {
  335. if (s.support.transforms3d) {
  336. s.params.watchSlidesProgress = true;
  337. s.classNames.push('swiper-container-3d');
  338. }
  339. else {
  340. s.params.effect = 'slide';
  341. }
  342. }
  343. if (s.params.effect !== 'slide') {
  344. s.classNames.push('swiper-container-' + s.params.effect);
  345. }
  346. if (s.params.effect === 'cube') {
  347. s.params.resistanceRatio = 0;
  348. s.params.slidesPerView = 1;
  349. s.params.slidesPerColumn = 1;
  350. s.params.slidesPerGroup = 1;
  351. s.params.centeredSlides = false;
  352. s.params.spaceBetween = 0;
  353. s.params.virtualTranslate = true;
  354. s.params.setWrapperSize = false;
  355. }
  356. if (s.params.effect === 'fade' || s.params.effect === 'flip') {
  357. s.params.slidesPerView = 1;
  358. s.params.slidesPerColumn = 1;
  359. s.params.slidesPerGroup = 1;
  360. s.params.watchSlidesProgress = true;
  361. s.params.spaceBetween = 0;
  362. s.params.setWrapperSize = false;
  363. if (typeof initialVirtualTranslate === 'undefined') {
  364. s.params.virtualTranslate = true;
  365. }
  366. }
  367. // Grab Cursor
  368. if (s.params.grabCursor && s.support.touch) {
  369. s.params.grabCursor = false;
  370. }
  371. // Wrapper
  372. s.wrapper = s.container.children('.' + s.params.wrapperClass);
  373. // Pagination
  374. if (s.params.pagination) {
  375. s.paginationContainer = $(s.params.pagination);
  376. if (s.params.paginationType === 'bullets' && s.params.paginationClickable) {
  377. s.paginationContainer.addClass('swiper-pagination-clickable');
  378. }
  379. else {
  380. s.params.paginationClickable = false;
  381. }
  382. s.paginationContainer.addClass('swiper-pagination-' + s.params.paginationType);
  383. }
  384. // Is Horizontal
  385. s.isHorizontal = function () {
  386. return s.params.direction === 'horizontal';
  387. };
  388. // s.isH = isH;
  389. // RTL
  390. s.rtl = s.isHorizontal() && (s.container[0].dir.toLowerCase() === 'rtl' || s.container.css('direction') === 'rtl');
  391. if (s.rtl) {
  392. s.classNames.push('swiper-container-rtl');
  393. }
  394. // Wrong RTL support
  395. if (s.rtl) {
  396. s.wrongRTL = s.wrapper.css('display') === '-webkit-box';
  397. }
  398. // Columns
  399. if (s.params.slidesPerColumn > 1) {
  400. s.classNames.push('swiper-container-multirow');
  401. }
  402. // Check for Android
  403. if (s.device.android) {
  404. s.classNames.push('swiper-container-android');
  405. }
  406. // Add classes
  407. s.container.addClass(s.classNames.join(' '));
  408. // Translate
  409. s.translate = 0;
  410. // Progress
  411. s.progress = 0;
  412. // Velocity
  413. s.velocity = 0;
  414. /*=========================
  415. Locks, unlocks
  416. ===========================*/
  417. s.lockSwipeToNext = function () {
  418. s.params.allowSwipeToNext = false;
  419. };
  420. s.lockSwipeToPrev = function () {
  421. s.params.allowSwipeToPrev = false;
  422. };
  423. s.lockSwipes = function () {
  424. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = false;
  425. };
  426. s.unlockSwipeToNext = function () {
  427. s.params.allowSwipeToNext = true;
  428. };
  429. s.unlockSwipeToPrev = function () {
  430. s.params.allowSwipeToPrev = true;
  431. };
  432. s.unlockSwipes = function () {
  433. s.params.allowSwipeToNext = s.params.allowSwipeToPrev = true;
  434. };
  435. /*=========================
  436. Round helper
  437. ===========================*/
  438. function round(a) {
  439. return Math.floor(a);
  440. }
  441. /*=========================
  442. Set grab cursor
  443. ===========================*/
  444. if (s.params.grabCursor) {
  445. s.container[0].style.cursor = 'move';
  446. s.container[0].style.cursor = '-webkit-grab';
  447. s.container[0].style.cursor = '-moz-grab';
  448. s.container[0].style.cursor = 'grab';
  449. }
  450. /*=========================
  451. Update on Images Ready
  452. ===========================*/
  453. s.imagesToLoad = [];
  454. s.imagesLoaded = 0;
  455. s.loadImage = function (imgElement, src, srcset, checkForComplete, callback) {
  456. var image;
  457. function onReady () {
  458. if (callback) callback();
  459. }
  460. if (!imgElement.complete || !checkForComplete) {
  461. if (src) {
  462. image = new window.Image();
  463. image.onload = onReady;
  464. image.onerror = onReady;
  465. if (srcset) {
  466. image.srcset = srcset;
  467. }
  468. if (src) {
  469. image.src = src;
  470. }
  471. } else {
  472. onReady();
  473. }
  474. } else {//image already loaded...
  475. onReady();
  476. }
  477. };
  478. s.preloadImages = function () {
  479. s.imagesToLoad = s.container.find('img');
  480. function _onReady() {
  481. if (typeof s === 'undefined' || s === null) return;
  482. if (s.imagesLoaded !== undefined) s.imagesLoaded++;
  483. if (s.imagesLoaded === s.imagesToLoad.length) {
  484. if (s.params.updateOnImagesReady) s.update();
  485. s.emit('onImagesReady', s);
  486. }
  487. }
  488. for (var i = 0; i < s.imagesToLoad.length; i++) {
  489. s.loadImage(s.imagesToLoad[i], (s.imagesToLoad[i].currentSrc || s.imagesToLoad[i].getAttribute('src')), (s.imagesToLoad[i].srcset || s.imagesToLoad[i].getAttribute('srcset')), true, _onReady);
  490. }
  491. };
  492. /*=========================
  493. Autoplay
  494. ===========================*/
  495. s.autoplayTimeoutId = undefined;
  496. s.autoplaying = false;
  497. s.autoplayPaused = false;
  498. function autoplay() {
  499. s.autoplayTimeoutId = setTimeout(function () {
  500. if (s.params.loop) {
  501. s.fixLoop();
  502. s._slideNext();
  503. s.emit('onAutoplay', s);
  504. }
  505. else {
  506. if (!s.isEnd) {
  507. s._slideNext();
  508. s.emit('onAutoplay', s);
  509. }
  510. else {
  511. if (!params.autoplayStopOnLast) {
  512. s._slideTo(0);
  513. s.emit('onAutoplay', s);
  514. }
  515. else {
  516. s.stopAutoplay();
  517. }
  518. }
  519. }
  520. }, s.params.autoplay);
  521. }
  522. s.startAutoplay = function () {
  523. if (typeof s.autoplayTimeoutId !== 'undefined') return false;
  524. if (!s.params.autoplay) return false;
  525. if (s.autoplaying) return false;
  526. s.autoplaying = true;
  527. s.emit('onAutoplayStart', s);
  528. autoplay();
  529. };
  530. s.stopAutoplay = function (internal) {
  531. if (!s.autoplayTimeoutId) return;
  532. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  533. s.autoplaying = false;
  534. s.autoplayTimeoutId = undefined;
  535. s.emit('onAutoplayStop', s);
  536. };
  537. s.pauseAutoplay = function (speed) {
  538. if (s.autoplayPaused) return;
  539. if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
  540. s.autoplayPaused = true;
  541. if (speed === 0) {
  542. s.autoplayPaused = false;
  543. autoplay();
  544. }
  545. else {
  546. s.wrapper.transitionEnd(function () {
  547. if (!s) return;
  548. s.autoplayPaused = false;
  549. if (!s.autoplaying) {
  550. s.stopAutoplay();
  551. }
  552. else {
  553. autoplay();
  554. }
  555. });
  556. }
  557. };
  558. /*=========================
  559. Min/Max Translate
  560. ===========================*/
  561. s.minTranslate = function () {
  562. return (-s.snapGrid[0]);
  563. };
  564. s.maxTranslate = function () {
  565. return (-s.snapGrid[s.snapGrid.length - 1]);
  566. };
  567. /*=========================
  568. Slider/slides sizes
  569. ===========================*/
  570. s.updateAutoHeight = function () {
  571. // Update Height
  572. var slide = s.slides.eq(s.activeIndex)[0];
  573. if (typeof slide !== 'undefined') {
  574. var newHeight = slide.offsetHeight;
  575. if (newHeight) s.wrapper.css('height', newHeight + 'px');
  576. }
  577. };
  578. s.updateContainerSize = function () {
  579. var width, height;
  580. if (typeof s.params.width !== 'undefined') {
  581. width = s.params.width;
  582. }
  583. else {
  584. width = s.container[0].clientWidth;
  585. }
  586. if (typeof s.params.height !== 'undefined') {
  587. height = s.params.height;
  588. }
  589. else {
  590. height = s.container[0].clientHeight;
  591. }
  592. if (width === 0 && s.isHorizontal() || height === 0 && !s.isHorizontal()) {
  593. return;
  594. }
  595. //Subtract paddings
  596. width = width - parseInt(s.container.css('padding-left'), 10) - parseInt(s.container.css('padding-right'), 10);
  597. height = height - parseInt(s.container.css('padding-top'), 10) - parseInt(s.container.css('padding-bottom'), 10);
  598. // Store values
  599. s.width = width;
  600. s.height = height;
  601. s.size = s.isHorizontal() ? s.width : s.height;
  602. };
  603. s.updateSlidesSize = function () {
  604. s.slides = s.wrapper.children('.' + s.params.slideClass);
  605. s.snapGrid = [];
  606. s.slidesGrid = [];
  607. s.slidesSizesGrid = [];
  608. var spaceBetween = s.params.spaceBetween,
  609. slidePosition = -s.params.slidesOffsetBefore,
  610. i,
  611. prevSlideSize = 0,
  612. index = 0;
  613. if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
  614. spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s.size;
  615. }
  616. s.virtualSize = -spaceBetween;
  617. // reset margins
  618. if (s.rtl) s.slides.css({marginLeft: '', marginTop: ''});
  619. else s.slides.css({marginRight: '', marginBottom: ''});
  620. var slidesNumberEvenToRows;
  621. if (s.params.slidesPerColumn > 1) {
  622. if (Math.floor(s.slides.length / s.params.slidesPerColumn) === s.slides.length / s.params.slidesPerColumn) {
  623. slidesNumberEvenToRows = s.slides.length;
  624. }
  625. else {
  626. slidesNumberEvenToRows = Math.ceil(s.slides.length / s.params.slidesPerColumn) * s.params.slidesPerColumn;
  627. }
  628. if (s.params.slidesPerView !== 'auto' && s.params.slidesPerColumnFill === 'row') {
  629. slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, s.params.slidesPerView * s.params.slidesPerColumn);
  630. }
  631. }
  632. // Calc slides
  633. var slideSize;
  634. var slidesPerColumn = s.params.slidesPerColumn;
  635. var slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
  636. var numFullColumns = slidesPerRow - (s.params.slidesPerColumn * slidesPerRow - s.slides.length);
  637. for (i = 0; i < s.slides.length; i++) {
  638. slideSize = 0;
  639. var slide = s.slides.eq(i);
  640. if (s.params.slidesPerColumn > 1) {
  641. // Set slides order
  642. var newSlideOrderIndex;
  643. var column, row;
  644. if (s.params.slidesPerColumnFill === 'column') {
  645. column = Math.floor(i / slidesPerColumn);
  646. row = i - column * slidesPerColumn;
  647. if (column > numFullColumns || (column === numFullColumns && row === slidesPerColumn-1)) {
  648. if (++row >= slidesPerColumn) {
  649. row = 0;
  650. column++;
  651. }
  652. }
  653. newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
  654. slide
  655. .css({
  656. '-webkit-box-ordinal-group': newSlideOrderIndex,
  657. '-moz-box-ordinal-group': newSlideOrderIndex,
  658. '-ms-flex-order': newSlideOrderIndex,
  659. '-webkit-order': newSlideOrderIndex,
  660. 'order': newSlideOrderIndex
  661. });
  662. }
  663. else {
  664. row = Math.floor(i / slidesPerRow);
  665. column = i - row * slidesPerRow;
  666. }
  667. slide
  668. .css({
  669. 'margin-top': (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px')
  670. })
  671. .attr('data-swiper-column', column)
  672. .attr('data-swiper-row', row);
  673. }
  674. if (slide.css('display') === 'none') continue;
  675. if (s.params.slidesPerView === 'auto') {
  676. slideSize = s.isHorizontal() ? slide.outerWidth(true) : slide.outerHeight(true);
  677. if (s.params.roundLengths) slideSize = round(slideSize);
  678. }
  679. else {
  680. slideSize = (s.size - (s.params.slidesPerView - 1) * spaceBetween) / s.params.slidesPerView;
  681. if (s.params.roundLengths) slideSize = round(slideSize);
  682. if (s.isHorizontal()) {
  683. s.slides[i].style.width = slideSize + 'px';
  684. }
  685. else {
  686. s.slides[i].style.height = slideSize + 'px';
  687. }
  688. }
  689. s.slides[i].swiperSlideSize = slideSize;
  690. s.slidesSizesGrid.push(slideSize);
  691. if (s.params.centeredSlides) {
  692. slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
  693. if (i === 0) slidePosition = slidePosition - s.size / 2 - spaceBetween;
  694. if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
  695. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  696. s.slidesGrid.push(slidePosition);
  697. }
  698. else {
  699. if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
  700. s.slidesGrid.push(slidePosition);
  701. slidePosition = slidePosition + slideSize + spaceBetween;
  702. }
  703. s.virtualSize += slideSize + spaceBetween;
  704. prevSlideSize = slideSize;
  705. index ++;
  706. }
  707. s.virtualSize = Math.max(s.virtualSize, s.size) + s.params.slidesOffsetAfter;
  708. var newSlidesGrid;
  709. if (
  710. s.rtl && s.wrongRTL && (s.params.effect === 'slide' || s.params.effect === 'coverflow')) {
  711. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  712. }
  713. if (!s.support.flexbox || s.params.setWrapperSize) {
  714. if (s.isHorizontal()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  715. else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
  716. }
  717. if (s.params.slidesPerColumn > 1) {
  718. s.virtualSize = (slideSize + s.params.spaceBetween) * slidesNumberEvenToRows;
  719. s.virtualSize = Math.ceil(s.virtualSize / s.params.slidesPerColumn) - s.params.spaceBetween;
  720. s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
  721. if (s.params.centeredSlides) {
  722. newSlidesGrid = [];
  723. for (i = 0; i < s.snapGrid.length; i++) {
  724. if (s.snapGrid[i] < s.virtualSize + s.snapGrid[0]) newSlidesGrid.push(s.snapGrid[i]);
  725. }
  726. s.snapGrid = newSlidesGrid;
  727. }
  728. }
  729. // Remove last grid elements depending on width
  730. if (!s.params.centeredSlides) {
  731. newSlidesGrid = [];
  732. for (i = 0; i < s.snapGrid.length; i++) {
  733. if (s.snapGrid[i] <= s.virtualSize - s.size) {
  734. newSlidesGrid.push(s.snapGrid[i]);
  735. }
  736. }
  737. s.snapGrid = newSlidesGrid;
  738. if (Math.floor(s.virtualSize - s.size) > Math.floor(s.snapGrid[s.snapGrid.length - 1])) {
  739. s.snapGrid.push(s.virtualSize - s.size);
  740. }
  741. }
  742. if (s.snapGrid.length === 0) s.snapGrid = [0];
  743. if (s.params.spaceBetween !== 0) {
  744. if (s.isHorizontal()) {
  745. if (s.rtl) s.slides.css({marginLeft: spaceBetween + 'px'});
  746. else s.slides.css({marginRight: spaceBetween + 'px'});
  747. }
  748. else s.slides.css({marginBottom: spaceBetween + 'px'});
  749. }
  750. if (s.params.watchSlidesProgress) {
  751. s.updateSlidesOffset();
  752. }
  753. };
  754. s.updateSlidesOffset = function () {
  755. for (var i = 0; i < s.slides.length; i++) {
  756. s.slides[i].swiperSlideOffset = s.isHorizontal() ? s.slides[i].offsetLeft : s.slides[i].offsetTop;
  757. }
  758. };
  759. /*=========================
  760. Slider/slides progress
  761. ===========================*/
  762. s.updateSlidesProgress = function (translate) {
  763. if (typeof translate === 'undefined') {
  764. translate = s.translate || 0;
  765. }
  766. if (s.slides.length === 0) return;
  767. if (typeof s.slides[0].swiperSlideOffset === 'undefined') s.updateSlidesOffset();
  768. var offsetCenter = -translate;
  769. if (s.rtl) offsetCenter = translate;
  770. // Visible Slides
  771. s.slides.removeClass(s.params.slideVisibleClass);
  772. for (var i = 0; i < s.slides.length; i++) {
  773. var slide = s.slides[i];
  774. var slideProgress = (offsetCenter - slide.swiperSlideOffset) / (slide.swiperSlideSize + s.params.spaceBetween);
  775. if (s.params.watchSlidesVisibility) {
  776. var slideBefore = -(offsetCenter - slide.swiperSlideOffset);
  777. var slideAfter = slideBefore + s.slidesSizesGrid[i];
  778. var isVisible =
  779. (slideBefore >= 0 && slideBefore < s.size) ||
  780. (slideAfter > 0 && slideAfter <= s.size) ||
  781. (slideBefore <= 0 && slideAfter >= s.size);
  782. if (isVisible) {
  783. s.slides.eq(i).addClass(s.params.slideVisibleClass);
  784. }
  785. }
  786. slide.progress = s.rtl ? -slideProgress : slideProgress;
  787. }
  788. };
  789. s.updateProgress = function (translate) {
  790. if (typeof translate === 'undefined') {
  791. translate = s.translate || 0;
  792. }
  793. var translatesDiff = s.maxTranslate() - s.minTranslate();
  794. var wasBeginning = s.isBeginning;
  795. var wasEnd = s.isEnd;
  796. if (translatesDiff === 0) {
  797. s.progress = 0;
  798. s.isBeginning = s.isEnd = true;
  799. }
  800. else {
  801. s.progress = (translate - s.minTranslate()) / (translatesDiff);
  802. s.isBeginning = s.progress <= 0;
  803. s.isEnd = s.progress >= 1;
  804. }
  805. if (s.isBeginning && !wasBeginning) s.emit('onReachBeginning', s);
  806. if (s.isEnd && !wasEnd) s.emit('onReachEnd', s);
  807. if (s.params.watchSlidesProgress) s.updateSlidesProgress(translate);
  808. s.emit('onProgress', s, s.progress);
  809. };
  810. s.updateActiveIndex = function () {
  811. var translate = s.rtl ? s.translate : -s.translate;
  812. var newActiveIndex, i, snapIndex;
  813. for (i = 0; i < s.slidesGrid.length; i ++) {
  814. if (typeof s.slidesGrid[i + 1] !== 'undefined') {
  815. if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1] - (s.slidesGrid[i + 1] - s.slidesGrid[i]) / 2) {
  816. newActiveIndex = i;
  817. }
  818. else if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1]) {
  819. newActiveIndex = i + 1;
  820. }
  821. }
  822. else {
  823. if (translate >= s.slidesGrid[i]) {
  824. newActiveIndex = i;
  825. }
  826. }
  827. }
  828. // Normalize slideIndex
  829. if (newActiveIndex < 0 || typeof newActiveIndex === 'undefined') newActiveIndex = 0;
  830. // for (i = 0; i < s.slidesGrid.length; i++) {
  831. // if (- translate >= s.slidesGrid[i]) {
  832. // newActiveIndex = i;
  833. // }
  834. // }
  835. snapIndex = Math.floor(newActiveIndex / s.params.slidesPerGroup);
  836. if (snapIndex >= s.snapGrid.length) snapIndex = s.snapGrid.length - 1;
  837. if (newActiveIndex === s.activeIndex) {
  838. return;
  839. }
  840. s.snapIndex = snapIndex;
  841. s.previousIndex = s.activeIndex;
  842. s.activeIndex = newActiveIndex;
  843. s.updateClasses();
  844. };
  845. /*=========================
  846. Classes
  847. ===========================*/
  848. s.updateClasses = function () {
  849. s.slides.removeClass(s.params.slideActiveClass + ' ' + s.params.slideNextClass + ' ' + s.params.slidePrevClass);
  850. var activeSlide = s.slides.eq(s.activeIndex);
  851. // Active classes
  852. activeSlide.addClass(s.params.slideActiveClass);
  853. activeSlide.next('.' + s.params.slideClass).addClass(s.params.slideNextClass);
  854. activeSlide.prev('.' + s.params.slideClass).addClass(s.params.slidePrevClass);
  855. // Pagination
  856. if (s.paginationContainer && s.paginationContainer.length > 0) {
  857. // Current/Total
  858. var current,
  859. total = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  860. if (s.params.loop) {
  861. current = Math.ceil(s.activeIndex - s.loopedSlides)/s.params.slidesPerGroup;
  862. if (current > s.slides.length - 1 - s.loopedSlides * 2) {
  863. current = current - (s.slides.length - s.loopedSlides * 2);
  864. }
  865. if (current > total - 1) current = current - total;
  866. if (current < 0 && s.params.paginationType !== 'bullets') current = total + current;
  867. }
  868. else {
  869. if (typeof s.snapIndex !== 'undefined') {
  870. current = s.snapIndex;
  871. }
  872. else {
  873. current = s.activeIndex || 0;
  874. }
  875. }
  876. // Types
  877. if (s.params.paginationType === 'bullets' && s.bullets && s.bullets.length > 0) {
  878. s.bullets.removeClass(s.params.bulletActiveClass);
  879. if (s.paginationContainer.length > 1) {
  880. s.bullets.each(function () {
  881. if ($(this).index() === current) $(this).addClass(s.params.bulletActiveClass);
  882. });
  883. }
  884. else {
  885. s.bullets.eq(current).addClass(s.params.bulletActiveClass);
  886. }
  887. }
  888. if (s.params.paginationType === 'fraction') {
  889. s.paginationContainer.find('.' + s.params.paginationCurrentClass).text(current + 1);
  890. s.paginationContainer.find('.' + s.params.paginationTotalClass).text(total);
  891. }
  892. if (s.params.paginationType === 'progress') {
  893. var scale = (current + 1) / total,
  894. scaleX = scale,
  895. scaleY = 1;
  896. if (!s.isHorizontal()) {
  897. scaleY = scale;
  898. scaleX = 1;
  899. }
  900. s.paginationContainer.find('.' + s.params.paginationProgressbarClass).transform('translate3d(0,0,0) scaleX(' + scaleX + ') scaleY(' + scaleY + ')').transition(s.params.speed);
  901. }
  902. if (s.params.paginationType === 'custom' && s.params.paginationCustomRender) {
  903. s.paginationContainer.html(s.params.paginationCustomRender(s, current + 1, total));
  904. }
  905. }
  906. // Next/active buttons
  907. if (!s.params.loop) {
  908. if (s.params.prevButton) {
  909. if (s.isBeginning) {
  910. $(s.params.prevButton).addClass(s.params.buttonDisabledClass);
  911. if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.prevButton));
  912. }
  913. else {
  914. $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  915. if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.prevButton));
  916. }
  917. }
  918. if (s.params.nextButton) {
  919. if (s.isEnd) {
  920. $(s.params.nextButton).addClass(s.params.buttonDisabledClass);
  921. if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.nextButton));
  922. }
  923. else {
  924. $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  925. if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.nextButton));
  926. }
  927. }
  928. }
  929. };
  930. /*=========================
  931. Pagination
  932. ===========================*/
  933. s.updatePagination = function () {
  934. if (!s.params.pagination) return;
  935. if (s.paginationContainer && s.paginationContainer.length > 0) {
  936. var paginationHTML = '';
  937. if (s.params.paginationType === 'bullets') {
  938. var numberOfBullets = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
  939. for (var i = 0; i < numberOfBullets; i++) {
  940. if (s.params.paginationBulletRender) {
  941. paginationHTML += s.params.paginationBulletRender(i, s.params.bulletClass);
  942. }
  943. else {
  944. paginationHTML += '<' + s.params.paginationElement+' class="' + s.params.bulletClass + '"></' + s.params.paginationElement + '>';
  945. }
  946. }
  947. s.paginationContainer.html(paginationHTML);
  948. s.bullets = s.paginationContainer.find('.' + s.params.bulletClass);
  949. if (s.params.paginationClickable && s.params.a11y && s.a11y) {
  950. s.a11y.initPagination();
  951. }
  952. }
  953. if (s.params.paginationType === 'fraction') {
  954. if (s.params.paginationFractionRender) {
  955. paginationHTML = s.params.paginationFractionRender(s, s.params.paginationCurrentClass, s.params.paginationTotalClass);
  956. }
  957. else {
  958. paginationHTML =
  959. '<span class="' + s.params.paginationCurrentClass + '"></span>' +
  960. ' / ' +
  961. '<span class="' + s.params.paginationTotalClass+'"></span>';
  962. }
  963. s.paginationContainer.html(paginationHTML);
  964. }
  965. if (s.params.paginationType === 'progress') {
  966. if (s.params.paginationProgressRender) {
  967. paginationHTML = s.params.paginationProgressRender(s, s.params.paginationProgressbarClass);
  968. }
  969. else {
  970. paginationHTML = '<span class="' + s.params.paginationProgressbarClass + '"></span>';
  971. }
  972. s.paginationContainer.html(paginationHTML);
  973. }
  974. }
  975. };
  976. /*=========================
  977. Common update method
  978. ===========================*/
  979. s.update = function (updateTranslate) {
  980. s.updateContainerSize();
  981. s.updateSlidesSize();
  982. s.updateProgress();
  983. s.updatePagination();
  984. s.updateClasses();
  985. if (s.params.scrollbar && s.scrollbar) {
  986. s.scrollbar.set();
  987. }
  988. function forceSetTranslate() {
  989. newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  990. s.setWrapperTranslate(newTranslate);
  991. s.updateActiveIndex();
  992. s.updateClasses();
  993. }
  994. if (updateTranslate) {
  995. var translated, newTranslate;
  996. if (s.controller && s.controller.spline) {
  997. s.controller.spline = undefined;
  998. }
  999. if (s.params.freeMode) {
  1000. forceSetTranslate();
  1001. if (s.params.autoHeight) {
  1002. s.updateAutoHeight();
  1003. }
  1004. }
  1005. else {
  1006. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  1007. translated = s.slideTo(s.slides.length - 1, 0, false, true);
  1008. }
  1009. else {
  1010. translated = s.slideTo(s.activeIndex, 0, false, true);
  1011. }
  1012. if (!translated) {
  1013. forceSetTranslate();
  1014. }
  1015. }
  1016. }
  1017. else if (s.params.autoHeight) {
  1018. s.updateAutoHeight();
  1019. }
  1020. };
  1021. /*=========================
  1022. Resize Handler
  1023. ===========================*/
  1024. s.onResize = function (forceUpdatePagination) {
  1025. //Breakpoints
  1026. if (s.params.breakpoints) {
  1027. s.setBreakpoint();
  1028. }
  1029. // Disable locks on resize
  1030. var allowSwipeToPrev = s.params.allowSwipeToPrev;
  1031. var allowSwipeToNext = s.params.allowSwipeToNext;
  1032. s.params.allowSwipeToPrev = s.params.allowSwipeToNext = true;
  1033. s.updateContainerSize();
  1034. s.updateSlidesSize();
  1035. if (s.params.slidesPerView === 'auto' || s.params.freeMode || forceUpdatePagination) s.updatePagination();
  1036. if (s.params.scrollbar && s.scrollbar) {
  1037. s.scrollbar.set();
  1038. }
  1039. if (s.controller && s.controller.spline) {
  1040. s.controller.spline = undefined;
  1041. }
  1042. if (s.params.freeMode) {
  1043. var newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
  1044. s.setWrapperTranslate(newTranslate);
  1045. s.updateActiveIndex();
  1046. s.updateClasses();
  1047. if (s.params.autoHeight) {
  1048. s.updateAutoHeight();
  1049. }
  1050. }
  1051. else {
  1052. s.updateClasses();
  1053. if ((s.params.slidesPerView === 'auto' || s.params.slidesPerView > 1) && s.isEnd && !s.params.centeredSlides) {
  1054. s.slideTo(s.slides.length - 1, 0, false, true);
  1055. }
  1056. else {
  1057. s.slideTo(s.activeIndex, 0, false, true);
  1058. }
  1059. }
  1060. // Return locks after resize
  1061. s.params.allowSwipeToPrev = allowSwipeToPrev;
  1062. s.params.allowSwipeToNext = allowSwipeToNext;
  1063. };
  1064. /*=========================
  1065. Events
  1066. ===========================*/
  1067. //Define Touch Events
  1068. var desktopEvents = ['mousedown', 'mousemove', 'mouseup'];
  1069. if (window.navigator.pointerEnabled) desktopEvents = ['pointerdown', 'pointermove', 'pointerup'];
  1070. else if (window.navigator.msPointerEnabled) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp'];
  1071. s.touchEvents = {
  1072. start : s.support.touch || !s.params.simulateTouch ? 'touchstart' : desktopEvents[0],
  1073. move : s.support.touch || !s.params.simulateTouch ? 'touchmove' : desktopEvents[1],
  1074. end : s.support.touch || !s.params.simulateTouch ? 'touchend' : desktopEvents[2]
  1075. };
  1076. // WP8 Touch Events Fix
  1077. if (window.navigator.pointerEnabled || window.navigator.msPointerEnabled) {
  1078. (s.params.touchEventsTarget === 'container' ? s.container : s.wrapper).addClass('swiper-wp8-' + s.params.direction);
  1079. }
  1080. // Attach/detach events
  1081. s.initEvents = function (detach) {
  1082. var actionDom = detach ? 'off' : 'on';
  1083. var action = detach ? 'removeEventListener' : 'addEventListener';
  1084. var touchEventsTarget = s.params.touchEventsTarget === 'container' ? s.container[0] : s.wrapper[0];
  1085. var target = s.support.touch ? touchEventsTarget : document;
  1086. var moveCapture = s.params.nested ? true : false;
  1087. //Touch Events
  1088. if (s.browser.ie) {
  1089. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  1090. target[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  1091. target[action](s.touchEvents.end, s.onTouchEnd, false);
  1092. }
  1093. else {
  1094. if (s.support.touch) {
  1095. touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
  1096. touchEventsTarget[action](s.touchEvents.move, s.onTouchMove, moveCapture);
  1097. touchEventsTarget[action](s.touchEvents.end, s.onTouchEnd, false);
  1098. }
  1099. if (params.simulateTouch && !s.device.ios && !s.device.android) {
  1100. touchEventsTarget[action]('mousedown', s.onTouchStart, false);
  1101. document[action]('mousemove', s.onTouchMove, moveCapture);
  1102. document[action]('mouseup', s.onTouchEnd, false);
  1103. }
  1104. }
  1105. window[action]('resize', s.onResize);
  1106. // Next, Prev, Index
  1107. if (s.params.nextButton) {
  1108. $(s.params.nextButton)[actionDom]('click', s.onClickNext);
  1109. if (s.params.a11y && s.a11y) $(s.params.nextButton)[actionDom]('keydown', s.a11y.onEnterKey);
  1110. }
  1111. if (s.params.prevButton) {
  1112. $(s.params.prevButton)[actionDom]('click', s.onClickPrev);
  1113. if (s.params.a11y && s.a11y) $(s.params.prevButton)[actionDom]('keydown', s.a11y.onEnterKey);
  1114. }
  1115. if (s.params.pagination && s.params.paginationClickable) {
  1116. $(s.paginationContainer)[actionDom]('click', '.' + s.params.bulletClass, s.onClickIndex);
  1117. if (s.params.a11y && s.a11y) $(s.paginationContainer)[actionDom]('keydown', '.' + s.params.bulletClass, s.a11y.onEnterKey);
  1118. }
  1119. // Prevent Links Clicks
  1120. if (s.params.preventClicks || s.params.preventClicksPropagation) touchEventsTarget[action]('click', s.preventClicks, true);
  1121. };
  1122. s.attachEvents = function (detach) {
  1123. s.initEvents();
  1124. };
  1125. s.detachEvents = function () {
  1126. s.initEvents(true);
  1127. };
  1128. /*=========================
  1129. Handle Clicks
  1130. ===========================*/
  1131. // Prevent Clicks
  1132. s.allowClick = true;
  1133. s.preventClicks = function (e) {
  1134. if (!s.allowClick) {
  1135. if (s.params.preventClicks) e.preventDefault();
  1136. if (s.params.preventClicksPropagation && s.animating) {
  1137. e.stopPropagation();
  1138. e.stopImmediatePropagation();
  1139. }
  1140. }
  1141. };
  1142. // Clicks
  1143. s.onClickNext = function (e) {
  1144. e.preventDefault();
  1145. if (s.isEnd && !s.params.loop) return;
  1146. s.slideNext();
  1147. };
  1148. s.onClickPrev = function (e) {
  1149. e.preventDefault();
  1150. if (s.isBeginning && !s.params.loop) return;
  1151. s.slidePrev();
  1152. };
  1153. s.onClickIndex = function (e) {
  1154. e.preventDefault();
  1155. var index = $(this).index() * s.params.slidesPerGroup;
  1156. if (s.params.loop) index = index + s.loopedSlides;
  1157. s.slideTo(index);
  1158. };
  1159. /*=========================
  1160. Handle Touches
  1161. ===========================*/
  1162. function findElementInEvent(e, selector) {
  1163. var el = $(e.target);
  1164. if (!el.is(selector)) {
  1165. if (typeof selector === 'string') {
  1166. el = el.parents(selector);
  1167. }
  1168. else if (selector.nodeType) {
  1169. var found;
  1170. el.parents().each(function (index, _el) {
  1171. if (_el === selector) found = selector;
  1172. });
  1173. if (!found) return undefined;
  1174. else return selector;
  1175. }
  1176. }
  1177. if (el.length === 0) {
  1178. return undefined;
  1179. }
  1180. return el[0];
  1181. }
  1182. s.updateClickedSlide = function (e) {
  1183. var slide = findElementInEvent(e, '.' + s.params.slideClass);
  1184. var slideFound = false;
  1185. if (slide) {
  1186. for (var i = 0; i < s.slides.length; i++) {
  1187. if (s.slides[i] === slide) slideFound = true;
  1188. }
  1189. }
  1190. if (slide && slideFound) {
  1191. s.clickedSlide = slide;
  1192. s.clickedIndex = $(slide).index();
  1193. }
  1194. else {
  1195. s.clickedSlide = undefined;
  1196. s.clickedIndex = undefined;
  1197. return;
  1198. }
  1199. if (s.params.slideToClickedSlide && s.clickedIndex !== undefined && s.clickedIndex !== s.activeIndex) {
  1200. var slideToIndex = s.clickedIndex,
  1201. realIndex,
  1202. duplicatedSlides;
  1203. if (s.params.loop) {
  1204. if (s.animating) return;
  1205. realIndex = $(s.clickedSlide).attr('data-swiper-slide-index');
  1206. if (s.params.centeredSlides) {
  1207. if ((slideToIndex < s.loopedSlides - s.params.slidesPerView/2) || (slideToIndex > s.slides.length - s.loopedSlides + s.params.slidesPerView/2)) {
  1208. s.fixLoop();
  1209. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.swiper-slide-duplicate)').eq(0).index();
  1210. setTimeout(function () {
  1211. s.slideTo(slideToIndex);
  1212. }, 0);
  1213. }
  1214. else {
  1215. s.slideTo(slideToIndex);
  1216. }
  1217. }
  1218. else {
  1219. if (slideToIndex > s.slides.length - s.params.slidesPerView) {
  1220. s.fixLoop();
  1221. slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]:not(.swiper-slide-duplicate)').eq(0).index();
  1222. setTimeout(function () {
  1223. s.slideTo(slideToIndex);
  1224. }, 0);
  1225. }
  1226. else {
  1227. s.slideTo(slideToIndex);
  1228. }
  1229. }
  1230. }
  1231. else {
  1232. s.slideTo(slideToIndex);
  1233. }
  1234. }
  1235. };
  1236. var isTouched,
  1237. isMoved,
  1238. allowTouchCallbacks,
  1239. touchStartTime,
  1240. isScrolling,
  1241. currentTranslate,
  1242. startTranslate,
  1243. allowThresholdMove,
  1244. // Form elements to match
  1245. formElements = 'input, select, textarea, button',
  1246. // Last click time
  1247. lastClickTime = Date.now(), clickTimeout,
  1248. //Velocities
  1249. velocities = [],
  1250. allowMomentumBounce;
  1251. // Animating Flag
  1252. s.animating = false;
  1253. // Touches information
  1254. s.touches = {
  1255. startX: 0,
  1256. startY: 0,
  1257. currentX: 0,
  1258. currentY: 0,
  1259. diff: 0
  1260. };
  1261. // Touch handlers
  1262. var isTouchEvent, startMoving;
  1263. s.onTouchStart = function (e) {
  1264. if (e.originalEvent) e = e.originalEvent;
  1265. isTouchEvent = e.type === 'touchstart';
  1266. if (!isTouchEvent && 'which' in e && e.which === 3) return;
  1267. if (s.params.noSwiping && findElementInEvent(e, '.' + s.params.noSwipingClass)) {
  1268. s.allowClick = true;
  1269. return;
  1270. }
  1271. if (s.params.swipeHandler) {
  1272. if (!findElementInEvent(e, s.params.swipeHandler)) return;
  1273. }
  1274. var startX = s.touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
  1275. var startY = s.touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
  1276. // Do NOT start if iOS edge swipe is detected. Otherwise iOS app (UIWebView) cannot swipe-to-go-back anymore
  1277. if(s.device.ios && s.params.iOSEdgeSwipeDetection && startX <= s.params.iOSEdgeSwipeThreshold) {
  1278. return;
  1279. }
  1280. isTouched = true;
  1281. isMoved = false;
  1282. allowTouchCallbacks = true;
  1283. isScrolling = undefined;
  1284. startMoving = undefined;
  1285. s.touches.startX = startX;
  1286. s.touches.startY = startY;
  1287. touchStartTime = Date.now();
  1288. s.allowClick = true;
  1289. s.updateContainerSize();
  1290. s.swipeDirection = undefined;
  1291. if (s.params.threshold > 0) allowThresholdMove = false;
  1292. if (e.type !== 'touchstart') {
  1293. var preventDefault = true;
  1294. if ($(e.target).is(formElements)) preventDefault = false;
  1295. if (document.activeElement && $(document.activeElement).is(formElements)) {
  1296. document.activeElement.blur();
  1297. }
  1298. if (preventDefault) {
  1299. e.preventDefault();
  1300. }
  1301. }
  1302. s.emit('onTouchStart', s, e);
  1303. };
  1304. s.onTouchMove = function (e) {
  1305. if (e.originalEvent) e = e.originalEvent;
  1306. if (isTouchEvent && e.type === 'mousemove') return;
  1307. if (e.preventedByNestedSwiper) return;
  1308. if (s.params.onlyExternal) {
  1309. // isMoved = true;
  1310. s.allowClick = false;
  1311. if (isTouched) {
  1312. s.touches.startX = s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1313. s.touches.startY = s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1314. touchStartTime = Date.now();
  1315. }
  1316. return;
  1317. }
  1318. if (isTouchEvent && document.activeElement) {
  1319. if (e.target === document.activeElement && $(e.target).is(formElements)) {
  1320. isMoved = true;
  1321. s.allowClick = false;
  1322. return;
  1323. }
  1324. }
  1325. if (allowTouchCallbacks) {
  1326. s.emit('onTouchMove', s, e);
  1327. }
  1328. if (e.targetTouches && e.targetTouches.length > 1) return;
  1329. s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
  1330. s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
  1331. if (typeof isScrolling === 'undefined') {
  1332. var touchAngle = Math.atan2(Math.abs(s.touches.currentY - s.touches.startY), Math.abs(s.touches.currentX - s.touches.startX)) * 180 / Math.PI;
  1333. isScrolling = s.isHorizontal() ? touchAngle > s.params.touchAngle : (90 - touchAngle > s.params.touchAngle);
  1334. }
  1335. if (isScrolling) {
  1336. s.emit('onTouchMoveOpposite', s, e);
  1337. }
  1338. if (typeof startMoving === 'undefined' && s.browser.ieTouch) {
  1339. if (s.touches.currentX !== s.touches.startX || s.touches.currentY !== s.touches.startY) {
  1340. startMoving = true;
  1341. }
  1342. }
  1343. if (!isTouched) return;
  1344. if (isScrolling) {
  1345. isTouched = false;
  1346. return;
  1347. }
  1348. if (!startMoving && s.browser.ieTouch) {
  1349. return;
  1350. }
  1351. s.allowClick = false;
  1352. s.emit('onSliderMove', s, e);
  1353. e.preventDefault();
  1354. if (s.params.touchMoveStopPropagation && !s.params.nested) {
  1355. e.stopPropagation();
  1356. }
  1357. if (!isMoved) {
  1358. if (params.loop) {
  1359. s.fixLoop();
  1360. }
  1361. startTranslate = s.getWrapperTranslate();
  1362. s.setWrapperTransition(0);
  1363. if (s.animating) {
  1364. s.wrapper.trigger('webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd msTransitionEnd');
  1365. }
  1366. if (s.params.autoplay && s.autoplaying) {
  1367. if (s.params.autoplayDisableOnInteraction) {
  1368. s.stopAutoplay();
  1369. }
  1370. else {
  1371. s.pauseAutoplay();
  1372. }
  1373. }
  1374. allowMomentumBounce = false;
  1375. //Grab Cursor
  1376. if (s.params.grabCursor) {
  1377. s.container[0].style.cursor = 'move';
  1378. s.container[0].style.cursor = '-webkit-grabbing';
  1379. s.container[0].style.cursor = '-moz-grabbin';
  1380. s.container[0].style.cursor = 'grabbing';
  1381. }
  1382. }
  1383. isMoved = true;
  1384. var diff = s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1385. diff = diff * s.params.touchRatio;
  1386. if (s.rtl) diff = -diff;
  1387. s.swipeDirection = diff > 0 ? 'prev' : 'next';
  1388. currentTranslate = diff + startTranslate;
  1389. var disableParentSwiper = true;
  1390. if ((diff > 0 && currentTranslate > s.minTranslate())) {
  1391. disableParentSwiper = false;
  1392. if (s.params.resistance) currentTranslate = s.minTranslate() - 1 + Math.pow(-s.minTranslate() + startTranslate + diff, s.params.resistanceRatio);
  1393. }
  1394. else if (diff < 0 && currentTranslate < s.maxTranslate()) {
  1395. disableParentSwiper = false;
  1396. if (s.params.resistance) currentTranslate = s.maxTranslate() + 1 - Math.pow(s.maxTranslate() - startTranslate - diff, s.params.resistanceRatio);
  1397. }
  1398. if (disableParentSwiper) {
  1399. e.preventedByNestedSwiper = true;
  1400. }
  1401. // Directions locks
  1402. if (!s.params.allowSwipeToNext && s.swipeDirection === 'next' && currentTranslate < startTranslate) {
  1403. currentTranslate = startTranslate;
  1404. }
  1405. if (!s.params.allowSwipeToPrev && s.swipeDirection === 'prev' && currentTranslate > startTranslate) {
  1406. currentTranslate = startTranslate;
  1407. }
  1408. if (!s.params.followFinger) return;
  1409. // Threshold
  1410. if (s.params.threshold > 0) {
  1411. if (Math.abs(diff) > s.params.threshold || allowThresholdMove) {
  1412. if (!allowThresholdMove) {
  1413. allowThresholdMove = true;
  1414. s.touches.startX = s.touches.currentX;
  1415. s.touches.startY = s.touches.currentY;
  1416. currentTranslate = startTranslate;
  1417. s.touches.diff = s.isHorizontal() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
  1418. return;
  1419. }
  1420. }
  1421. else {
  1422. currentTranslate = startTranslate;
  1423. return;
  1424. }
  1425. }
  1426. // Update active index in free mode
  1427. if (s.params.freeMode || s.params.watchSlidesProgress) {
  1428. s.updateActiveIndex();
  1429. }
  1430. if (s.params.freeMode) {
  1431. //Velocity
  1432. if (velocities.length === 0) {
  1433. velocities.push({
  1434. position: s.touches[s.isHorizontal() ? 'startX' : 'startY'],
  1435. time: touchStartTime
  1436. });
  1437. }
  1438. velocities.push({
  1439. position: s.touches[s.isHorizontal() ? 'currentX' : 'currentY'],
  1440. time: (new window.Date()).getTime()
  1441. });
  1442. }
  1443. // Update progress
  1444. s.updateProgress(currentTranslate);
  1445. // Update translate
  1446. s.setWrapperTranslate(currentTranslate);
  1447. };
  1448. s.onTouchEnd = function (e) {
  1449. if (e.originalEvent) e = e.originalEvent;
  1450. if (allowTouchCallbacks) {
  1451. s.emit('onTouchEnd', s, e);
  1452. }
  1453. allowTouchCallbacks = false;
  1454. if (!isTouched) return;
  1455. //Return Grab Cursor
  1456. if (s.params.grabCursor && isMoved && isTouched) {
  1457. s.container[0].style.cursor = 'move';
  1458. s.container[0].style.cursor = '-webkit-grab';
  1459. s.container[0].style.cursor = '-moz-grab';
  1460. s.container[0].style.cursor = 'grab';
  1461. }
  1462. // Time diff
  1463. var touchEndTime = Date.now();
  1464. var timeDiff = touchEndTime - touchStartTime;
  1465. // Tap, doubleTap, Click
  1466. if (s.allowClick) {
  1467. s.updateClickedSlide(e);
  1468. s.emit('onTap', s, e);
  1469. if (timeDiff < 300 && (touchEndTime - lastClickTime) > 300) {
  1470. if (clickTimeout) clearTimeout(clickTimeout);
  1471. clickTimeout = setTimeout(function () {
  1472. if (!s) return;
  1473. if (s.params.paginationHide && s.paginationContainer.length > 0 && !$(e.target).hasClass(s.params.bulletClass)) {
  1474. s.paginationContainer.toggleClass(s.params.paginationHiddenClass);
  1475. }
  1476. s.emit('onClick', s, e);
  1477. }, 300);
  1478. }
  1479. if (timeDiff < 300 && (touchEndTime - lastClickTime) < 300) {
  1480. if (clickTimeout) clearTimeout(clickTimeout);
  1481. s.emit('onDoubleTap', s, e);
  1482. }
  1483. }
  1484. lastClickTime = Date.now();
  1485. setTimeout(function () {
  1486. if (s) s.allowClick = true;
  1487. }, 0);
  1488. if (!isTouched || !isMoved || !s.swipeDirection || s.touches.diff === 0 || currentTranslate === startTranslate) {
  1489. isTouched = isMoved = false;
  1490. return;
  1491. }
  1492. isTouched = isMoved = false;
  1493. var currentPos;
  1494. if (s.params.followFinger) {
  1495. currentPos = s.rtl ? s.translate : -s.translate;
  1496. }
  1497. else {
  1498. currentPos = -currentTranslate;
  1499. }
  1500. if (s.params.freeMode) {
  1501. if (currentPos < -s.minTranslate()) {
  1502. s.slideTo(s.activeIndex);
  1503. return;
  1504. }
  1505. else if (currentPos > -s.maxTranslate()) {
  1506. if (s.slides.length < s.snapGrid.length) {
  1507. s.slideTo(s.snapGrid.length - 1);
  1508. }
  1509. else {
  1510. s.slideTo(s.slides.length - 1);
  1511. }
  1512. return;
  1513. }
  1514. if (s.params.freeModeMomentum) {
  1515. if (velocities.length > 1) {
  1516. var lastMoveEvent = velocities.pop(), velocityEvent = velocities.pop();
  1517. var distance = lastMoveEvent.position - velocityEvent.position;
  1518. var time = lastMoveEvent.time - velocityEvent.time;
  1519. s.velocity = distance / time;
  1520. s.velocity = s.velocity / 2;
  1521. if (Math.abs(s.velocity) < s.params.freeModeMinimumVelocity) {
  1522. s.velocity = 0;
  1523. }
  1524. // this implies that the user stopped moving a finger then released.
  1525. // There would be no events with distance zero, so the last event is stale.
  1526. if (time > 150 || (new window.Date().getTime() - lastMoveEvent.time) > 300) {
  1527. s.velocity = 0;
  1528. }
  1529. } else {
  1530. s.velocity = 0;
  1531. }
  1532. velocities.length = 0;
  1533. var momentumDuration = 1000 * s.params.freeModeMomentumRatio;
  1534. var momentumDistance = s.velocity * momentumDuration;
  1535. var newPosition = s.translate + momentumDistance;
  1536. if (s.rtl) newPosition = - newPosition;
  1537. var doBounce = false;
  1538. var afterBouncePosition;
  1539. var bounceAmount = Math.abs(s.velocity) * 20 * s.params.freeModeMomentumBounceRatio;
  1540. if (newPosition < s.maxTranslate()) {
  1541. if (s.params.freeModeMomentumBounce) {
  1542. if (newPosition + s.maxTranslate() < -bounceAmount) {
  1543. newPosition = s.maxTranslate() - bounceAmount;
  1544. }
  1545. afterBouncePosition = s.maxTranslate();
  1546. doBounce = true;
  1547. allowMomentumBounce = true;
  1548. }
  1549. else {
  1550. newPosition = s.maxTranslate();
  1551. }
  1552. }
  1553. else if (newPosition > s.minTranslate()) {
  1554. if (s.params.freeModeMomentumBounce) {
  1555. if (newPosition - s.minTranslate() > bounceAmount) {
  1556. newPosition = s.minTranslate() + bounceAmount;
  1557. }
  1558. afterBouncePosition = s.minTranslate();
  1559. doBounce = true;
  1560. allowMomentumBounce = true;
  1561. }
  1562. else {
  1563. newPosition = s.minTranslate();
  1564. }
  1565. }
  1566. else if (s.params.freeModeSticky) {
  1567. var j = 0,
  1568. nextSlide;
  1569. for (j = 0; j < s.snapGrid.length; j += 1) {
  1570. if (s.snapGrid[j] > -newPosition) {
  1571. nextSlide = j;
  1572. break;
  1573. }
  1574. }
  1575. if (Math.abs(s.snapGrid[nextSlide] - newPosition) < Math.abs(s.snapGrid[nextSlide - 1] - newPosition) || s.swipeDirection === 'next') {
  1576. newPosition = s.snapGrid[nextSlide];
  1577. } else {
  1578. newPosition = s.snapGrid[nextSlide - 1];
  1579. }
  1580. if (!s.rtl) newPosition = - newPosition;
  1581. }
  1582. //Fix duration
  1583. if (s.velocity !== 0) {
  1584. if (s.rtl) {
  1585. momentumDuration = Math.abs((-newPosition - s.translate) / s.velocity);
  1586. }
  1587. else {
  1588. momentumDuration = Math.abs((newPosition - s.translate) / s.velocity);
  1589. }
  1590. }
  1591. else if (s.params.freeModeSticky) {
  1592. s.slideReset();
  1593. return;
  1594. }
  1595. if (s.params.freeModeMomentumBounce && doBounce) {
  1596. s.updateProgress(afterBouncePosition);
  1597. s.setWrapperTransition(momentumDuration);
  1598. s.setWrapperTranslate(newPosition);
  1599. s.onTransitionStart();
  1600. s.animating = true;
  1601. s.wrapper.transitionEnd(function () {
  1602. if (!s || !allowMomentumBounce) return;
  1603. s.emit('onMomentumBounce', s);
  1604. s.setWrapperTransition(s.params.speed);
  1605. s.setWrapperTranslate(afterBouncePosition);
  1606. s.wrapper.transitionEnd(function () {
  1607. if (!s) return;
  1608. s.onTransitionEnd();
  1609. });
  1610. });
  1611. } else if (s.velocity) {
  1612. s.updateProgress(newPosition);
  1613. s.setWrapperTransition(momentumDuration);
  1614. s.setWrapperTranslate(newPosition);
  1615. s.onTransitionStart();
  1616. if (!s.animating) {
  1617. s.animating = true;
  1618. s.wrapper.transitionEnd(function () {
  1619. if (!s) return;
  1620. s.onTransitionEnd();
  1621. });
  1622. }
  1623. } else {
  1624. s.updateProgress(newPosition);
  1625. }
  1626. s.updateActiveIndex();
  1627. }
  1628. if (!s.params.freeModeMomentum || timeDiff >= s.params.longSwipesMs) {
  1629. s.updateProgress();
  1630. s.updateActiveIndex();
  1631. }
  1632. return;
  1633. }
  1634. // Find current slide
  1635. var i, stopIndex = 0, groupSize = s.slidesSizesGrid[0];
  1636. for (i = 0; i < s.slidesGrid.length; i += s.params.slidesPerGroup) {
  1637. if (typeof s.slidesGrid[i + s.params.slidesPerGroup] !== 'undefined') {
  1638. if (currentPos >= s.slidesGrid[i] && currentPos < s.slidesGrid[i + s.params.slidesPerGroup]) {
  1639. stopIndex = i;
  1640. groupSize = s.slidesGrid[i + s.params.slidesPerGroup] - s.slidesGrid[i];
  1641. }
  1642. }
  1643. else {
  1644. if (currentPos >= s.slidesGrid[i]) {
  1645. stopIndex = i;
  1646. groupSize = s.slidesGrid[s.slidesGrid.length - 1] - s.slidesGrid[s.slidesGrid.length - 2];
  1647. }
  1648. }
  1649. }
  1650. // Find current slide size
  1651. var ratio = (currentPos - s.slidesGrid[stopIndex]) / groupSize;
  1652. if (timeDiff > s.params.longSwipesMs) {
  1653. // Long touches
  1654. if (!s.params.longSwipes) {
  1655. s.slideTo(s.activeIndex);
  1656. return;
  1657. }
  1658. if (s.swipeDirection === 'next') {
  1659. if (ratio >= s.params.longSwipesRatio) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1660. else s.slideTo(stopIndex);
  1661. }
  1662. if (s.swipeDirection === 'prev') {
  1663. if (ratio > (1 - s.params.longSwipesRatio)) s.slideTo(stopIndex + s.params.slidesPerGroup);
  1664. else s.slideTo(stopIndex);
  1665. }
  1666. }
  1667. else {
  1668. // Short swipes
  1669. if (!s.params.shortSwipes) {
  1670. s.slideTo(s.activeIndex);
  1671. return;
  1672. }
  1673. if (s.swipeDirection === 'next') {
  1674. s.slideTo(stopIndex + s.params.slidesPerGroup);
  1675. }
  1676. if (s.swipeDirection === 'prev') {
  1677. s.slideTo(stopIndex);
  1678. }
  1679. }
  1680. };
  1681. /*=========================
  1682. Transitions
  1683. ===========================*/
  1684. s._slideTo = function (slideIndex, speed) {
  1685. return s.slideTo(slideIndex, speed, true, true);
  1686. };
  1687. s.slideTo = function (slideIndex, speed, runCallbacks, internal) {
  1688. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1689. if (typeof slideIndex === 'undefined') slideIndex = 0;
  1690. if (slideIndex < 0) slideIndex = 0;
  1691. s.snapIndex = Math.floor(slideIndex / s.params.slidesPerGroup);
  1692. if (s.snapIndex >= s.snapGrid.length) s.snapIndex = s.snapGrid.length - 1;
  1693. var translate = - s.snapGrid[s.snapIndex];
  1694. // Stop autoplay
  1695. if (s.params.autoplay && s.autoplaying) {
  1696. if (internal || !s.params.autoplayDisableOnInteraction) {
  1697. s.pauseAutoplay(speed);
  1698. }
  1699. else {
  1700. s.stopAutoplay();
  1701. }
  1702. }
  1703. // Update progress
  1704. s.updateProgress(translate);
  1705. // Normalize slideIndex
  1706. for (var i = 0; i < s.slidesGrid.length; i++) {
  1707. if (- Math.floor(translate * 100) >= Math.floor(s.slidesGrid[i] * 100)) {
  1708. slideIndex = i;
  1709. }
  1710. }
  1711. // Directions locks
  1712. if (!s.params.allowSwipeToNext && translate < s.translate && translate < s.minTranslate()) {
  1713. return false;
  1714. }
  1715. if (!s.params.allowSwipeToPrev && translate > s.translate && translate > s.maxTranslate()) {
  1716. if ((s.activeIndex || 0) !== slideIndex ) return false;
  1717. }
  1718. // Update Index
  1719. if (typeof speed === 'undefined') speed = s.params.speed;
  1720. s.previousIndex = s.activeIndex || 0;
  1721. s.activeIndex = slideIndex;
  1722. if ((s.rtl && -translate === s.translate) || (!s.rtl && translate === s.translate)) {
  1723. // Update Height
  1724. if (s.params.autoHeight) {
  1725. s.updateAutoHeight();
  1726. }
  1727. s.updateClasses();
  1728. if (s.params.effect !== 'slide') {
  1729. s.setWrapperTranslate(translate);
  1730. }
  1731. return false;
  1732. }
  1733. s.updateClasses();
  1734. s.onTransitionStart(runCallbacks);
  1735. if (speed === 0) {
  1736. s.setWrapperTranslate(translate);
  1737. s.setWrapperTransition(0);
  1738. s.onTransitionEnd(runCallbacks);
  1739. }
  1740. else {
  1741. s.setWrapperTranslate(translate);
  1742. s.setWrapperTransition(speed);
  1743. if (!s.animating) {
  1744. s.animating = true;
  1745. s.wrapper.transitionEnd(function () {
  1746. if (!s) return;
  1747. s.onTransitionEnd(runCallbacks);
  1748. });
  1749. }
  1750. }
  1751. return true;
  1752. };
  1753. s.onTransitionStart = function (runCallbacks) {
  1754. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1755. if (s.params.autoHeight) {
  1756. s.updateAutoHeight();
  1757. }
  1758. if (s.lazy) s.lazy.onTransitionStart();
  1759. if (runCallbacks) {
  1760. s.emit('onTransitionStart', s);
  1761. if (s.activeIndex !== s.previousIndex) {
  1762. s.emit('onSlideChangeStart', s);
  1763. if (s.activeIndex > s.previousIndex) {
  1764. s.emit('onSlideNextStart', s);
  1765. }
  1766. else {
  1767. s.emit('onSlidePrevStart', s);
  1768. }
  1769. }
  1770. }
  1771. };
  1772. s.onTransitionEnd = function (runCallbacks) {
  1773. s.animating = false;
  1774. s.setWrapperTransition(0);
  1775. if (typeof runCallbacks === 'undefined') runCallbacks = true;
  1776. if (s.lazy) s.lazy.onTransitionEnd();
  1777. if (runCallbacks) {
  1778. s.emit('onTransitionEnd', s);
  1779. if (s.activeIndex !== s.previousIndex) {
  1780. s.emit('onSlideChangeEnd', s);
  1781. if (s.activeIndex > s.previousIndex) {
  1782. s.emit('onSlideNextEnd', s);
  1783. }
  1784. else {
  1785. s.emit('onSlidePrevEnd', s);
  1786. }
  1787. }
  1788. }
  1789. if (s.params.hashnav && s.hashnav) {
  1790. s.hashnav.setHash();
  1791. }
  1792. };
  1793. s.slideNext = function (runCallbacks, speed, internal) {
  1794. if (s.params.loop) {
  1795. if (s.animating) return false;
  1796. s.fixLoop();
  1797. var clientLeft = s.container[0].clientLeft;
  1798. return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  1799. }
  1800. else return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
  1801. };
  1802. s._slideNext = function (speed) {
  1803. return s.slideNext(true, speed, true);
  1804. };
  1805. s.slidePrev = function (runCallbacks, speed, internal) {
  1806. if (s.params.loop) {
  1807. if (s.animating) return false;
  1808. s.fixLoop();
  1809. var clientLeft = s.container[0].clientLeft;
  1810. return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  1811. }
  1812. else return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
  1813. };
  1814. s._slidePrev = function (speed) {
  1815. return s.slidePrev(true, speed, true);
  1816. };
  1817. s.slideReset = function (runCallbacks, speed, internal) {
  1818. return s.slideTo(s.activeIndex, speed, runCallbacks);
  1819. };
  1820. /*=========================
  1821. Translate/transition helpers
  1822. ===========================*/
  1823. s.setWrapperTransition = function (duration, byController) {
  1824. s.wrapper.transition(duration);
  1825. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  1826. s.effects[s.params.effect].setTransition(duration);
  1827. }
  1828. if (s.params.parallax && s.parallax) {
  1829. s.parallax.setTransition(duration);
  1830. }
  1831. if (s.params.scrollbar && s.scrollbar) {
  1832. s.scrollbar.setTransition(duration);
  1833. }
  1834. if (s.params.control && s.controller) {
  1835. s.controller.setTransition(duration, byController);
  1836. }
  1837. s.emit('onSetTransition', s, duration);
  1838. };
  1839. s.setWrapperTranslate = function (translate, updateActiveIndex, byController) {
  1840. var x = 0, y = 0, z = 0;
  1841. if (s.isHorizontal()) {
  1842. x = s.rtl ? -translate : translate;
  1843. }
  1844. else {
  1845. y = translate;
  1846. }
  1847. if (s.params.roundLengths) {
  1848. x = round(x);
  1849. y = round(y);
  1850. }
  1851. if (!s.params.virtualTranslate) {
  1852. if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)');
  1853. else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)');
  1854. }
  1855. s.translate = s.isHorizontal() ? x : y;
  1856. // Check if we need to update progress
  1857. var progress;
  1858. var translatesDiff = s.maxTranslate() - s.minTranslate();
  1859. if (translatesDiff === 0) {
  1860. progress = 0;
  1861. }
  1862. else {
  1863. progress = (translate - s.minTranslate()) / (translatesDiff);
  1864. }
  1865. if (progress !== s.progress) {
  1866. s.updateProgress(translate);
  1867. }
  1868. if (updateActiveIndex) s.updateActiveIndex();
  1869. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  1870. s.effects[s.params.effect].setTranslate(s.translate);
  1871. }
  1872. if (s.params.parallax && s.parallax) {
  1873. s.parallax.setTranslate(s.translate);
  1874. }
  1875. if (s.params.scrollbar && s.scrollbar) {
  1876. s.scrollbar.setTranslate(s.translate);
  1877. }
  1878. if (s.params.control && s.controller) {
  1879. s.controller.setTranslate(s.translate, byController);
  1880. }
  1881. s.emit('onSetTranslate', s, s.translate);
  1882. };
  1883. s.getTranslate = function (el, axis) {
  1884. var matrix, curTransform, curStyle, transformMatrix;
  1885. // automatic axis detection
  1886. if (typeof axis === 'undefined') {
  1887. axis = 'x';
  1888. }
  1889. if (s.params.virtualTranslate) {
  1890. return s.rtl ? -s.translate : s.translate;
  1891. }
  1892. curStyle = window.getComputedStyle(el, null);
  1893. if (window.WebKitCSSMatrix) {
  1894. curTransform = curStyle.transform || curStyle.webkitTransform;
  1895. if (curTransform.split(',').length > 6) {
  1896. curTransform = curTransform.split(', ').map(function(a){
  1897. return a.replace(',','.');
  1898. }).join(', ');
  1899. }
  1900. // Some old versions of Webkit choke when 'none' is passed; pass
  1901. // empty string instead in this case
  1902. transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
  1903. }
  1904. else {
  1905. transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
  1906. matrix = transformMatrix.toString().split(',');
  1907. }
  1908. if (axis === 'x') {
  1909. //Latest Chrome and webkits Fix
  1910. if (window.WebKitCSSMatrix)
  1911. curTransform = transformMatrix.m41;
  1912. //Crazy IE10 Matrix
  1913. else if (matrix.length === 16)
  1914. curTransform = parseFloat(matrix[12]);
  1915. //Normal Browsers
  1916. else
  1917. curTransform = parseFloat(matrix[4]);
  1918. }
  1919. if (axis === 'y') {
  1920. //Latest Chrome and webkits Fix
  1921. if (window.WebKitCSSMatrix)
  1922. curTransform = transformMatrix.m42;
  1923. //Crazy IE10 Matrix
  1924. else if (matrix.length === 16)
  1925. curTransform = parseFloat(matrix[13]);
  1926. //Normal Browsers
  1927. else
  1928. curTransform = parseFloat(matrix[5]);
  1929. }
  1930. if (s.rtl && curTransform) curTransform = -curTransform;
  1931. return curTransform || 0;
  1932. };
  1933. s.getWrapperTranslate = function (axis) {
  1934. if (typeof axis === 'undefined') {
  1935. axis = s.isHorizontal() ? 'x' : 'y';
  1936. }
  1937. return s.getTranslate(s.wrapper[0], axis);
  1938. };
  1939. /*=========================
  1940. Observer
  1941. ===========================*/
  1942. s.observers = [];
  1943. function initObserver(target, options) {
  1944. options = options || {};
  1945. // create an observer instance
  1946. var ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
  1947. var observer = new ObserverFunc(function (mutations) {
  1948. mutations.forEach(function (mutation) {
  1949. s.onResize(true);
  1950. s.emit('onObserverUpdate', s, mutation);
  1951. });
  1952. });
  1953. observer.observe(target, {
  1954. attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
  1955. childList: typeof options.childList === 'undefined' ? true : options.childList,
  1956. characterData: typeof options.characterData === 'undefined' ? true : options.characterData
  1957. });
  1958. s.observers.push(observer);
  1959. }
  1960. s.initObservers = function () {
  1961. if (s.params.observeParents) {
  1962. var containerParents = s.container.parents();
  1963. for (var i = 0; i < containerParents.length; i++) {
  1964. initObserver(containerParents[i]);
  1965. }
  1966. }
  1967. // Observe container
  1968. initObserver(s.container[0], {childList: false});
  1969. // Observe wrapper
  1970. initObserver(s.wrapper[0], {attributes: false});
  1971. };
  1972. s.disconnectObservers = function () {
  1973. for (var i = 0; i < s.observers.length; i++) {
  1974. s.observers[i].disconnect();
  1975. }
  1976. s.observers = [];
  1977. };
  1978. /*=========================
  1979. Loop
  1980. ===========================*/
  1981. // Create looped slides
  1982. s.createLoop = function () {
  1983. // Remove duplicated slides
  1984. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  1985. var slides = s.wrapper.children('.' + s.params.slideClass);
  1986. if(s.params.slidesPerView === 'auto' && !s.params.loopedSlides) s.params.loopedSlides = slides.length;
  1987. s.loopedSlides = parseInt(s.params.loopedSlides || s.params.slidesPerView, 10);
  1988. s.loopedSlides = s.loopedSlides + s.params.loopAdditionalSlides;
  1989. if (s.loopedSlides > slides.length) {
  1990. s.loopedSlides = slides.length;
  1991. }
  1992. var prependSlides = [], appendSlides = [], i;
  1993. slides.each(function (index, el) {
  1994. var slide = $(this);
  1995. if (index < s.loopedSlides) appendSlides.push(el);
  1996. if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el);
  1997. slide.attr('data-swiper-slide-index', index);
  1998. });
  1999. for (i = 0; i < appendSlides.length; i++) {
  2000. s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  2001. }
  2002. for (i = prependSlides.length - 1; i >= 0; i--) {
  2003. s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
  2004. }
  2005. };
  2006. s.destroyLoop = function () {
  2007. s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
  2008. s.slides.removeAttr('data-swiper-slide-index');
  2009. };
  2010. s.fixLoop = function () {
  2011. var newIndex;
  2012. //Fix For Negative Oversliding
  2013. if (s.activeIndex < s.loopedSlides) {
  2014. newIndex = s.slides.length - s.loopedSlides * 3 + s.activeIndex;
  2015. newIndex = newIndex + s.loopedSlides;
  2016. s.slideTo(newIndex, 0, false, true);
  2017. }
  2018. //Fix For Positive Oversliding
  2019. else if ((s.params.slidesPerView === 'auto' && s.activeIndex >= s.loopedSlides * 2) || (s.activeIndex > s.slides.length - s.params.slidesPerView * 2)) {
  2020. newIndex = -s.slides.length + s.activeIndex + s.loopedSlides;
  2021. newIndex = newIndex + s.loopedSlides;
  2022. s.slideTo(newIndex, 0, false, true);
  2023. }
  2024. };
  2025. /*=========================
  2026. Append/Prepend/Remove Slides
  2027. ===========================*/
  2028. s.appendSlide = function (slides) {
  2029. if (s.params.loop) {
  2030. s.destroyLoop();
  2031. }
  2032. if (typeof slides === 'object' && slides.length) {
  2033. for (var i = 0; i < slides.length; i++) {
  2034. if (slides[i]) s.wrapper.append(slides[i]);
  2035. }
  2036. }
  2037. else {
  2038. s.wrapper.append(slides);
  2039. }
  2040. if (s.params.loop) {
  2041. s.createLoop();
  2042. }
  2043. if (!(s.params.observer && s.support.observer)) {
  2044. s.update(true);
  2045. }
  2046. };
  2047. s.prependSlide = function (slides) {
  2048. if (s.params.loop) {
  2049. s.destroyLoop();
  2050. }
  2051. var newActiveIndex = s.activeIndex + 1;
  2052. if (typeof slides === 'object' && slides.length) {
  2053. for (var i = 0; i < slides.length; i++) {
  2054. if (slides[i]) s.wrapper.prepend(slides[i]);
  2055. }
  2056. newActiveIndex = s.activeIndex + slides.length;
  2057. }
  2058. else {
  2059. s.wrapper.prepend(slides);
  2060. }
  2061. if (s.params.loop) {
  2062. s.createLoop();
  2063. }
  2064. if (!(s.params.observer && s.support.observer)) {
  2065. s.update(true);
  2066. }
  2067. s.slideTo(newActiveIndex, 0, false);
  2068. };
  2069. s.removeSlide = function (slidesIndexes) {
  2070. if (s.params.loop) {
  2071. s.destroyLoop();
  2072. s.slides = s.wrapper.children('.' + s.params.slideClass);
  2073. }
  2074. var newActiveIndex = s.activeIndex,
  2075. indexToRemove;
  2076. if (typeof slidesIndexes === 'object' && slidesIndexes.length) {
  2077. for (var i = 0; i < slidesIndexes.length; i++) {
  2078. indexToRemove = slidesIndexes[i];
  2079. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  2080. if (indexToRemove < newActiveIndex) newActiveIndex--;
  2081. }
  2082. newActiveIndex = Math.max(newActiveIndex, 0);
  2083. }
  2084. else {
  2085. indexToRemove = slidesIndexes;
  2086. if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
  2087. if (indexToRemove < newActiveIndex) newActiveIndex--;
  2088. newActiveIndex = Math.max(newActiveIndex, 0);
  2089. }
  2090. if (s.params.loop) {
  2091. s.createLoop();
  2092. }
  2093. if (!(s.params.observer && s.support.observer)) {
  2094. s.update(true);
  2095. }
  2096. if (s.params.loop) {
  2097. s.slideTo(newActiveIndex + s.loopedSlides, 0, false);
  2098. }
  2099. else {
  2100. s.slideTo(newActiveIndex, 0, false);
  2101. }
  2102. };
  2103. s.removeAllSlides = function () {
  2104. var slidesIndexes = [];
  2105. for (var i = 0; i < s.slides.length; i++) {
  2106. slidesIndexes.push(i);
  2107. }
  2108. s.removeSlide(slidesIndexes);
  2109. };
  2110. /*=========================
  2111. Effects
  2112. ===========================*/
  2113. s.effects = {
  2114. fade: {
  2115. setTranslate: function () {
  2116. for (var i = 0; i < s.slides.length; i++) {
  2117. var slide = s.slides.eq(i);
  2118. var offset = slide[0].swiperSlideOffset;
  2119. var tx = -offset;
  2120. if (!s.params.virtualTranslate) tx = tx - s.translate;
  2121. var ty = 0;
  2122. if (!s.isHorizontal()) {
  2123. ty = tx;
  2124. tx = 0;
  2125. }
  2126. var slideOpacity = s.params.fade.crossFade ?
  2127. Math.max(1 - Math.abs(slide[0].progress), 0) :
  2128. 1 + Math.min(Math.max(slide[0].progress, -1), 0);
  2129. slide
  2130. .css({
  2131. opacity: slideOpacity
  2132. })
  2133. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px)');
  2134. }
  2135. },
  2136. setTransition: function (duration) {
  2137. s.slides.transition(duration);
  2138. if (s.params.virtualTranslate && duration !== 0) {
  2139. var eventTriggered = false;
  2140. s.slides.transitionEnd(function () {
  2141. if (eventTriggered) return;
  2142. if (!s) return;
  2143. eventTriggered = true;
  2144. s.animating = false;
  2145. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  2146. for (var i = 0; i < triggerEvents.length; i++) {
  2147. s.wrapper.trigger(triggerEvents[i]);
  2148. }
  2149. });
  2150. }
  2151. }
  2152. },
  2153. flip: {
  2154. setTranslate: function () {
  2155. for (var i = 0; i < s.slides.length; i++) {
  2156. var slide = s.slides.eq(i);
  2157. var progress = slide[0].progress;
  2158. if (s.params.flip.limitRotation) {
  2159. progress = Math.max(Math.min(slide[0].progress, 1), -1);
  2160. }
  2161. var offset = slide[0].swiperSlideOffset;
  2162. var rotate = -180 * progress,
  2163. rotateY = rotate,
  2164. rotateX = 0,
  2165. tx = -offset,
  2166. ty = 0;
  2167. if (!s.isHorizontal()) {
  2168. ty = tx;
  2169. tx = 0;
  2170. rotateX = -rotateY;
  2171. rotateY = 0;
  2172. }
  2173. else if (s.rtl) {
  2174. rotateY = -rotateY;
  2175. }
  2176. slide[0].style.zIndex = -Math.abs(Math.round(progress)) + s.slides.length;
  2177. if (s.params.flip.slideShadows) {
  2178. //Set shadows
  2179. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2180. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2181. if (shadowBefore.length === 0) {
  2182. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2183. slide.append(shadowBefore);
  2184. }
  2185. if (shadowAfter.length === 0) {
  2186. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2187. slide.append(shadowAfter);
  2188. }
  2189. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  2190. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  2191. }
  2192. slide
  2193. .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)');
  2194. }
  2195. },
  2196. setTransition: function (duration) {
  2197. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2198. if (s.params.virtualTranslate && duration !== 0) {
  2199. var eventTriggered = false;
  2200. s.slides.eq(s.activeIndex).transitionEnd(function () {
  2201. if (eventTriggered) return;
  2202. if (!s) return;
  2203. if (!$(this).hasClass(s.params.slideActiveClass)) return;
  2204. eventTriggered = true;
  2205. s.animating = false;
  2206. var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
  2207. for (var i = 0; i < triggerEvents.length; i++) {
  2208. s.wrapper.trigger(triggerEvents[i]);
  2209. }
  2210. });
  2211. }
  2212. }
  2213. },
  2214. cube: {
  2215. setTranslate: function () {
  2216. var wrapperRotate = 0, cubeShadow;
  2217. if (s.params.cube.shadow) {
  2218. if (s.isHorizontal()) {
  2219. cubeShadow = s.wrapper.find('.swiper-cube-shadow');
  2220. if (cubeShadow.length === 0) {
  2221. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  2222. s.wrapper.append(cubeShadow);
  2223. }
  2224. cubeShadow.css({height: s.width + 'px'});
  2225. }
  2226. else {
  2227. cubeShadow = s.container.find('.swiper-cube-shadow');
  2228. if (cubeShadow.length === 0) {
  2229. cubeShadow = $('<div class="swiper-cube-shadow"></div>');
  2230. s.container.append(cubeShadow);
  2231. }
  2232. }
  2233. }
  2234. for (var i = 0; i < s.slides.length; i++) {
  2235. var slide = s.slides.eq(i);
  2236. var slideAngle = i * 90;
  2237. var round = Math.floor(slideAngle / 360);
  2238. if (s.rtl) {
  2239. slideAngle = -slideAngle;
  2240. round = Math.floor(-slideAngle / 360);
  2241. }
  2242. var progress = Math.max(Math.min(slide[0].progress, 1), -1);
  2243. var tx = 0, ty = 0, tz = 0;
  2244. if (i % 4 === 0) {
  2245. tx = - round * 4 * s.size;
  2246. tz = 0;
  2247. }
  2248. else if ((i - 1) % 4 === 0) {
  2249. tx = 0;
  2250. tz = - round * 4 * s.size;
  2251. }
  2252. else if ((i - 2) % 4 === 0) {
  2253. tx = s.size + round * 4 * s.size;
  2254. tz = s.size;
  2255. }
  2256. else if ((i - 3) % 4 === 0) {
  2257. tx = - s.size;
  2258. tz = 3 * s.size + s.size * 4 * round;
  2259. }
  2260. if (s.rtl) {
  2261. tx = -tx;
  2262. }
  2263. if (!s.isHorizontal()) {
  2264. ty = tx;
  2265. tx = 0;
  2266. }
  2267. var transform = 'rotateX(' + (s.isHorizontal() ? 0 : -slideAngle) + 'deg) rotateY(' + (s.isHorizontal() ? slideAngle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)';
  2268. if (progress <= 1 && progress > -1) {
  2269. wrapperRotate = i * 90 + progress * 90;
  2270. if (s.rtl) wrapperRotate = -i * 90 - progress * 90;
  2271. }
  2272. slide.transform(transform);
  2273. if (s.params.cube.slideShadows) {
  2274. //Set shadows
  2275. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2276. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2277. if (shadowBefore.length === 0) {
  2278. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2279. slide.append(shadowBefore);
  2280. }
  2281. if (shadowAfter.length === 0) {
  2282. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2283. slide.append(shadowAfter);
  2284. }
  2285. if (shadowBefore.length) shadowBefore[0].style.opacity = Math.max(-progress, 0);
  2286. if (shadowAfter.length) shadowAfter[0].style.opacity = Math.max(progress, 0);
  2287. }
  2288. }
  2289. s.wrapper.css({
  2290. '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2291. '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2292. '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
  2293. 'transform-origin': '50% 50% -' + (s.size / 2) + 'px'
  2294. });
  2295. if (s.params.cube.shadow) {
  2296. if (s.isHorizontal()) {
  2297. 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) + ')');
  2298. }
  2299. else {
  2300. var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
  2301. var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
  2302. var scale1 = s.params.cube.shadowScale,
  2303. scale2 = s.params.cube.shadowScale / multiplier,
  2304. offset = s.params.cube.shadowOffset;
  2305. cubeShadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotateX(-90deg)');
  2306. }
  2307. }
  2308. var zFactor = (s.isSafari || s.isUiWebView) ? (-s.size / 2) : 0;
  2309. s.wrapper.transform('translate3d(0px,0,' + zFactor + 'px) rotateX(' + (s.isHorizontal() ? 0 : wrapperRotate) + 'deg) rotateY(' + (s.isHorizontal() ? -wrapperRotate : 0) + 'deg)');
  2310. },
  2311. setTransition: function (duration) {
  2312. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2313. if (s.params.cube.shadow && !s.isHorizontal()) {
  2314. s.container.find('.swiper-cube-shadow').transition(duration);
  2315. }
  2316. }
  2317. },
  2318. coverflow: {
  2319. setTranslate: function () {
  2320. var transform = s.translate;
  2321. var center = s.isHorizontal() ? -transform + s.width / 2 : -transform + s.height / 2;
  2322. var rotate = s.isHorizontal() ? s.params.coverflow.rotate: -s.params.coverflow.rotate;
  2323. var translate = s.params.coverflow.depth;
  2324. //Each slide offset from center
  2325. for (var i = 0, length = s.slides.length; i < length; i++) {
  2326. var slide = s.slides.eq(i);
  2327. var slideSize = s.slidesSizesGrid[i];
  2328. var slideOffset = slide[0].swiperSlideOffset;
  2329. var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier;
  2330. var rotateY = s.isHorizontal() ? rotate * offsetMultiplier : 0;
  2331. var rotateX = s.isHorizontal() ? 0 : rotate * offsetMultiplier;
  2332. // var rotateZ = 0
  2333. var translateZ = -translate * Math.abs(offsetMultiplier);
  2334. var translateY = s.isHorizontal() ? 0 : s.params.coverflow.stretch * (offsetMultiplier);
  2335. var translateX = s.isHorizontal() ? s.params.coverflow.stretch * (offsetMultiplier) : 0;
  2336. //Fix for ultra small values
  2337. if (Math.abs(translateX) < 0.001) translateX = 0;
  2338. if (Math.abs(translateY) < 0.001) translateY = 0;
  2339. if (Math.abs(translateZ) < 0.001) translateZ = 0;
  2340. if (Math.abs(rotateY) < 0.001) rotateY = 0;
  2341. if (Math.abs(rotateX) < 0.001) rotateX = 0;
  2342. var slideTransform = 'translate3d(' + translateX + 'px,' + translateY + 'px,' + translateZ + 'px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)';
  2343. slide.transform(slideTransform);
  2344. slide[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
  2345. if (s.params.coverflow.slideShadows) {
  2346. //Set shadows
  2347. var shadowBefore = s.isHorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
  2348. var shadowAfter = s.isHorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
  2349. if (shadowBefore.length === 0) {
  2350. shadowBefore = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'left' : 'top') + '"></div>');
  2351. slide.append(shadowBefore);
  2352. }
  2353. if (shadowAfter.length === 0) {
  2354. shadowAfter = $('<div class="swiper-slide-shadow-' + (s.isHorizontal() ? 'right' : 'bottom') + '"></div>');
  2355. slide.append(shadowAfter);
  2356. }
  2357. if (shadowBefore.length) shadowBefore[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
  2358. if (shadowAfter.length) shadowAfter[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0;
  2359. }
  2360. }
  2361. //Set correct perspective for IE10
  2362. if (s.browser.ie) {
  2363. var ws = s.wrapper[0].style;
  2364. ws.perspectiveOrigin = center + 'px 50%';
  2365. }
  2366. },
  2367. setTransition: function (duration) {
  2368. s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
  2369. }
  2370. }
  2371. };
  2372. /*=========================
  2373. Images Lazy Loading
  2374. ===========================*/
  2375. s.lazy = {
  2376. initialImageLoaded: false,
  2377. loadImageInSlide: function (index, loadInDuplicate) {
  2378. if (typeof index === 'undefined') return;
  2379. if (typeof loadInDuplicate === 'undefined') loadInDuplicate = true;
  2380. if (s.slides.length === 0) return;
  2381. var slide = s.slides.eq(index);
  2382. var img = slide.find('.swiper-lazy:not(.swiper-lazy-loaded):not(.swiper-lazy-loading)');
  2383. if (slide.hasClass('swiper-lazy') && !slide.hasClass('swiper-lazy-loaded') && !slide.hasClass('swiper-lazy-loading')) {
  2384. img = img.add(slide[0]);
  2385. }
  2386. if (img.length === 0) return;
  2387. img.each(function () {
  2388. var _img = $(this);
  2389. _img.addClass('swiper-lazy-loading');
  2390. var background = _img.attr('data-background');
  2391. var src = _img.attr('data-src'),
  2392. srcset = _img.attr('data-srcset');
  2393. s.loadImage(_img[0], (src || background), srcset, false, function () {
  2394. if (background) {
  2395. _img.css('background-image', 'url(' + background + ')');
  2396. _img.removeAttr('data-background');
  2397. }
  2398. else {
  2399. if (srcset) {
  2400. _img.attr('srcset', srcset);
  2401. _img.removeAttr('data-srcset');
  2402. }
  2403. if (src) {
  2404. _img.attr('src', src);
  2405. _img.removeAttr('data-src');
  2406. }
  2407. }
  2408. _img.addClass('swiper-lazy-loaded').removeClass('swiper-lazy-loading');
  2409. slide.find('.swiper-lazy-preloader, .preloader').remove();
  2410. if (s.params.loop && loadInDuplicate) {
  2411. var slideOriginalIndex = slide.attr('data-swiper-slide-index');
  2412. if (slide.hasClass(s.params.slideDuplicateClass)) {
  2413. var originalSlide = s.wrapper.children('[data-swiper-slide-index="' + slideOriginalIndex + '"]:not(.' + s.params.slideDuplicateClass + ')');
  2414. s.lazy.loadImageInSlide(originalSlide.index(), false);
  2415. }
  2416. else {
  2417. var duplicatedSlide = s.wrapper.children('.' + s.params.slideDuplicateClass + '[data-swiper-slide-index="' + slideOriginalIndex + '"]');
  2418. s.lazy.loadImageInSlide(duplicatedSlide.index(), false);
  2419. }
  2420. }
  2421. s.emit('onLazyImageReady', s, slide[0], _img[0]);
  2422. });
  2423. s.emit('onLazyImageLoad', s, slide[0], _img[0]);
  2424. });
  2425. },
  2426. load: function () {
  2427. var i;
  2428. if (s.params.watchSlidesVisibility) {
  2429. s.wrapper.children('.' + s.params.slideVisibleClass).each(function () {
  2430. s.lazy.loadImageInSlide($(this).index());
  2431. });
  2432. }
  2433. else {
  2434. if (s.params.slidesPerView > 1) {
  2435. for (i = s.activeIndex; i < s.activeIndex + s.params.slidesPerView ; i++) {
  2436. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2437. }
  2438. }
  2439. else {
  2440. s.lazy.loadImageInSlide(s.activeIndex);
  2441. }
  2442. }
  2443. if (s.params.lazyLoadingInPrevNext) {
  2444. if (s.params.slidesPerView > 1 || (s.params.lazyLoadingInPrevNextAmount && s.params.lazyLoadingInPrevNextAmount > 1)) {
  2445. var amount = s.params.lazyLoadingInPrevNextAmount;
  2446. var spv = s.params.slidesPerView;
  2447. var maxIndex = Math.min(s.activeIndex + spv + Math.max(amount, spv), s.slides.length);
  2448. var minIndex = Math.max(s.activeIndex - Math.max(spv, amount), 0);
  2449. // Next Slides
  2450. for (i = s.activeIndex + s.params.slidesPerView; i < maxIndex; i++) {
  2451. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2452. }
  2453. // Prev Slides
  2454. for (i = minIndex; i < s.activeIndex ; i++) {
  2455. if (s.slides[i]) s.lazy.loadImageInSlide(i);
  2456. }
  2457. }
  2458. else {
  2459. var nextSlide = s.wrapper.children('.' + s.params.slideNextClass);
  2460. if (nextSlide.length > 0) s.lazy.loadImageInSlide(nextSlide.index());
  2461. var prevSlide = s.wrapper.children('.' + s.params.slidePrevClass);
  2462. if (prevSlide.length > 0) s.lazy.loadImageInSlide(prevSlide.index());
  2463. }
  2464. }
  2465. },
  2466. onTransitionStart: function () {
  2467. if (s.params.lazyLoading) {
  2468. if (s.params.lazyLoadingOnTransitionStart || (!s.params.lazyLoadingOnTransitionStart && !s.lazy.initialImageLoaded)) {
  2469. s.lazy.load();
  2470. }
  2471. }
  2472. },
  2473. onTransitionEnd: function () {
  2474. if (s.params.lazyLoading && !s.params.lazyLoadingOnTransitionStart) {
  2475. s.lazy.load();
  2476. }
  2477. }
  2478. };
  2479. /*=========================
  2480. Scrollbar
  2481. ===========================*/
  2482. s.scrollbar = {
  2483. isTouched: false,
  2484. setDragPosition: function (e) {
  2485. var sb = s.scrollbar;
  2486. var x = 0, y = 0;
  2487. var translate;
  2488. var pointerPosition = s.isHorizontal() ?
  2489. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageX : e.pageX || e.clientX) :
  2490. ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targetTouches[0].pageY : e.pageY || e.clientY) ;
  2491. var position = (pointerPosition) - sb.track.offset()[s.isHorizontal() ? 'left' : 'top'] - sb.dragSize / 2;
  2492. var positionMin = -s.minTranslate() * sb.moveDivider;
  2493. var positionMax = -s.maxTranslate() * sb.moveDivider;
  2494. if (position < positionMin) {
  2495. position = positionMin;
  2496. }
  2497. else if (position > positionMax) {
  2498. position = positionMax;
  2499. }
  2500. position = -position / sb.moveDivider;
  2501. s.updateProgress(position);
  2502. s.setWrapperTranslate(position, true);
  2503. },
  2504. dragStart: function (e) {
  2505. var sb = s.scrollbar;
  2506. sb.isTouched = true;
  2507. e.preventDefault();
  2508. e.stopPropagation();
  2509. sb.setDragPosition(e);
  2510. clearTimeout(sb.dragTimeout);
  2511. sb.track.transition(0);
  2512. if (s.params.scrollbarHide) {
  2513. sb.track.css('opacity', 1);
  2514. }
  2515. s.wrapper.transition(100);
  2516. sb.drag.transition(100);
  2517. s.emit('onScrollbarDragStart', s);
  2518. },
  2519. dragMove: function (e) {
  2520. var sb = s.scrollbar;
  2521. if (!sb.isTouched) return;
  2522. if (e.preventDefault) e.preventDefault();
  2523. else e.returnValue = false;
  2524. sb.setDragPosition(e);
  2525. s.wrapper.transition(0);
  2526. sb.track.transition(0);
  2527. sb.drag.transition(0);
  2528. s.emit('onScrollbarDragMove', s);
  2529. },
  2530. dragEnd: function (e) {
  2531. var sb = s.scrollbar;
  2532. if (!sb.isTouched) return;
  2533. sb.isTouched = false;
  2534. if (s.params.scrollbarHide) {
  2535. clearTimeout(sb.dragTimeout);
  2536. sb.dragTimeout = setTimeout(function () {
  2537. sb.track.css('opacity', 0);
  2538. sb.track.transition(400);
  2539. }, 1000);
  2540. }
  2541. s.emit('onScrollbarDragEnd', s);
  2542. if (s.params.scrollbarSnapOnRelease) {
  2543. s.slideReset();
  2544. }
  2545. },
  2546. enableDraggable: function () {
  2547. var sb = s.scrollbar;
  2548. var target = s.support.touch ? sb.track : document;
  2549. $(sb.track).on(s.touchEvents.start, sb.dragStart);
  2550. $(target).on(s.touchEvents.move, sb.dragMove);
  2551. $(target).on(s.touchEvents.end, sb.dragEnd);
  2552. },
  2553. disableDraggable: function () {
  2554. var sb = s.scrollbar;
  2555. var target = s.support.touch ? sb.track : document;
  2556. $(sb.track).off(s.touchEvents.start, sb.dragStart);
  2557. $(target).off(s.touchEvents.move, sb.dragMove);
  2558. $(target).off(s.touchEvents.end, sb.dragEnd);
  2559. },
  2560. set: function () {
  2561. if (!s.params.scrollbar) return;
  2562. var sb = s.scrollbar;
  2563. sb.track = $(s.params.scrollbar);
  2564. sb.drag = sb.track.find('.swiper-scrollbar-drag');
  2565. if (sb.drag.length === 0) {
  2566. sb.drag = $('<div class="swiper-scrollbar-drag"></div>');
  2567. sb.track.append(sb.drag);
  2568. }
  2569. sb.drag[0].style.width = '';
  2570. sb.drag[0].style.height = '';
  2571. sb.trackSize = s.isHorizontal() ? sb.track[0].offsetWidth : sb.track[0].offsetHeight;
  2572. sb.divider = s.size / s.virtualSize;
  2573. sb.moveDivider = sb.divider * (sb.trackSize / s.size);
  2574. sb.dragSize = sb.trackSize * sb.divider;
  2575. if (s.isHorizontal()) {
  2576. sb.drag[0].style.width = sb.dragSize + 'px';
  2577. }
  2578. else {
  2579. sb.drag[0].style.height = sb.dragSize + 'px';
  2580. }
  2581. if (sb.divider >= 1) {
  2582. sb.track[0].style.display = 'none';
  2583. }
  2584. else {
  2585. sb.track[0].style.display = '';
  2586. }
  2587. if (s.params.scrollbarHide) {
  2588. sb.track[0].style.opacity = 0;
  2589. }
  2590. },
  2591. setTranslate: function () {
  2592. if (!s.params.scrollbar) return;
  2593. var diff;
  2594. var sb = s.scrollbar;
  2595. var translate = s.translate || 0;
  2596. var newPos;
  2597. var newSize = sb.dragSize;
  2598. newPos = (sb.trackSize - sb.dragSize) * s.progress;
  2599. if (s.rtl && s.isHorizontal()) {
  2600. newPos = -newPos;
  2601. if (newPos > 0) {
  2602. newSize = sb.dragSize - newPos;
  2603. newPos = 0;
  2604. }
  2605. else if (-newPos + sb.dragSize > sb.trackSize) {
  2606. newSize = sb.trackSize + newPos;
  2607. }
  2608. }
  2609. else {
  2610. if (newPos < 0) {
  2611. newSize = sb.dragSize + newPos;
  2612. newPos = 0;
  2613. }
  2614. else if (newPos + sb.dragSize > sb.trackSize) {
  2615. newSize = sb.trackSize - newPos;
  2616. }
  2617. }
  2618. if (s.isHorizontal()) {
  2619. if (s.support.transforms3d) {
  2620. sb.drag.transform('translate3d(' + (newPos) + 'px, 0, 0)');
  2621. }
  2622. else {
  2623. sb.drag.transform('translateX(' + (newPos) + 'px)');
  2624. }
  2625. sb.drag[0].style.width = newSize + 'px';
  2626. }
  2627. else {
  2628. if (s.support.transforms3d) {
  2629. sb.drag.transform('translate3d(0px, ' + (newPos) + 'px, 0)');
  2630. }
  2631. else {
  2632. sb.drag.transform('translateY(' + (newPos) + 'px)');
  2633. }
  2634. sb.drag[0].style.height = newSize + 'px';
  2635. }
  2636. if (s.params.scrollbarHide) {
  2637. clearTimeout(sb.timeout);
  2638. sb.track[0].style.opacity = 1;
  2639. sb.timeout = setTimeout(function () {
  2640. sb.track[0].style.opacity = 0;
  2641. sb.track.transition(400);
  2642. }, 1000);
  2643. }
  2644. },
  2645. setTransition: function (duration) {
  2646. if (!s.params.scrollbar) return;
  2647. s.scrollbar.drag.transition(duration);
  2648. }
  2649. };
  2650. /*=========================
  2651. Controller
  2652. ===========================*/
  2653. s.controller = {
  2654. LinearSpline: function (x, y) {
  2655. this.x = x;
  2656. this.y = y;
  2657. this.lastIndex = x.length - 1;
  2658. // Given an x value (x2), return the expected y2 value:
  2659. // (x1,y1) is the known point before given value,
  2660. // (x3,y3) is the known point after given value.
  2661. var i1, i3;
  2662. var l = this.x.length;
  2663. this.interpolate = function (x2) {
  2664. if (!x2) return 0;
  2665. // Get the indexes of x1 and x3 (the array indexes before and after given x2):
  2666. i3 = binarySearch(this.x, x2);
  2667. i1 = i3 - 1;
  2668. // We have our indexes i1 & i3, so we can calculate already:
  2669. // y2 := ((x2−x1) × (y3−y1)) ÷ (x3−x1) + y1
  2670. return ((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1]) + this.y[i1];
  2671. };
  2672. var binarySearch = (function() {
  2673. var maxIndex, minIndex, guess;
  2674. return function(array, val) {
  2675. minIndex = -1;
  2676. maxIndex = array.length;
  2677. while (maxIndex - minIndex > 1)
  2678. if (array[guess = maxIndex + minIndex >> 1] <= val) {
  2679. minIndex = guess;
  2680. } else {
  2681. maxIndex = guess;
  2682. }
  2683. return maxIndex;
  2684. };
  2685. })();
  2686. },
  2687. //xxx: for now i will just save one spline function to to
  2688. getInterpolateFunction: function(c){
  2689. if(!s.controller.spline) s.controller.spline = s.params.loop ?
  2690. new s.controller.LinearSpline(s.slidesGrid, c.slidesGrid) :
  2691. new s.controller.LinearSpline(s.snapGrid, c.snapGrid);
  2692. },
  2693. setTranslate: function (translate, byController) {
  2694. var controlled = s.params.control;
  2695. var multiplier, controlledTranslate;
  2696. function setControlledTranslate(c) {
  2697. // this will create an Interpolate function based on the snapGrids
  2698. // x is the Grid of the scrolled scroller and y will be the controlled scroller
  2699. // it makes sense to create this only once and recall it for the interpolation
  2700. // the function does a lot of value caching for performance
  2701. translate = c.rtl && c.params.direction === 'horizontal' ? -s.translate : s.translate;
  2702. if (s.params.controlBy === 'slide') {
  2703. s.controller.getInterpolateFunction(c);
  2704. // i am not sure why the values have to be multiplicated this way, tried to invert the snapGrid
  2705. // but it did not work out
  2706. controlledTranslate = -s.controller.spline.interpolate(-translate);
  2707. }
  2708. if(!controlledTranslate || s.params.controlBy === 'container'){
  2709. multiplier = (c.maxTranslate() - c.minTranslate()) / (s.maxTranslate() - s.minTranslate());
  2710. controlledTranslate = (translate - s.minTranslate()) * multiplier + c.minTranslate();
  2711. }
  2712. if (s.params.controlInverse) {
  2713. controlledTranslate = c.maxTranslate() - controlledTranslate;
  2714. }
  2715. c.updateProgress(controlledTranslate);
  2716. c.setWrapperTranslate(controlledTranslate, false, s);
  2717. c.updateActiveIndex();
  2718. }
  2719. if (s.isArray(controlled)) {
  2720. for (var i = 0; i < controlled.length; i++) {
  2721. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  2722. setControlledTranslate(controlled[i]);
  2723. }
  2724. }
  2725. }
  2726. else if (controlled instanceof Swiper && byController !== controlled) {
  2727. setControlledTranslate(controlled);
  2728. }
  2729. },
  2730. setTransition: function (duration, byController) {
  2731. var controlled = s.params.control;
  2732. var i;
  2733. function setControlledTransition(c) {
  2734. c.setWrapperTransition(duration, s);
  2735. if (duration !== 0) {
  2736. c.onTransitionStart();
  2737. c.wrapper.transitionEnd(function(){
  2738. if (!controlled) return;
  2739. if (c.params.loop && s.params.controlBy === 'slide') {
  2740. c.fixLoop();
  2741. }
  2742. c.onTransitionEnd();
  2743. });
  2744. }
  2745. }
  2746. if (s.isArray(controlled)) {
  2747. for (i = 0; i < controlled.length; i++) {
  2748. if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
  2749. setControlledTransition(controlled[i]);
  2750. }
  2751. }
  2752. }
  2753. else if (controlled instanceof Swiper && byController !== controlled) {
  2754. setControlledTransition(controlled);
  2755. }
  2756. }
  2757. };
  2758. /*=========================
  2759. Hash Navigation
  2760. ===========================*/
  2761. s.hashnav = {
  2762. init: function () {
  2763. if (!s.params.hashnav) return;
  2764. s.hashnav.initialized = true;
  2765. var hash = document.location.hash.replace('#', '');
  2766. if (!hash) return;
  2767. var speed = 0;
  2768. for (var i = 0, length = s.slides.length; i < length; i++) {
  2769. var slide = s.slides.eq(i);
  2770. var slideHash = slide.attr('data-hash');
  2771. if (slideHash === hash && !slide.hasClass(s.params.slideDuplicateClass)) {
  2772. var index = slide.index();
  2773. s.slideTo(index, speed, s.params.runCallbacksOnInit, true);
  2774. }
  2775. }
  2776. },
  2777. setHash: function () {
  2778. if (!s.hashnav.initialized || !s.params.hashnav) return;
  2779. document.location.hash = s.slides.eq(s.activeIndex).attr('data-hash') || '';
  2780. }
  2781. };
  2782. /*=========================
  2783. Keyboard Control
  2784. ===========================*/
  2785. function handleKeyboard(e) {
  2786. if (e.originalEvent) e = e.originalEvent; //jquery fix
  2787. var kc = e.keyCode || e.charCode;
  2788. // Directions locks
  2789. if (!s.params.allowSwipeToNext && (s.isHorizontal() && kc === 39 || !s.isHorizontal() && kc === 40)) {
  2790. return false;
  2791. }
  2792. if (!s.params.allowSwipeToPrev && (s.isHorizontal() && kc === 37 || !s.isHorizontal() && kc === 38)) {
  2793. return false;
  2794. }
  2795. if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) {
  2796. return;
  2797. }
  2798. if (document.activeElement && document.activeElement.nodeName && (document.activeElement.nodeName.toLowerCase() === 'input' || document.activeElement.nodeName.toLowerCase() === 'textarea')) {
  2799. return;
  2800. }
  2801. if (kc === 37 || kc === 39 || kc === 38 || kc === 40) {
  2802. var inView = false;
  2803. //Check that swiper should be inside of visible area of window
  2804. if (s.container.parents('.swiper-slide').length > 0 && s.container.parents('.swiper-slide-active').length === 0) {
  2805. return;
  2806. }
  2807. var windowScroll = {
  2808. left: window.pageXOffset,
  2809. top: window.pageYOffset
  2810. };
  2811. var windowWidth = window.innerWidth;
  2812. var windowHeight = window.innerHeight;
  2813. var swiperOffset = s.container.offset();
  2814. if (s.rtl) swiperOffset.left = swiperOffset.left - s.container[0].scrollLeft;
  2815. var swiperCoord = [
  2816. [swiperOffset.left, swiperOffset.top],
  2817. [swiperOffset.left + s.width, swiperOffset.top],
  2818. [swiperOffset.left, swiperOffset.top + s.height],
  2819. [swiperOffset.left + s.width, swiperOffset.top + s.height]
  2820. ];
  2821. for (var i = 0; i < swiperCoord.length; i++) {
  2822. var point = swiperCoord[i];
  2823. if (
  2824. point[0] >= windowScroll.left && point[0] <= windowScroll.left + windowWidth &&
  2825. point[1] >= windowScroll.top && point[1] <= windowScroll.top + windowHeight
  2826. ) {
  2827. inView = true;
  2828. }
  2829. }
  2830. if (!inView) return;
  2831. }
  2832. if (s.isHorizontal()) {
  2833. if (kc === 37 || kc === 39) {
  2834. if (e.preventDefault) e.preventDefault();
  2835. else e.returnValue = false;
  2836. }
  2837. if ((kc === 39 && !s.rtl) || (kc === 37 && s.rtl)) s.slideNext();
  2838. if ((kc === 37 && !s.rtl) || (kc === 39 && s.rtl)) s.slidePrev();
  2839. }
  2840. else {
  2841. if (kc === 38 || kc === 40) {
  2842. if (e.preventDefault) e.preventDefault();
  2843. else e.returnValue = false;
  2844. }
  2845. if (kc === 40) s.slideNext();
  2846. if (kc === 38) s.slidePrev();
  2847. }
  2848. }
  2849. s.disableKeyboardControl = function () {
  2850. s.params.keyboardControl = false;
  2851. $(document).off('keydown', handleKeyboard);
  2852. };
  2853. s.enableKeyboardControl = function () {
  2854. s.params.keyboardControl = true;
  2855. $(document).on('keydown', handleKeyboard);
  2856. };
  2857. /*=========================
  2858. Mousewheel Control
  2859. ===========================*/
  2860. s.mousewheel = {
  2861. event: false,
  2862. lastScrollTime: (new window.Date()).getTime()
  2863. };
  2864. if (s.params.mousewheelControl) {
  2865. try {
  2866. new window.WheelEvent('wheel');
  2867. s.mousewheel.event = 'wheel';
  2868. } catch (e) {}
  2869. if (!s.mousewheel.event && document.onmousewheel !== undefined) {
  2870. s.mousewheel.event = 'mousewheel';
  2871. }
  2872. if (!s.mousewheel.event) {
  2873. s.mousewheel.event = 'DOMMouseScroll';
  2874. }
  2875. }
  2876. function handleMousewheel(e) {
  2877. if (e.originalEvent) e = e.originalEvent; //jquery fix
  2878. var we = s.mousewheel.event;
  2879. var delta = 0;
  2880. var rtlFactor = s.rtl ? -1 : 1;
  2881. //Opera & IE
  2882. if (e.detail) delta = -e.detail;
  2883. //WebKits
  2884. else if (we === 'mousewheel') {
  2885. if (s.params.mousewheelForceToAxis) {
  2886. if (s.isHorizontal()) {
  2887. if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) delta = e.wheelDeltaX * rtlFactor;
  2888. else return;
  2889. }
  2890. else {
  2891. if (Math.abs(e.wheelDeltaY) > Math.abs(e.wheelDeltaX)) delta = e.wheelDeltaY;
  2892. else return;
  2893. }
  2894. }
  2895. else {
  2896. delta = Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY) ? - e.wheelDeltaX * rtlFactor : - e.wheelDeltaY;
  2897. }
  2898. }
  2899. //Old FireFox
  2900. else if (we === 'DOMMouseScroll') delta = -e.detail;
  2901. //New FireFox
  2902. else if (we === 'wheel') {
  2903. if (s.params.mousewheelForceToAxis) {
  2904. if (s.isHorizontal()) {
  2905. if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = -e.deltaX * rtlFactor;
  2906. else return;
  2907. }
  2908. else {
  2909. if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) delta = -e.deltaY;
  2910. else return;
  2911. }
  2912. }
  2913. else {
  2914. delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? - e.deltaX * rtlFactor : - e.deltaY;
  2915. }
  2916. }
  2917. if (delta === 0) return;
  2918. if (s.params.mousewheelInvert) delta = -delta;
  2919. if (!s.params.freeMode) {
  2920. if ((new window.Date()).getTime() - s.mousewheel.lastScrollTime > 60) {
  2921. if (delta < 0) {
  2922. if ((!s.isEnd || s.params.loop) && !s.animating) s.slideNext();
  2923. else if (s.params.mousewheelReleaseOnEdges) return true;
  2924. }
  2925. else {
  2926. if ((!s.isBeginning || s.params.loop) && !s.animating) s.slidePrev();
  2927. else if (s.params.mousewheelReleaseOnEdges) return true;
  2928. }
  2929. }
  2930. s.mousewheel.lastScrollTime = (new window.Date()).getTime();
  2931. }
  2932. else {
  2933. //Freemode or scrollContainer:
  2934. var position = s.getWrapperTranslate() + delta * s.params.mousewheelSensitivity;
  2935. var wasBeginning = s.isBeginning,
  2936. wasEnd = s.isEnd;
  2937. if (position >= s.minTranslate()) position = s.minTranslate();
  2938. if (position <= s.maxTranslate()) position = s.maxTranslate();
  2939. s.setWrapperTransition(0);
  2940. s.setWrapperTranslate(position);
  2941. s.updateProgress();
  2942. s.updateActiveIndex();
  2943. if (!wasBeginning && s.isBeginning || !wasEnd && s.isEnd) {
  2944. s.updateClasses();
  2945. }
  2946. if (s.params.freeModeSticky) {
  2947. clearTimeout(s.mousewheel.timeout);
  2948. s.mousewheel.timeout = setTimeout(function () {
  2949. s.slideReset();
  2950. }, 300);
  2951. }
  2952. else {
  2953. if (s.params.lazyLoading && s.lazy) {
  2954. s.lazy.load();
  2955. }
  2956. }
  2957. // Return page scroll on edge positions
  2958. if (position === 0 || position === s.maxTranslate()) return;
  2959. }
  2960. if (s.params.autoplay) s.stopAutoplay();
  2961. if (e.preventDefault) e.preventDefault();
  2962. else e.returnValue = false;
  2963. return false;
  2964. }
  2965. s.disableMousewheelControl = function () {
  2966. if (!s.mousewheel.event) return false;
  2967. s.container.off(s.mousewheel.event, handleMousewheel);
  2968. return true;
  2969. };
  2970. s.enableMousewheelControl = function () {
  2971. if (!s.mousewheel.event) return false;
  2972. s.container.on(s.mousewheel.event, handleMousewheel);
  2973. return true;
  2974. };
  2975. /*=========================
  2976. Parallax
  2977. ===========================*/
  2978. function setParallaxTransform(el, progress) {
  2979. el = $(el);
  2980. var p, pX, pY;
  2981. var rtlFactor = s.rtl ? -1 : 1;
  2982. p = el.attr('data-swiper-parallax') || '0';
  2983. pX = el.attr('data-swiper-parallax-x');
  2984. pY = el.attr('data-swiper-parallax-y');
  2985. if (pX || pY) {
  2986. pX = pX || '0';
  2987. pY = pY || '0';
  2988. }
  2989. else {
  2990. if (s.isHorizontal()) {
  2991. pX = p;
  2992. pY = '0';
  2993. }
  2994. else {
  2995. pY = p;
  2996. pX = '0';
  2997. }
  2998. }
  2999. if ((pX).indexOf('%') >= 0) {
  3000. pX = parseInt(pX, 10) * progress * rtlFactor + '%';
  3001. }
  3002. else {
  3003. pX = pX * progress * rtlFactor + 'px' ;
  3004. }
  3005. if ((pY).indexOf('%') >= 0) {
  3006. pY = parseInt(pY, 10) * progress + '%';
  3007. }
  3008. else {
  3009. pY = pY * progress + 'px' ;
  3010. }
  3011. el.transform('translate3d(' + pX + ', ' + pY + ',0px)');
  3012. }
  3013. s.parallax = {
  3014. setTranslate: function () {
  3015. s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  3016. setParallaxTransform(this, s.progress);
  3017. });
  3018. s.slides.each(function () {
  3019. var slide = $(this);
  3020. slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () {
  3021. var progress = Math.min(Math.max(slide[0].progress, -1), 1);
  3022. setParallaxTransform(this, progress);
  3023. });
  3024. });
  3025. },
  3026. setTransition: function (duration) {
  3027. if (typeof duration === 'undefined') duration = s.params.speed;
  3028. s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
  3029. var el = $(this);
  3030. var parallaxDuration = parseInt(el.attr('data-swiper-parallax-duration'), 10) || duration;
  3031. if (duration === 0) parallaxDuration = 0;
  3032. el.transition(parallaxDuration);
  3033. });
  3034. }
  3035. };
  3036. /*=========================
  3037. Plugins API. Collect all and init all plugins
  3038. ===========================*/
  3039. s._plugins = [];
  3040. for (var plugin in s.plugins) {
  3041. var p = s.plugins[plugin](s, s.params[plugin]);
  3042. if (p) s._plugins.push(p);
  3043. }
  3044. // Method to call all plugins event/method
  3045. s.callPlugins = function (eventName) {
  3046. for (var i = 0; i < s._plugins.length; i++) {
  3047. if (eventName in s._plugins[i]) {
  3048. s._plugins[i][eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3049. }
  3050. }
  3051. };
  3052. /*=========================
  3053. Events/Callbacks/Plugins Emitter
  3054. ===========================*/
  3055. function normalizeEventName (eventName) {
  3056. if (eventName.indexOf('on') !== 0) {
  3057. if (eventName[0] !== eventName[0].toUpperCase()) {
  3058. eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1);
  3059. }
  3060. else {
  3061. eventName = 'on' + eventName;
  3062. }
  3063. }
  3064. return eventName;
  3065. }
  3066. s.emitterEventListeners = {
  3067. };
  3068. s.emit = function (eventName) {
  3069. // Trigger callbacks
  3070. if (s.params[eventName]) {
  3071. s.params[eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3072. }
  3073. var i;
  3074. // Trigger events
  3075. if (s.emitterEventListeners[eventName]) {
  3076. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  3077. s.emitterEventListeners[eventName][i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3078. }
  3079. }
  3080. // Trigger plugins
  3081. if (s.callPlugins) s.callPlugins(eventName, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
  3082. };
  3083. s.on = function (eventName, handler) {
  3084. eventName = normalizeEventName(eventName);
  3085. if (!s.emitterEventListeners[eventName]) s.emitterEventListeners[eventName] = [];
  3086. s.emitterEventListeners[eventName].push(handler);
  3087. return s;
  3088. };
  3089. s.off = function (eventName, handler) {
  3090. var i;
  3091. eventName = normalizeEventName(eventName);
  3092. if (typeof handler === 'undefined') {
  3093. // Remove all handlers for such event
  3094. s.emitterEventListeners[eventName] = [];
  3095. return s;
  3096. }
  3097. if (!s.emitterEventListeners[eventName] || s.emitterEventListeners[eventName].length === 0) return;
  3098. for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
  3099. if(s.emitterEventListeners[eventName][i] === handler) s.emitterEventListeners[eventName].splice(i, 1);
  3100. }
  3101. return s;
  3102. };
  3103. s.once = function (eventName, handler) {
  3104. eventName = normalizeEventName(eventName);
  3105. var _handler = function () {
  3106. handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
  3107. s.off(eventName, _handler);
  3108. };
  3109. s.on(eventName, _handler);
  3110. return s;
  3111. };
  3112. // Accessibility tools
  3113. s.a11y = {
  3114. makeFocusable: function ($el) {
  3115. $el.attr('tabIndex', '0');
  3116. return $el;
  3117. },
  3118. addRole: function ($el, role) {
  3119. $el.attr('role', role);
  3120. return $el;
  3121. },
  3122. addLabel: function ($el, label) {
  3123. $el.attr('aria-label', label);
  3124. return $el;
  3125. },
  3126. disable: function ($el) {
  3127. $el.attr('aria-disabled', true);
  3128. return $el;
  3129. },
  3130. enable: function ($el) {
  3131. $el.attr('aria-disabled', false);
  3132. return $el;
  3133. },
  3134. onEnterKey: function (event) {
  3135. if (event.keyCode !== 13) return;
  3136. if ($(event.target).is(s.params.nextButton)) {
  3137. s.onClickNext(event);
  3138. if (s.isEnd) {
  3139. s.a11y.notify(s.params.lastSlideMessage);
  3140. }
  3141. else {
  3142. s.a11y.notify(s.params.nextSlideMessage);
  3143. }
  3144. }
  3145. else if ($(event.target).is(s.params.prevButton)) {
  3146. s.onClickPrev(event);
  3147. if (s.isBeginning) {
  3148. s.a11y.notify(s.params.firstSlideMessage);
  3149. }
  3150. else {
  3151. s.a11y.notify(s.params.prevSlideMessage);
  3152. }
  3153. }
  3154. if ($(event.target).is('.' + s.params.bulletClass)) {
  3155. $(event.target)[0].click();
  3156. }
  3157. },
  3158. liveRegion: $('<span class="swiper-notification" aria-live="assertive" aria-atomic="true"></span>'),
  3159. notify: function (message) {
  3160. var notification = s.a11y.liveRegion;
  3161. if (notification.length === 0) return;
  3162. notification.html('');
  3163. notification.html(message);
  3164. },
  3165. init: function () {
  3166. // Setup accessibility
  3167. if (s.params.nextButton) {
  3168. var nextButton = $(s.params.nextButton);
  3169. s.a11y.makeFocusable(nextButton);
  3170. s.a11y.addRole(nextButton, 'button');
  3171. s.a11y.addLabel(nextButton, s.params.nextSlideMessage);
  3172. }
  3173. if (s.params.prevButton) {
  3174. var prevButton = $(s.params.prevButton);
  3175. s.a11y.makeFocusable(prevButton);
  3176. s.a11y.addRole(prevButton, 'button');
  3177. s.a11y.addLabel(prevButton, s.params.prevSlideMessage);
  3178. }
  3179. $(s.container).append(s.a11y.liveRegion);
  3180. },
  3181. initPagination: function () {
  3182. if (s.params.pagination && s.params.paginationClickable && s.bullets && s.bullets.length) {
  3183. s.bullets.each(function () {
  3184. var bullet = $(this);
  3185. s.a11y.makeFocusable(bullet);
  3186. s.a11y.addRole(bullet, 'button');
  3187. s.a11y.addLabel(bullet, s.params.paginationBulletMessage.replace(/{{index}}/, bullet.index() + 1));
  3188. });
  3189. }
  3190. },
  3191. destroy: function () {
  3192. if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove();
  3193. }
  3194. };
  3195. /*=========================
  3196. Init/Destroy
  3197. ===========================*/
  3198. s.init = function () {
  3199. if (s.params.loop) s.createLoop();
  3200. s.updateContainerSize();
  3201. s.updateSlidesSize();
  3202. s.updatePagination();
  3203. if (s.params.scrollbar && s.scrollbar) {
  3204. s.scrollbar.set();
  3205. if (s.params.scrollbarDraggable) {
  3206. s.scrollbar.enableDraggable();
  3207. }
  3208. }
  3209. if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
  3210. if (!s.params.loop) s.updateProgress();
  3211. s.effects[s.params.effect].setTranslate();
  3212. }
  3213. if (s.params.loop) {
  3214. s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit);
  3215. }
  3216. else {
  3217. s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit);
  3218. if (s.params.initialSlide === 0) {
  3219. if (s.parallax && s.params.parallax) s.parallax.setTranslate();
  3220. if (s.lazy && s.params.lazyLoading) {
  3221. s.lazy.load();
  3222. s.lazy.initialImageLoaded = true;
  3223. }
  3224. }
  3225. }
  3226. s.attachEvents();
  3227. if (s.params.observer && s.support.observer) {
  3228. s.initObservers();
  3229. }
  3230. if (s.params.preloadImages && !s.params.lazyLoading) {
  3231. s.preloadImages();
  3232. }
  3233. if (s.params.autoplay) {
  3234. s.startAutoplay();
  3235. }
  3236. if (s.params.keyboardControl) {
  3237. if (s.enableKeyboardControl) s.enableKeyboardControl();
  3238. }
  3239. if (s.params.mousewheelControl) {
  3240. if (s.enableMousewheelControl) s.enableMousewheelControl();
  3241. }
  3242. if (s.params.hashnav) {
  3243. if (s.hashnav) s.hashnav.init();
  3244. }
  3245. if (s.params.a11y && s.a11y) s.a11y.init();
  3246. s.emit('onInit', s);
  3247. };
  3248. // Cleanup dynamic styles
  3249. s.cleanupStyles = function () {
  3250. // Container
  3251. s.container.removeClass(s.classNames.join(' ')).removeAttr('style');
  3252. // Wrapper
  3253. s.wrapper.removeAttr('style');
  3254. // Slides
  3255. if (s.slides && s.slides.length) {
  3256. s.slides
  3257. .removeClass([
  3258. s.params.slideVisibleClass,
  3259. s.params.slideActiveClass,
  3260. s.params.slideNextClass,
  3261. s.params.slidePrevClass
  3262. ].join(' '))
  3263. .removeAttr('style')
  3264. .removeAttr('data-swiper-column')
  3265. .removeAttr('data-swiper-row');
  3266. }
  3267. // Pagination/Bullets
  3268. if (s.paginationContainer && s.paginationContainer.length) {
  3269. s.paginationContainer.removeClass(s.params.paginationHiddenClass);
  3270. }
  3271. if (s.bullets && s.bullets.length) {
  3272. s.bullets.removeClass(s.params.bulletActiveClass);
  3273. }
  3274. // Buttons
  3275. if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
  3276. if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
  3277. // Scrollbar
  3278. if (s.params.scrollbar && s.scrollbar) {
  3279. if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style');
  3280. if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style');
  3281. }
  3282. };
  3283. // Destroy
  3284. s.destroy = function (deleteInstance, cleanupStyles) {
  3285. // Detach evebts
  3286. s.detachEvents();
  3287. // Stop autoplay
  3288. s.stopAutoplay();
  3289. // Disable draggable
  3290. if (s.params.scrollbar && s.scrollbar) {
  3291. if (s.params.scrollbarDraggable) {
  3292. s.scrollbar.disableDraggable();
  3293. }
  3294. }
  3295. // Destroy loop
  3296. if (s.params.loop) {
  3297. s.destroyLoop();
  3298. }
  3299. // Cleanup styles
  3300. if (cleanupStyles) {
  3301. s.cleanupStyles();
  3302. }
  3303. // Disconnect observer
  3304. s.disconnectObservers();
  3305. // Disable keyboard/mousewheel
  3306. if (s.params.keyboardControl) {
  3307. if (s.disableKeyboardControl) s.disableKeyboardControl();
  3308. }
  3309. if (s.params.mousewheelControl) {
  3310. if (s.disableMousewheelControl) s.disableMousewheelControl();
  3311. }
  3312. // Disable a11y
  3313. if (s.params.a11y && s.a11y) s.a11y.destroy();
  3314. // Destroy callback
  3315. s.emit('onDestroy');
  3316. // Delete instance
  3317. if (deleteInstance !== false) s = null;
  3318. };
  3319. s.init();
  3320. // Return swiper instance
  3321. return s;
  3322. };
  3323. /*==================================================
  3324. Prototype
  3325. ====================================================*/
  3326. Swiper.prototype = {
  3327. isSafari: (function () {
  3328. var ua = navigator.userAgent.toLowerCase();
  3329. return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0);
  3330. })(),
  3331. isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent),
  3332. isArray: function (arr) {
  3333. return Object.prototype.toString.apply(arr) === '[object Array]';
  3334. },
  3335. /*==================================================
  3336. Browser
  3337. ====================================================*/
  3338. browser: {
  3339. ie: window.navigator.pointerEnabled || window.navigator.msPointerEnabled,
  3340. ieTouch: (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 1) || (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 1)
  3341. },
  3342. /*==================================================
  3343. Devices
  3344. ====================================================*/
  3345. device: (function () {
  3346. var ua = navigator.userAgent;
  3347. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  3348. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  3349. var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  3350. var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  3351. return {
  3352. ios: ipad || iphone || ipod,
  3353. android: android
  3354. };
  3355. })(),
  3356. /*==================================================
  3357. Feature Detection
  3358. ====================================================*/
  3359. support: {
  3360. touch : (window.Modernizr && Modernizr.touch === true) || (function () {
  3361. return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
  3362. })(),
  3363. transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () {
  3364. var div = document.createElement('div').style;
  3365. return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
  3366. })(),
  3367. flexbox: (function () {
  3368. var div = document.createElement('div').style;
  3369. var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' ');
  3370. for (var i = 0; i < styles.length; i++) {
  3371. if (styles[i] in div) return true;
  3372. }
  3373. })(),
  3374. observer: (function () {
  3375. return ('MutationObserver' in window || 'WebkitMutationObserver' in window);
  3376. })()
  3377. },
  3378. /*==================================================
  3379. Plugins
  3380. ====================================================*/
  3381. plugins: {}
  3382. };
  3383. /*===========================
  3384. Dom7 Library
  3385. ===========================*/
  3386. var Dom7 = (function () {
  3387. var Dom7 = function (arr) {
  3388. var _this = this, i = 0;
  3389. // Create array-like object
  3390. for (i = 0; i < arr.length; i++) {
  3391. _this[i] = arr[i];
  3392. }
  3393. _this.length = arr.length;
  3394. // Return collection with methods
  3395. return this;
  3396. };
  3397. var $ = function (selector, context) {
  3398. var arr = [], i = 0;
  3399. if (selector && !context) {
  3400. if (selector instanceof Dom7) {
  3401. return selector;
  3402. }
  3403. }
  3404. if (selector) {
  3405. // String
  3406. if (typeof selector === 'string') {
  3407. var els, tempParent, html = selector.trim();
  3408. if (html.indexOf('<') >= 0 && html.indexOf('>') >= 0) {
  3409. var toCreate = 'div';
  3410. if (html.indexOf('<li') === 0) toCreate = 'ul';
  3411. if (html.indexOf('<tr') === 0) toCreate = 'tbody';
  3412. if (html.indexOf('<td') === 0 || html.indexOf('<th') === 0) toCreate = 'tr';
  3413. if (html.indexOf('<tbody') === 0) toCreate = 'table';
  3414. if (html.indexOf('<option') === 0) toCreate = 'select';
  3415. tempParent = document.createElement(toCreate);
  3416. tempParent.innerHTML = selector;
  3417. for (i = 0; i < tempParent.childNodes.length; i++) {
  3418. arr.push(tempParent.childNodes[i]);
  3419. }
  3420. }
  3421. else {
  3422. if (!context && selector[0] === '#' && !selector.match(/[ .<>:~]/)) {
  3423. // Pure ID selector
  3424. els = [document.getElementById(selector.split('#')[1])];
  3425. }
  3426. else {
  3427. // Other selectors
  3428. els = (context || document).querySelectorAll(selector);
  3429. }
  3430. for (i = 0; i < els.length; i++) {
  3431. if (els[i]) arr.push(els[i]);
  3432. }
  3433. }
  3434. }
  3435. // Node/element
  3436. else if (selector.nodeType || selector === window || selector === document) {
  3437. arr.push(selector);
  3438. }
  3439. //Array of elements or instance of Dom
  3440. else if (selector.length > 0 && selector[0].nodeType) {
  3441. for (i = 0; i < selector.length; i++) {
  3442. arr.push(selector[i]);
  3443. }
  3444. }
  3445. }
  3446. return new Dom7(arr);
  3447. };
  3448. Dom7.prototype = {
  3449. // Classes and attriutes
  3450. addClass: function (className) {
  3451. if (typeof className === 'undefined') {
  3452. return this;
  3453. }
  3454. var classes = className.split(' ');
  3455. for (var i = 0; i < classes.length; i++) {
  3456. for (var j = 0; j < this.length; j++) {
  3457. this[j].classList.add(classes[i]);
  3458. }
  3459. }
  3460. return this;
  3461. },
  3462. removeClass: function (className) {
  3463. var classes = className.split(' ');
  3464. for (var i = 0; i < classes.length; i++) {
  3465. for (var j = 0; j < this.length; j++) {
  3466. this[j].classList.remove(classes[i]);
  3467. }
  3468. }
  3469. return this;
  3470. },
  3471. hasClass: function (className) {
  3472. if (!this[0]) return false;
  3473. else return this[0].classList.contains(className);
  3474. },
  3475. toggleClass: function (className) {
  3476. var classes = className.split(' ');
  3477. for (var i = 0; i < classes.length; i++) {
  3478. for (var j = 0; j < this.length; j++) {
  3479. this[j].classList.toggle(classes[i]);
  3480. }
  3481. }
  3482. return this;
  3483. },
  3484. attr: function (attrs, value) {
  3485. if (arguments.length === 1 && typeof attrs === 'string') {
  3486. // Get attr
  3487. if (this[0]) return this[0].getAttribute(attrs);
  3488. else return undefined;
  3489. }
  3490. else {
  3491. // Set attrs
  3492. for (var i = 0; i < this.length; i++) {
  3493. if (arguments.length === 2) {
  3494. // String
  3495. this[i].setAttribute(attrs, value);
  3496. }
  3497. else {
  3498. // Object
  3499. for (var attrName in attrs) {
  3500. this[i][attrName] = attrs[attrName];
  3501. this[i].setAttribute(attrName, attrs[attrName]);
  3502. }
  3503. }
  3504. }
  3505. return this;
  3506. }
  3507. },
  3508. removeAttr: function (attr) {
  3509. for (var i = 0; i < this.length; i++) {
  3510. this[i].removeAttribute(attr);
  3511. }
  3512. return this;
  3513. },
  3514. data: function (key, value) {
  3515. if (typeof value === 'undefined') {
  3516. // Get value
  3517. if (this[0]) {
  3518. var dataKey = this[0].getAttribute('data-' + key);
  3519. if (dataKey) return dataKey;
  3520. else if (this[0].dom7ElementDataStorage && (key in this[0].dom7ElementDataStorage)) return this[0].dom7ElementDataStorage[key];
  3521. else return undefined;
  3522. }
  3523. else return undefined;
  3524. }
  3525. else {
  3526. // Set value
  3527. for (var i = 0; i < this.length; i++) {
  3528. var el = this[i];
  3529. if (!el.dom7ElementDataStorage) el.dom7ElementDataStorage = {};
  3530. el.dom7ElementDataStorage[key] = value;
  3531. }
  3532. return this;
  3533. }
  3534. },
  3535. // Transforms
  3536. transform : function (transform) {
  3537. for (var i = 0; i < this.length; i++) {
  3538. var elStyle = this[i].style;
  3539. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  3540. }
  3541. return this;
  3542. },
  3543. transition: function (duration) {
  3544. if (typeof duration !== 'string') {
  3545. duration = duration + 'ms';
  3546. }
  3547. for (var i = 0; i < this.length; i++) {
  3548. var elStyle = this[i].style;
  3549. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  3550. }
  3551. return this;
  3552. },
  3553. //Events
  3554. on: function (eventName, targetSelector, listener, capture) {
  3555. function handleLiveEvent(e) {
  3556. var target = e.target;
  3557. if ($(target).is(targetSelector)) listener.call(target, e);
  3558. else {
  3559. var parents = $(target).parents();
  3560. for (var k = 0; k < parents.length; k++) {
  3561. if ($(parents[k]).is(targetSelector)) listener.call(parents[k], e);
  3562. }
  3563. }
  3564. }
  3565. var events = eventName.split(' ');
  3566. var i, j;
  3567. for (i = 0; i < this.length; i++) {
  3568. if (typeof targetSelector === 'function' || targetSelector === false) {
  3569. // Usual events
  3570. if (typeof targetSelector === 'function') {
  3571. listener = arguments[1];
  3572. capture = arguments[2] || false;
  3573. }
  3574. for (j = 0; j < events.length; j++) {
  3575. this[i].addEventListener(events[j], listener, capture);
  3576. }
  3577. }
  3578. else {
  3579. //Live events
  3580. for (j = 0; j < events.length; j++) {
  3581. if (!this[i].dom7LiveListeners) this[i].dom7LiveListeners = [];
  3582. this[i].dom7LiveListeners.push({listener: listener, liveListener: handleLiveEvent});
  3583. this[i].addEventListener(events[j], handleLiveEvent, capture);
  3584. }
  3585. }
  3586. }
  3587. return this;
  3588. },
  3589. off: function (eventName, targetSelector, listener, capture) {
  3590. var events = eventName.split(' ');
  3591. for (var i = 0; i < events.length; i++) {
  3592. for (var j = 0; j < this.length; j++) {
  3593. if (typeof targetSelector === 'function' || targetSelector === false) {
  3594. // Usual events
  3595. if (typeof targetSelector === 'function') {
  3596. listener = arguments[1];
  3597. capture = arguments[2] || false;
  3598. }
  3599. this[j].removeEventListener(events[i], listener, capture);
  3600. }
  3601. else {
  3602. // Live event
  3603. if (this[j].dom7LiveListeners) {
  3604. for (var k = 0; k < this[j].dom7LiveListeners.length; k++) {
  3605. if (this[j].dom7LiveListeners[k].listener === listener) {
  3606. this[j].removeEventListener(events[i], this[j].dom7LiveListeners[k].liveListener, capture);
  3607. }
  3608. }
  3609. }
  3610. }
  3611. }
  3612. }
  3613. return this;
  3614. },
  3615. once: function (eventName, targetSelector, listener, capture) {
  3616. var dom = this;
  3617. if (typeof targetSelector === 'function') {
  3618. targetSelector = false;
  3619. listener = arguments[1];
  3620. capture = arguments[2];
  3621. }
  3622. function proxy(e) {
  3623. listener(e);
  3624. dom.off(eventName, targetSelector, proxy, capture);
  3625. }
  3626. dom.on(eventName, targetSelector, proxy, capture);
  3627. },
  3628. trigger: function (eventName, eventData) {
  3629. for (var i = 0; i < this.length; i++) {
  3630. var evt;
  3631. try {
  3632. evt = new window.CustomEvent(eventName, {detail: eventData, bubbles: true, cancelable: true});
  3633. }
  3634. catch (e) {
  3635. evt = document.createEvent('Event');
  3636. evt.initEvent(eventName, true, true);
  3637. evt.detail = eventData;
  3638. }
  3639. this[i].dispatchEvent(evt);
  3640. }
  3641. return this;
  3642. },
  3643. transitionEnd: function (callback) {
  3644. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  3645. i, j, dom = this;
  3646. function fireCallBack(e) {
  3647. /*jshint validthis:true */
  3648. if (e.target !== this) return;
  3649. callback.call(this, e);
  3650. for (i = 0; i < events.length; i++) {
  3651. dom.off(events[i], fireCallBack);
  3652. }
  3653. }
  3654. if (callback) {
  3655. for (i = 0; i < events.length; i++) {
  3656. dom.on(events[i], fireCallBack);
  3657. }
  3658. }
  3659. return this;
  3660. },
  3661. // Sizing/Styles
  3662. width: function () {
  3663. if (this[0] === window) {
  3664. return window.innerWidth;
  3665. }
  3666. else {
  3667. if (this.length > 0) {
  3668. return parseFloat(this.css('width'));
  3669. }
  3670. else {
  3671. return null;
  3672. }
  3673. }
  3674. },
  3675. outerWidth: function (includeMargins) {
  3676. if (this.length > 0) {
  3677. if (includeMargins)
  3678. return this[0].offsetWidth + parseFloat(this.css('margin-right')) + parseFloat(this.css('margin-left'));
  3679. else
  3680. return this[0].offsetWidth;
  3681. }
  3682. else return null;
  3683. },
  3684. height: function () {
  3685. if (this[0] === window) {
  3686. return window.innerHeight;
  3687. }
  3688. else {
  3689. if (this.length > 0) {
  3690. return parseFloat(this.css('height'));
  3691. }
  3692. else {
  3693. return null;
  3694. }
  3695. }
  3696. },
  3697. outerHeight: function (includeMargins) {
  3698. if (this.length > 0) {
  3699. if (includeMargins)
  3700. return this[0].offsetHeight + parseFloat(this.css('margin-top')) + parseFloat(this.css('margin-bottom'));
  3701. else
  3702. return this[0].offsetHeight;
  3703. }
  3704. else return null;
  3705. },
  3706. offset: function () {
  3707. if (this.length > 0) {
  3708. var el = this[0];
  3709. var box = el.getBoundingClientRect();
  3710. var body = document.body;
  3711. var clientTop = el.clientTop || body.clientTop || 0;
  3712. var clientLeft = el.clientLeft || body.clientLeft || 0;
  3713. var scrollTop = window.pageYOffset || el.scrollTop;
  3714. var scrollLeft = window.pageXOffset || el.scrollLeft;
  3715. return {
  3716. top: box.top + scrollTop - clientTop,
  3717. left: box.left + scrollLeft - clientLeft
  3718. };
  3719. }
  3720. else {
  3721. return null;
  3722. }
  3723. },
  3724. css: function (props, value) {
  3725. var i;
  3726. if (arguments.length === 1) {
  3727. if (typeof props === 'string') {
  3728. if (this[0]) return window.getComputedStyle(this[0], null).getPropertyValue(props);
  3729. }
  3730. else {
  3731. for (i = 0; i < this.length; i++) {
  3732. for (var prop in props) {
  3733. this[i].style[prop] = props[prop];
  3734. }
  3735. }
  3736. return this;
  3737. }
  3738. }
  3739. if (arguments.length === 2 && typeof props === 'string') {
  3740. for (i = 0; i < this.length; i++) {
  3741. this[i].style[props] = value;
  3742. }
  3743. return this;
  3744. }
  3745. return this;
  3746. },
  3747. //Dom manipulation
  3748. each: function (callback) {
  3749. for (var i = 0; i < this.length; i++) {
  3750. callback.call(this[i], i, this[i]);
  3751. }
  3752. return this;
  3753. },
  3754. html: function (html) {
  3755. if (typeof html === 'undefined') {
  3756. return this[0] ? this[0].innerHTML : undefined;
  3757. }
  3758. else {
  3759. for (var i = 0; i < this.length; i++) {
  3760. this[i].innerHTML = html;
  3761. }
  3762. return this;
  3763. }
  3764. },
  3765. text: function (text) {
  3766. if (typeof text === 'undefined') {
  3767. if (this[0]) {
  3768. return this[0].textContent.trim();
  3769. }
  3770. else return null;
  3771. }
  3772. else {
  3773. for (var i = 0; i < this.length; i++) {
  3774. this[i].textContent = text;
  3775. }
  3776. return this;
  3777. }
  3778. },
  3779. is: function (selector) {
  3780. if (!this[0]) return false;
  3781. var compareWith, i;
  3782. if (typeof selector === 'string') {
  3783. var el = this[0];
  3784. if (el === document) return selector === document;
  3785. if (el === window) return selector === window;
  3786. if (el.matches) return el.matches(selector);
  3787. else if (el.webkitMatchesSelector) return el.webkitMatchesSelector(selector);
  3788. else if (el.mozMatchesSelector) return el.mozMatchesSelector(selector);
  3789. else if (el.msMatchesSelector) return el.msMatchesSelector(selector);
  3790. else {
  3791. compareWith = $(selector);
  3792. for (i = 0; i < compareWith.length; i++) {
  3793. if (compareWith[i] === this[0]) return true;
  3794. }
  3795. return false;
  3796. }
  3797. }
  3798. else if (selector === document) return this[0] === document;
  3799. else if (selector === window) return this[0] === window;
  3800. else {
  3801. if (selector.nodeType || selector instanceof Dom7) {
  3802. compareWith = selector.nodeType ? [selector] : selector;
  3803. for (i = 0; i < compareWith.length; i++) {
  3804. if (compareWith[i] === this[0]) return true;
  3805. }
  3806. return false;
  3807. }
  3808. return false;
  3809. }
  3810. },
  3811. index: function () {
  3812. if (this[0]) {
  3813. var child = this[0];
  3814. var i = 0;
  3815. while ((child = child.previousSibling) !== null) {
  3816. if (child.nodeType === 1) i++;
  3817. }
  3818. return i;
  3819. }
  3820. else return undefined;
  3821. },
  3822. eq: function (index) {
  3823. if (typeof index === 'undefined') return this;
  3824. var length = this.length;
  3825. var returnIndex;
  3826. if (index > length - 1) {
  3827. return new Dom7([]);
  3828. }
  3829. if (index < 0) {
  3830. returnIndex = length + index;
  3831. if (returnIndex < 0) return new Dom7([]);
  3832. else return new Dom7([this[returnIndex]]);
  3833. }
  3834. return new Dom7([this[index]]);
  3835. },
  3836. append: function (newChild) {
  3837. var i, j;
  3838. for (i = 0; i < this.length; i++) {
  3839. if (typeof newChild === 'string') {
  3840. var tempDiv = document.createElement('div');
  3841. tempDiv.innerHTML = newChild;
  3842. while (tempDiv.firstChild) {
  3843. this[i].appendChild(tempDiv.firstChild);
  3844. }
  3845. }
  3846. else if (newChild instanceof Dom7) {
  3847. for (j = 0; j < newChild.length; j++) {
  3848. this[i].appendChild(newChild[j]);
  3849. }
  3850. }
  3851. else {
  3852. this[i].appendChild(newChild);
  3853. }
  3854. }
  3855. return this;
  3856. },
  3857. prepend: function (newChild) {
  3858. var i, j;
  3859. for (i = 0; i < this.length; i++) {
  3860. if (typeof newChild === 'string') {
  3861. var tempDiv = document.createElement('div');
  3862. tempDiv.innerHTML = newChild;
  3863. for (j = tempDiv.childNodes.length - 1; j >= 0; j--) {
  3864. this[i].insertBefore(tempDiv.childNodes[j], this[i].childNodes[0]);
  3865. }
  3866. // this[i].insertAdjacentHTML('afterbegin', newChild);
  3867. }
  3868. else if (newChild instanceof Dom7) {
  3869. for (j = 0; j < newChild.length; j++) {
  3870. this[i].insertBefore(newChild[j], this[i].childNodes[0]);
  3871. }
  3872. }
  3873. else {
  3874. this[i].insertBefore(newChild, this[i].childNodes[0]);
  3875. }
  3876. }
  3877. return this;
  3878. },
  3879. insertBefore: function (selector) {
  3880. var before = $(selector);
  3881. for (var i = 0; i < this.length; i++) {
  3882. if (before.length === 1) {
  3883. before[0].parentNode.insertBefore(this[i], before[0]);
  3884. }
  3885. else if (before.length > 1) {
  3886. for (var j = 0; j < before.length; j++) {
  3887. before[j].parentNode.insertBefore(this[i].cloneNode(true), before[j]);
  3888. }
  3889. }
  3890. }
  3891. },
  3892. insertAfter: function (selector) {
  3893. var after = $(selector);
  3894. for (var i = 0; i < this.length; i++) {
  3895. if (after.length === 1) {
  3896. after[0].parentNode.insertBefore(this[i], after[0].nextSibling);
  3897. }
  3898. else if (after.length > 1) {
  3899. for (var j = 0; j < after.length; j++) {
  3900. after[j].parentNode.insertBefore(this[i].cloneNode(true), after[j].nextSibling);
  3901. }
  3902. }
  3903. }
  3904. },
  3905. next: function (selector) {
  3906. if (this.length > 0) {
  3907. if (selector) {
  3908. if (this[0].nextElementSibling && $(this[0].nextElementSibling).is(selector)) return new Dom7([this[0].nextElementSibling]);
  3909. else return new Dom7([]);
  3910. }
  3911. else {
  3912. if (this[0].nextElementSibling) return new Dom7([this[0].nextElementSibling]);
  3913. else return new Dom7([]);
  3914. }
  3915. }
  3916. else return new Dom7([]);
  3917. },
  3918. nextAll: function (selector) {
  3919. var nextEls = [];
  3920. var el = this[0];
  3921. if (!el) return new Dom7([]);
  3922. while (el.nextElementSibling) {
  3923. var next = el.nextElementSibling;
  3924. if (selector) {
  3925. if($(next).is(selector)) nextEls.push(next);
  3926. }
  3927. else nextEls.push(next);
  3928. el = next;
  3929. }
  3930. return new Dom7(nextEls);
  3931. },
  3932. prev: function (selector) {
  3933. if (this.length > 0) {
  3934. if (selector) {
  3935. if (this[0].previousElementSibling && $(this[0].previousElementSibling).is(selector)) return new Dom7([this[0].previousElementSibling]);
  3936. else return new Dom7([]);
  3937. }
  3938. else {
  3939. if (this[0].previousElementSibling) return new Dom7([this[0].previousElementSibling]);
  3940. else return new Dom7([]);
  3941. }
  3942. }
  3943. else return new Dom7([]);
  3944. },
  3945. prevAll: function (selector) {
  3946. var prevEls = [];
  3947. var el = this[0];
  3948. if (!el) return new Dom7([]);
  3949. while (el.previousElementSibling) {
  3950. var prev = el.previousElementSibling;
  3951. if (selector) {
  3952. if($(prev).is(selector)) prevEls.push(prev);
  3953. }
  3954. else prevEls.push(prev);
  3955. el = prev;
  3956. }
  3957. return new Dom7(prevEls);
  3958. },
  3959. parent: function (selector) {
  3960. var parents = [];
  3961. for (var i = 0; i < this.length; i++) {
  3962. if (selector) {
  3963. if ($(this[i].parentNode).is(selector)) parents.push(this[i].parentNode);
  3964. }
  3965. else {
  3966. parents.push(this[i].parentNode);
  3967. }
  3968. }
  3969. return $($.unique(parents));
  3970. },
  3971. parents: function (selector) {
  3972. var parents = [];
  3973. for (var i = 0; i < this.length; i++) {
  3974. var parent = this[i].parentNode;
  3975. while (parent) {
  3976. if (selector) {
  3977. if ($(parent).is(selector)) parents.push(parent);
  3978. }
  3979. else {
  3980. parents.push(parent);
  3981. }
  3982. parent = parent.parentNode;
  3983. }
  3984. }
  3985. return $($.unique(parents));
  3986. },
  3987. find : function (selector) {
  3988. var foundElements = [];
  3989. for (var i = 0; i < this.length; i++) {
  3990. var found = this[i].querySelectorAll(selector);
  3991. for (var j = 0; j < found.length; j++) {
  3992. foundElements.push(found[j]);
  3993. }
  3994. }
  3995. return new Dom7(foundElements);
  3996. },
  3997. children: function (selector) {
  3998. var children = [];
  3999. for (var i = 0; i < this.length; i++) {
  4000. var childNodes = this[i].childNodes;
  4001. for (var j = 0; j < childNodes.length; j++) {
  4002. if (!selector) {
  4003. if (childNodes[j].nodeType === 1) children.push(childNodes[j]);
  4004. }
  4005. else {
  4006. if (childNodes[j].nodeType === 1 && $(childNodes[j]).is(selector)) children.push(childNodes[j]);
  4007. }
  4008. }
  4009. }
  4010. return new Dom7($.unique(children));
  4011. },
  4012. remove: function () {
  4013. for (var i = 0; i < this.length; i++) {
  4014. if (this[i].parentNode) this[i].parentNode.removeChild(this[i]);
  4015. }
  4016. return this;
  4017. },
  4018. add: function () {
  4019. var dom = this;
  4020. var i, j;
  4021. for (i = 0; i < arguments.length; i++) {
  4022. var toAdd = $(arguments[i]);
  4023. for (j = 0; j < toAdd.length; j++) {
  4024. dom[dom.length] = toAdd[j];
  4025. dom.length++;
  4026. }
  4027. }
  4028. return dom;
  4029. }
  4030. };
  4031. $.fn = Dom7.prototype;
  4032. $.unique = function (arr) {
  4033. var unique = [];
  4034. for (var i = 0; i < arr.length; i++) {
  4035. if (unique.indexOf(arr[i]) === -1) unique.push(arr[i]);
  4036. }
  4037. return unique;
  4038. };
  4039. return $;
  4040. })();
  4041. /*===========================
  4042. Get Dom libraries
  4043. ===========================*/
  4044. var swiperDomPlugins = ['jQuery', 'Zepto', 'Dom7'];
  4045. for (var i = 0; i < swiperDomPlugins.length; i++) {
  4046. if (window[swiperDomPlugins[i]]) {
  4047. addLibraryPlugin(window[swiperDomPlugins[i]]);
  4048. }
  4049. }
  4050. // Required DOM Plugins
  4051. var domLib;
  4052. if (typeof Dom7 === 'undefined') {
  4053. domLib = window.Dom7 || window.Zepto || window.jQuery;
  4054. }
  4055. else {
  4056. domLib = Dom7;
  4057. }
  4058. /*===========================
  4059. Add .swiper plugin from Dom libraries
  4060. ===========================*/
  4061. function addLibraryPlugin(lib) {
  4062. lib.fn.swiper = function (params) {
  4063. var firstInstance;
  4064. lib(this).each(function () {
  4065. var s = new Swiper(this, params);
  4066. if (!firstInstance) firstInstance = s;
  4067. });
  4068. return firstInstance;
  4069. };
  4070. }
  4071. if (domLib) {
  4072. if (!('transitionEnd' in domLib.fn)) {
  4073. domLib.fn.transitionEnd = function (callback) {
  4074. var events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
  4075. i, j, dom = this;
  4076. function fireCallBack(e) {
  4077. /*jshint validthis:true */
  4078. if (e.target !== this) return;
  4079. callback.call(this, e);
  4080. for (i = 0; i < events.length; i++) {
  4081. dom.off(events[i], fireCallBack);
  4082. }
  4083. }
  4084. if (callback) {
  4085. for (i = 0; i < events.length; i++) {
  4086. dom.on(events[i], fireCallBack);
  4087. }
  4088. }
  4089. return this;
  4090. };
  4091. }
  4092. if (!('transform' in domLib.fn)) {
  4093. domLib.fn.transform = function (transform) {
  4094. for (var i = 0; i < this.length; i++) {
  4095. var elStyle = this[i].style;
  4096. elStyle.webkitTransform = elStyle.MsTransform = elStyle.msTransform = elStyle.MozTransform = elStyle.OTransform = elStyle.transform = transform;
  4097. }
  4098. return this;
  4099. };
  4100. }
  4101. if (!('transition' in domLib.fn)) {
  4102. domLib.fn.transition = function (duration) {
  4103. if (typeof duration !== 'string') {
  4104. duration = duration + 'ms';
  4105. }
  4106. for (var i = 0; i < this.length; i++) {
  4107. var elStyle = this[i].style;
  4108. elStyle.webkitTransitionDuration = elStyle.MsTransitionDuration = elStyle.msTransitionDuration = elStyle.MozTransitionDuration = elStyle.OTransitionDuration = elStyle.transitionDuration = duration;
  4109. }
  4110. return this;
  4111. };
  4112. }
  4113. }
  4114. window.Swiper = Swiper;
  4115. })();
  4116. /*===========================
  4117. Swiper AMD Export
  4118. ===========================*/
  4119. if (typeof(module) !== 'undefined')
  4120. {
  4121. module.exports = window.Swiper;
  4122. }
  4123. else if (typeof define === 'function' && define.amd) {
  4124. define([], function () {
  4125. 'use strict';
  4126. return window.Swiper;
  4127. });
  4128. }