swiper.js 164 KB

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