1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376 |
- /*!
- * =====================================================
- * SUI Mobile - http://m.sui.taobao.org/
- *
- * =====================================================
- */
- /*===========================
- Swiper
- ===========================*/
- /* global WebKitCSSMatrix:true */
- /* global Modernizr:true */
- /* global DocumentTouch:true */
- +function($){
- "use strict";
- var Swiper = function (container, params) {
- // if (!(this instanceof Swiper)) return new Swiper(container, params);
- var defaults = this.defaults;
- var initalVirtualTranslate = params && params.virtualTranslate;
- params = params || {};
- for (var def in defaults) {
- if (typeof params[def] === 'undefined') {
- params[def] = defaults[def];
- }
- else if (typeof params[def] === 'object') {
- for (var deepDef in defaults[def]) {
- if (typeof params[def][deepDef] === 'undefined') {
- params[def][deepDef] = defaults[def][deepDef];
- }
- }
- }
- }
- // Swiper
- var s = this;
- // Params
- s.params = params;
- // Classname
- s.classNames = [];
- // Export it to Swiper instance
- s.$ = $;
- /*=========================
- Preparation - Define Container, Wrapper and Pagination
- ===========================*/
- s.container = $(container);
- if (s.container.length === 0) return;
- if (s.container.length > 1) {
- s.container.each(function () {
- new $.Swiper(this, params);
- });
- return;
- }
- // Save instance in container HTML Element and in data
- s.container[0].swiper = s;
- s.container.data('swiper', s);
- s.classNames.push('swiper-container-' + s.params.direction);
- if (s.params.freeMode) {
- s.classNames.push('swiper-container-free-mode');
- }
- if (!s.support.flexbox) {
- s.classNames.push('swiper-container-no-flexbox');
- s.params.slidesPerColumn = 1;
- }
- // Enable slides progress when required
- if (s.params.parallax || s.params.watchSlidesVisibility) {
- s.params.watchSlidesProgress = true;
- }
- // Coverflow / 3D
- if (['cube', 'coverflow'].indexOf(s.params.effect) >= 0) {
- if (s.support.transforms3d) {
- s.params.watchSlidesProgress = true;
- s.classNames.push('swiper-container-3d');
- }
- else {
- s.params.effect = 'slide';
- }
- }
- if (s.params.effect !== 'slide') {
- s.classNames.push('swiper-container-' + s.params.effect);
- }
- if (s.params.effect === 'cube') {
- s.params.resistanceRatio = 0;
- s.params.slidesPerView = 1;
- s.params.slidesPerColumn = 1;
- s.params.slidesPerGroup = 1;
- s.params.centeredSlides = false;
- s.params.spaceBetween = 0;
- s.params.virtualTranslate = true;
- s.params.setWrapperSize = false;
- }
- if (s.params.effect === 'fade') {
- s.params.slidesPerView = 1;
- s.params.slidesPerColumn = 1;
- s.params.slidesPerGroup = 1;
- s.params.watchSlidesProgress = true;
- s.params.spaceBetween = 0;
- if (typeof initalVirtualTranslate === 'undefined') {
- s.params.virtualTranslate = true;
- }
- }
- // Grab Cursor
- if (s.params.grabCursor && s.support.touch) {
- s.params.grabCursor = false;
- }
- // Wrapper
- s.wrapper = s.container.children('.' + s.params.wrapperClass);
- // Pagination
- if (s.params.pagination) {
- s.paginationContainer = $(s.params.pagination);
- if (s.params.paginationClickable) {
- s.paginationContainer.addClass('swiper-pagination-clickable');
- }
- }
- // Is Horizontal
- function isH() {
- return s.params.direction === 'horizontal';
- }
- // RTL
- s.rtl = isH() && (s.container[0].dir.toLowerCase() === 'rtl' || s.container.css('direction') === 'rtl');
- if (s.rtl) {
- s.classNames.push('swiper-container-rtl');
- }
- // Wrong RTL support
- if (s.rtl) {
- s.wrongRTL = s.wrapper.css('display') === '-webkit-box';
- }
- // Columns
- if (s.params.slidesPerColumn > 1) {
- s.classNames.push('swiper-container-multirow');
- }
- // Check for Android
- if (s.device.android) {
- s.classNames.push('swiper-container-android');
- }
- // Add classes
- s.container.addClass(s.classNames.join(' '));
- // Translate
- s.translate = 0;
- // Progress
- s.progress = 0;
- // Velocity
- s.velocity = 0;
- // Locks, unlocks
- s.lockSwipeToNext = function () {
- s.params.allowSwipeToNext = false;
- };
- s.lockSwipeToPrev = function () {
- s.params.allowSwipeToPrev = false;
- };
- s.lockSwipes = function () {
- s.params.allowSwipeToNext = s.params.allowSwipeToPrev = false;
- };
- s.unlockSwipeToNext = function () {
- s.params.allowSwipeToNext = true;
- };
- s.unlockSwipeToPrev = function () {
- s.params.allowSwipeToPrev = true;
- };
- s.unlockSwipes = function () {
- s.params.allowSwipeToNext = s.params.allowSwipeToPrev = true;
- };
- /*=========================
- Set grab cursor
- ===========================*/
- if (s.params.grabCursor) {
- s.container[0].style.cursor = 'move';
- s.container[0].style.cursor = '-webkit-grab';
- s.container[0].style.cursor = '-moz-grab';
- s.container[0].style.cursor = 'grab';
- }
- /*=========================
- Update on Images Ready
- ===========================*/
- s.imagesToLoad = [];
- s.imagesLoaded = 0;
- s.loadImage = function (imgElement, src, checkForComplete, callback) {
- var image;
- function onReady () {
- if (callback) callback();
- }
- if (!imgElement.complete || !checkForComplete) {
- if (src) {
- image = new Image();
- image.onload = onReady;
- image.onerror = onReady;
- image.src = src;
- } else {
- onReady();
- }
- } else {//image already loaded...
- onReady();
- }
- };
- s.preloadImages = function () {
- s.imagesToLoad = s.container.find('img');
- function _onReady() {
- if (typeof s === 'undefined' || s === null) return;
- if (s.imagesLoaded !== undefined) s.imagesLoaded++;
- if (s.imagesLoaded === s.imagesToLoad.length) {
- if (s.params.updateOnImagesReady) s.update();
- s.emit('onImagesReady', s);
- }
- }
- for (var i = 0; i < s.imagesToLoad.length; i++) {
- s.loadImage(s.imagesToLoad[i], (s.imagesToLoad[i].currentSrc || s.imagesToLoad[i].getAttribute('src')), true, _onReady);
- }
- };
- /*=========================
- Autoplay
- ===========================*/
- s.autoplayTimeoutId = undefined;
- s.autoplaying = false;
- s.autoplayPaused = false;
- function autoplay() {
- s.autoplayTimeoutId = setTimeout(function () {
- if (s.params.loop) {
- s.fixLoop();
- s._slideNext();
- }
- else {
- if (!s.isEnd) {
- s._slideNext();
- }
- else {
- if (!params.autoplayStopOnLast) {
- s._slideTo(0);
- }
- else {
- s.stopAutoplay();
- }
- }
- }
- }, s.params.autoplay);
- }
- s.startAutoplay = function () {
- if (typeof s.autoplayTimeoutId !== 'undefined') return false;
- if (!s.params.autoplay) return false;
- if (s.autoplaying) return false;
- s.autoplaying = true;
- s.emit('onAutoplayStart', s);
- autoplay();
- };
- s.stopAutoplay = function () {
- if (!s.autoplayTimeoutId) return;
- if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
- s.autoplaying = false;
- s.autoplayTimeoutId = undefined;
- s.emit('onAutoplayStop', s);
- };
- s.pauseAutoplay = function (speed) {
- if (s.autoplayPaused) return;
- if (s.autoplayTimeoutId) clearTimeout(s.autoplayTimeoutId);
- s.autoplayPaused = true;
- if (speed === 0) {
- s.autoplayPaused = false;
- autoplay();
- }
- else {
- s.wrapper.transitionEnd(function () {
- s.autoplayPaused = false;
- if (!s.autoplaying) {
- s.stopAutoplay();
- }
- else {
- autoplay();
- }
- });
- }
- };
- /*=========================
- Min/Max Translate
- ===========================*/
- s.minTranslate = function () {
- return (-s.snapGrid[0]);
- };
- s.maxTranslate = function () {
- return (-s.snapGrid[s.snapGrid.length - 1]);
- };
- /*=========================
- Slider/slides sizes
- ===========================*/
- s.updateContainerSize = function () {
- s.width = s.container[0].clientWidth;
- s.height = s.container[0].clientHeight;
- s.size = isH() ? s.width : s.height;
- };
- s.updateSlidesSize = function () {
- s.slides = s.wrapper.children('.' + s.params.slideClass);
- s.snapGrid = [];
- s.slidesGrid = [];
- s.slidesSizesGrid = [];
- var spaceBetween = s.params.spaceBetween,
- slidePosition = 0,
- i,
- prevSlideSize = 0,
- index = 0;
- if (typeof spaceBetween === 'string' && spaceBetween.indexOf('%') >= 0) {
- spaceBetween = parseFloat(spaceBetween.replace('%', '')) / 100 * s.size;
- }
- s.virtualSize = -spaceBetween;
- // reset margins
- if (s.rtl) s.slides.css({marginLeft: '', marginTop: ''});
- else s.slides.css({marginRight: '', marginBottom: ''});
- var slidesNumberEvenToRows;
- if (s.params.slidesPerColumn > 1) {
- if (Math.floor(s.slides.length / s.params.slidesPerColumn) === s.slides.length / s.params.slidesPerColumn) {
- slidesNumberEvenToRows = s.slides.length;
- }
- else {
- slidesNumberEvenToRows = Math.ceil(s.slides.length / s.params.slidesPerColumn) * s.params.slidesPerColumn;
- }
- }
- // Calc slides
- var slideSize;
- for (i = 0; i < s.slides.length; i++) {
- slideSize = 0;
- var slide = s.slides.eq(i);
- if (s.params.slidesPerColumn > 1) {
- // Set slides order
- var newSlideOrderIndex;
- var column, row;
- var slidesPerColumn = s.params.slidesPerColumn;
- var slidesPerRow;
- if (s.params.slidesPerColumnFill === 'column') {
- column = Math.floor(i / slidesPerColumn);
- row = i - column * slidesPerColumn;
- newSlideOrderIndex = column + row * slidesNumberEvenToRows / slidesPerColumn;
- slide
- .css({
- '-webkit-box-ordinal-group': newSlideOrderIndex,
- '-moz-box-ordinal-group': newSlideOrderIndex,
- '-ms-flex-order': newSlideOrderIndex,
- '-webkit-order': newSlideOrderIndex,
- 'order': newSlideOrderIndex
- });
- }
- else {
- slidesPerRow = slidesNumberEvenToRows / slidesPerColumn;
- row = Math.floor(i / slidesPerRow);
- column = i - row * slidesPerRow;
- }
- slide
- .css({
- 'margin-top': (row !== 0 && s.params.spaceBetween) && (s.params.spaceBetween + 'px')
- })
- .attr('data-swiper-column', column)
- .attr('data-swiper-row', row);
- }
- if (slide.css('display') === 'none') continue;
- if (s.params.slidesPerView === 'auto') {
- slideSize = isH() ? slide.outerWidth(true) : slide.outerHeight(true);
- }
- else {
- slideSize = (s.size - (s.params.slidesPerView - 1) * spaceBetween) / s.params.slidesPerView;
- if (isH()) {
- s.slides[i].style.width = slideSize + 'px';
- }
- else {
- s.slides[i].style.height = slideSize + 'px';
- }
- }
- s.slides[i].swiperSlideSize = slideSize;
- s.slidesSizesGrid.push(slideSize);
- if (s.params.centeredSlides) {
- slidePosition = slidePosition + slideSize / 2 + prevSlideSize / 2 + spaceBetween;
- if (i === 0) slidePosition = slidePosition - s.size / 2 - spaceBetween;
- if (Math.abs(slidePosition) < 1 / 1000) slidePosition = 0;
- if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
- s.slidesGrid.push(slidePosition);
- }
- else {
- if ((index) % s.params.slidesPerGroup === 0) s.snapGrid.push(slidePosition);
- s.slidesGrid.push(slidePosition);
- slidePosition = slidePosition + slideSize + spaceBetween;
- }
- s.virtualSize += slideSize + spaceBetween;
- prevSlideSize = slideSize;
- index ++;
- }
- s.virtualSize = Math.max(s.virtualSize, s.size);
- var newSlidesGrid;
- if (
- s.rtl && s.wrongRTL && (s.params.effect === 'slide' || s.params.effect === 'coverflow')) {
- s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
- }
- if (!s.support.flexbox || s.params.setWrapperSize) {
- if (isH()) s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
- else s.wrapper.css({height: s.virtualSize + s.params.spaceBetween + 'px'});
- }
- if (s.params.slidesPerColumn > 1) {
- s.virtualSize = (slideSize + s.params.spaceBetween) * slidesNumberEvenToRows;
- s.virtualSize = Math.ceil(s.virtualSize / s.params.slidesPerColumn) - s.params.spaceBetween;
- s.wrapper.css({width: s.virtualSize + s.params.spaceBetween + 'px'});
- if (s.params.centeredSlides) {
- newSlidesGrid = [];
- for (i = 0; i < s.snapGrid.length; i++) {
- if (s.snapGrid[i] < s.virtualSize + s.snapGrid[0]) newSlidesGrid.push(s.snapGrid[i]);
- }
- s.snapGrid = newSlidesGrid;
- }
- }
- // Remove last grid elements depending on width
- if (!s.params.centeredSlides) {
- newSlidesGrid = [];
- for (i = 0; i < s.snapGrid.length; i++) {
- if (s.snapGrid[i] <= s.virtualSize - s.size) {
- newSlidesGrid.push(s.snapGrid[i]);
- }
- }
- s.snapGrid = newSlidesGrid;
- if (Math.floor(s.virtualSize - s.size) > Math.floor(s.snapGrid[s.snapGrid.length - 1])) {
- s.snapGrid.push(s.virtualSize - s.size);
- }
- }
- if (s.snapGrid.length === 0) s.snapGrid = [0];
- if (s.params.spaceBetween !== 0) {
- if (isH()) {
- if (s.rtl) s.slides.css({marginLeft: spaceBetween + 'px'});
- else s.slides.css({marginRight: spaceBetween + 'px'});
- }
- else s.slides.css({marginBottom: spaceBetween + 'px'});
- }
- if (s.params.watchSlidesProgress) {
- s.updateSlidesOffset();
- }
- };
- s.updateSlidesOffset = function () {
- for (var i = 0; i < s.slides.length; i++) {
- s.slides[i].swiperSlideOffset = isH() ? s.slides[i].offsetLeft : s.slides[i].offsetTop;
- }
- };
- /*=========================
- Slider/slides progress
- ===========================*/
- s.updateSlidesProgress = function (translate) {
- if (typeof translate === 'undefined') {
- translate = s.translate || 0;
- }
- if (s.slides.length === 0) return;
- if (typeof s.slides[0].swiperSlideOffset === 'undefined') s.updateSlidesOffset();
- var offsetCenter = s.params.centeredSlides ? -translate + s.size / 2 : -translate;
- if (s.rtl) offsetCenter = s.params.centeredSlides ? translate - s.size / 2 : translate;
- // Visible Slides
- s.slides.removeClass(s.params.slideVisibleClass);
- for (var i = 0; i < s.slides.length; i++) {
- var slide = s.slides[i];
- var slideCenterOffset = (s.params.centeredSlides === true) ? slide.swiperSlideSize / 2 : 0;
- var slideProgress = (offsetCenter - slide.swiperSlideOffset - slideCenterOffset) / (slide.swiperSlideSize + s.params.spaceBetween);
- if (s.params.watchSlidesVisibility) {
- var slideBefore = -(offsetCenter - slide.swiperSlideOffset - slideCenterOffset);
- var slideAfter = slideBefore + s.slidesSizesGrid[i];
- var isVisible =
- (slideBefore >= 0 && slideBefore < s.size) ||
- (slideAfter > 0 && slideAfter <= s.size) ||
- (slideBefore <= 0 && slideAfter >= s.size);
- if (isVisible) {
- s.slides.eq(i).addClass(s.params.slideVisibleClass);
- }
- }
- slide.progress = s.rtl ? -slideProgress : slideProgress;
- }
- };
- s.updateProgress = function (translate) {
- if (typeof translate === 'undefined') {
- translate = s.translate || 0;
- }
- var translatesDiff = s.maxTranslate() - s.minTranslate();
- if (translatesDiff === 0) {
- s.progress = 0;
- s.isBeginning = s.isEnd = true;
- }
- else {
- s.progress = (translate - s.minTranslate()) / (translatesDiff);
- s.isBeginning = s.progress <= 0;
- s.isEnd = s.progress >= 1;
- }
- if (s.isBeginning) s.emit('onReachBeginning', s);
- if (s.isEnd) s.emit('onReachEnd', s);
- if (s.params.watchSlidesProgress) s.updateSlidesProgress(translate);
- s.emit('onProgress', s, s.progress);
- };
- s.updateActiveIndex = function () {
- var translate = s.rtl ? s.translate : -s.translate;
- var newActiveIndex, i, snapIndex;
- for (i = 0; i < s.slidesGrid.length; i ++) {
- if (typeof s.slidesGrid[i + 1] !== 'undefined') {
- if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1] - (s.slidesGrid[i + 1] - s.slidesGrid[i]) / 2) {
- newActiveIndex = i;
- }
- else if (translate >= s.slidesGrid[i] && translate < s.slidesGrid[i + 1]) {
- newActiveIndex = i + 1;
- }
- }
- else {
- if (translate >= s.slidesGrid[i]) {
- newActiveIndex = i;
- }
- }
- }
- // Normalize slideIndex
- if (newActiveIndex < 0 || typeof newActiveIndex === 'undefined') newActiveIndex = 0;
- // for (i = 0; i < s.slidesGrid.length; i++) {
- // if (- translate >= s.slidesGrid[i]) {
- // newActiveIndex = i;
- // }
- // }
- snapIndex = Math.floor(newActiveIndex / s.params.slidesPerGroup);
- if (snapIndex >= s.snapGrid.length) snapIndex = s.snapGrid.length - 1;
- if (newActiveIndex === s.activeIndex) {
- return;
- }
- s.snapIndex = snapIndex;
- s.previousIndex = s.activeIndex;
- s.activeIndex = newActiveIndex;
- s.updateClasses();
- };
- /*=========================
- Classes
- ===========================*/
- s.updateClasses = function () {
- s.slides.removeClass(s.params.slideActiveClass + ' ' + s.params.slideNextClass + ' ' + s.params.slidePrevClass);
- var activeSlide = s.slides.eq(s.activeIndex);
- // Active classes
- activeSlide.addClass(s.params.slideActiveClass);
- activeSlide.next('.' + s.params.slideClass).addClass(s.params.slideNextClass);
- activeSlide.prev('.' + s.params.slideClass).addClass(s.params.slidePrevClass);
- // Pagination
- if (s.bullets && s.bullets.length > 0) {
- s.bullets.removeClass(s.params.bulletActiveClass);
- var bulletIndex;
- if (s.params.loop) {
- bulletIndex = Math.ceil(s.activeIndex - s.loopedSlides)/s.params.slidesPerGroup;
- if (bulletIndex > s.slides.length - 1 - s.loopedSlides * 2) {
- bulletIndex = bulletIndex - (s.slides.length - s.loopedSlides * 2);
- }
- if (bulletIndex > s.bullets.length - 1) bulletIndex = bulletIndex - s.bullets.length;
- }
- else {
- if (typeof s.snapIndex !== 'undefined') {
- bulletIndex = s.snapIndex;
- }
- else {
- bulletIndex = s.activeIndex || 0;
- }
- }
- if (s.paginationContainer.length > 1) {
- s.bullets.each(function () {
- if ($(this).index() === bulletIndex) $(this).addClass(s.params.bulletActiveClass);
- });
- }
- else {
- s.bullets.eq(bulletIndex).addClass(s.params.bulletActiveClass);
- }
- }
- // Next/active buttons
- if (!s.params.loop) {
- if (s.params.prevButton) {
- if (s.isBeginning) {
- $(s.params.prevButton).addClass(s.params.buttonDisabledClass);
- if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.prevButton));
- }
- else {
- $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
- if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.prevButton));
- }
- }
- if (s.params.nextButton) {
- if (s.isEnd) {
- $(s.params.nextButton).addClass(s.params.buttonDisabledClass);
- if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.nextButton));
- }
- else {
- $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
- if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.nextButton));
- }
- }
- }
- };
- /*=========================
- Pagination
- ===========================*/
- s.updatePagination = function () {
- if (!s.params.pagination) return;
- if (s.paginationContainer && s.paginationContainer.length > 0) {
- var bulletsHTML = '';
- var numberOfBullets = s.params.loop ? Math.ceil((s.slides.length - s.loopedSlides * 2) / s.params.slidesPerGroup) : s.snapGrid.length;
- for (var i = 0; i < numberOfBullets; i++) {
- if (s.params.paginationBulletRender) {
- bulletsHTML += s.params.paginationBulletRender(i, s.params.bulletClass);
- }
- else {
- bulletsHTML += '<span class="' + s.params.bulletClass + '"></span>';
- }
- }
- s.paginationContainer.html(bulletsHTML);
- s.bullets = s.paginationContainer.find('.' + s.params.bulletClass);
- }
- };
- /*=========================
- Common update method
- ===========================*/
- s.update = function (updateTranslate) {
- s.updateContainerSize();
- s.updateSlidesSize();
- s.updateProgress();
- s.updatePagination();
- s.updateClasses();
- if (s.params.scrollbar && s.scrollbar) {
- s.scrollbar.set();
- }
- function forceSetTranslate() {
- newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
- s.setWrapperTranslate(newTranslate);
- s.updateActiveIndex();
- s.updateClasses();
- }
- if (updateTranslate) {
- var translated, newTranslate;
- if (s.params.freeMode) {
- forceSetTranslate();
- }
- else {
- if (s.params.slidesPerView === 'auto' && s.isEnd && !s.params.centeredSlides) {
- translated = s.slideTo(s.slides.length - 1, 0, false, true);
- }
- else {
- translated = s.slideTo(s.activeIndex, 0, false, true);
- }
- if (!translated) {
- forceSetTranslate();
- }
- }
- }
- };
- /*=========================
- Resize Handler
- ===========================*/
- s.onResize = function () {
- s.updateContainerSize();
- s.updateSlidesSize();
- s.updateProgress();
- if (s.params.slidesPerView === 'auto' || s.params.freeMode) s.updatePagination();
- if (s.params.scrollbar && s.scrollbar) {
- s.scrollbar.set();
- }
- if (s.params.freeMode) {
- var newTranslate = Math.min(Math.max(s.translate, s.maxTranslate()), s.minTranslate());
- s.setWrapperTranslate(newTranslate);
- s.updateActiveIndex();
- s.updateClasses();
- }
- else {
- s.updateClasses();
- if (s.params.slidesPerView === 'auto' && s.isEnd && !s.params.centeredSlides) {
- s.slideTo(s.slides.length - 1, 0, false, true);
- }
- else {
- s.slideTo(s.activeIndex, 0, false, true);
- }
- }
- };
- /*=========================
- Events
- ===========================*/
- //Define Touch Events
- var desktopEvents = ['mousedown', 'mousemove', 'mouseup'];
- if (window.navigator.pointerEnabled) desktopEvents = ['pointerdown', 'pointermove', 'pointerup'];
- else if (window.navigator.msPointerEnabled) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp'];
- s.touchEvents = {
- start : s.support.touch || !s.params.simulateTouch ? 'touchstart' : desktopEvents[0],
- move : s.support.touch || !s.params.simulateTouch ? 'touchmove' : desktopEvents[1],
- end : s.support.touch || !s.params.simulateTouch ? 'touchend' : desktopEvents[2]
- };
- // WP8 Touch Events Fix
- if (window.navigator.pointerEnabled || window.navigator.msPointerEnabled) {
- (s.params.touchEventsTarget === 'container' ? s.container : s.wrapper).addClass('swiper-wp8-' + s.params.direction);
- }
- // Attach/detach events
- s.initEvents = function (detach) {
- var actionDom = detach ? 'off' : 'on';
- var action = detach ? 'removeEventListener' : 'addEventListener';
- var touchEventsTarget = s.params.touchEventsTarget === 'container' ? s.container[0] : s.wrapper[0];
- var target = s.support.touch ? touchEventsTarget : document;
- var moveCapture = s.params.nested ? true : false;
- //Touch Events
- if (s.browser.ie) {
- touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
- target[action](s.touchEvents.move, s.onTouchMove, moveCapture);
- target[action](s.touchEvents.end, s.onTouchEnd, false);
- }
- else {
- if (s.support.touch) {
- touchEventsTarget[action](s.touchEvents.start, s.onTouchStart, false);
- touchEventsTarget[action](s.touchEvents.move, s.onTouchMove, moveCapture);
- touchEventsTarget[action](s.touchEvents.end, s.onTouchEnd, false);
- }
- if (params.simulateTouch && !s.device.ios && !s.device.android) {
- touchEventsTarget[action]('mousedown', s.onTouchStart, false);
- target[action]('mousemove', s.onTouchMove, moveCapture);
- target[action]('mouseup', s.onTouchEnd, false);
- }
- }
- window[action]('resize', s.onResize);
- // Next, Prev, Index
- if (s.params.nextButton) {
- $(s.params.nextButton)[actionDom]('click', s.onClickNext);
- if (s.params.a11y && s.a11y) $(s.params.nextButton)[actionDom]('keydown', s.a11y.onEnterKey);
- }
- if (s.params.prevButton) {
- $(s.params.prevButton)[actionDom]('click', s.onClickPrev);
- if (s.params.a11y && s.a11y) $(s.params.prevButton)[actionDom]('keydown', s.a11y.onEnterKey);
- }
- if (s.params.pagination && s.params.paginationClickable) {
- $(s.paginationContainer)[actionDom]('click', '.' + s.params.bulletClass, s.onClickIndex);
- }
- // Prevent Links Clicks
- if (s.params.preventClicks || s.params.preventClicksPropagation) touchEventsTarget[action]('click', s.preventClicks, true);
- };
- s.attachEvents = function () {
- s.initEvents();
- };
- s.detachEvents = function () {
- s.initEvents(true);
- };
- /*=========================
- Handle Clicks
- ===========================*/
- // Prevent Clicks
- s.allowClick = true;
- s.preventClicks = function (e) {
- if (!s.allowClick) {
- if (s.params.preventClicks) e.preventDefault();
- if (s.params.preventClicksPropagation) {
- e.stopPropagation();
- e.stopImmediatePropagation();
- }
- }
- };
- // Clicks
- s.onClickNext = function (e) {
- e.preventDefault();
- s.slideNext();
- };
- s.onClickPrev = function (e) {
- e.preventDefault();
- s.slidePrev();
- };
- s.onClickIndex = function (e) {
- e.preventDefault();
- var index = $(this).index() * s.params.slidesPerGroup;
- if (s.params.loop) index = index + s.loopedSlides;
- s.slideTo(index);
- };
- /*=========================
- Handle Touches
- ===========================*/
- function findElementInEvent(e, selector) {
- var el = $(e.target);
- if (!el.is(selector)) {
- if (typeof selector === 'string') {
- el = el.parents(selector);
- }
- else if (selector.nodeType) {
- var found;
- el.parents().each(function (index, _el) {
- if (_el === selector) found = selector;
- });
- if (!found) return undefined;
- else return selector;
- }
- }
- if (el.length === 0) {
- return undefined;
- }
- return el[0];
- }
- s.updateClickedSlide = function (e) {
- var slide = findElementInEvent(e, '.' + s.params.slideClass);
- if (slide) {
- s.clickedSlide = slide;
- s.clickedIndex = $(slide).index();
- }
- else {
- s.clickedSlide = undefined;
- s.clickedIndex = undefined;
- return;
- }
- if (s.params.slideToClickedSlide && s.clickedIndex !== undefined && s.clickedIndex !== s.activeIndex) {
- var slideToIndex = s.clickedIndex,
- realIndex;
- if (s.params.loop) {
- realIndex = $(s.clickedSlide).attr('data-swiper-slide-index');
- if (slideToIndex > s.slides.length - s.params.slidesPerView) {
- s.fixLoop();
- slideToIndex = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]').eq(0).index();
- setTimeout(function () {
- s.slideTo(slideToIndex);
- }, 0);
- }
- else if (slideToIndex < s.params.slidesPerView - 1) {
- s.fixLoop();
- var duplicatedSlides = s.wrapper.children('.' + s.params.slideClass + '[data-swiper-slide-index="' + realIndex + '"]');
- slideToIndex = duplicatedSlides.eq(duplicatedSlides.length - 1).index();
- setTimeout(function () {
- s.slideTo(slideToIndex);
- }, 0);
- }
- else {
- s.slideTo(slideToIndex);
- }
- }
- else {
- s.slideTo(slideToIndex);
- }
- }
- };
- var isTouched,
- isMoved,
- touchStartTime,
- isScrolling,
- currentTranslate,
- startTranslate,
- allowThresholdMove,
- // Form elements to match
- formElements = 'input, select, textarea, button',
- // Last click time
- lastClickTime = Date.now(), clickTimeout,
- //Velocities
- velocities = [],
- allowMomentumBounce;
- // Animating Flag
- s.animating = false;
- // Touches information
- s.touches = {
- startX: 0,
- startY: 0,
- currentX: 0,
- currentY: 0,
- diff: 0
- };
- // Touch handlers
- var isTouchEvent, startMoving;
- s.onTouchStart = function (e) {
- if (e.originalEvent) e = e.originalEvent;
- isTouchEvent = e.type === 'touchstart';
- if (!isTouchEvent && 'which' in e && e.which === 3) return;
- if (s.params.noSwiping && findElementInEvent(e, '.' + s.params.noSwipingClass)) {
- s.allowClick = true;
- return;
- }
- if (s.params.swipeHandler) {
- if (!findElementInEvent(e, s.params.swipeHandler)) return;
- }
- isTouched = true;
- isMoved = false;
- isScrolling = undefined;
- startMoving = undefined;
- s.touches.startX = s.touches.currentX = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
- s.touches.startY = s.touches.currentY = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
- touchStartTime = Date.now();
- s.allowClick = true;
- s.updateContainerSize();
- s.swipeDirection = undefined;
- if (s.params.threshold > 0) allowThresholdMove = false;
- if (e.type !== 'touchstart') {
- var preventDefault = true;
- if ($(e.target).is(formElements)) preventDefault = false;
- if (document.activeElement && $(document.activeElement).is(formElements)) {
- document.activeElement.blur();
- }
- if (preventDefault) {
- e.preventDefault();
- }
- }
- s.emit('onTouchStart', s, e);
- };
- s.onTouchMove = function (e) {
- if (e.originalEvent) e = e.originalEvent;
- if (isTouchEvent && e.type === 'mousemove') return;
- if (e.preventedByNestedSwiper) return;
- if (s.params.onlyExternal) {
- isMoved = true;
- s.allowClick = false;
- return;
- }
- if (isTouchEvent && document.activeElement) {
- if (e.target === document.activeElement && $(e.target).is(formElements)) {
- isMoved = true;
- s.allowClick = false;
- return;
- }
- }
- s.emit('onTouchMove', s, e);
- if (e.targetTouches && e.targetTouches.length > 1) return;
- s.touches.currentX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
- s.touches.currentY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
- if (typeof isScrolling === 'undefined') {
- var touchAngle = Math.atan2(Math.abs(s.touches.currentY - s.touches.startY), Math.abs(s.touches.currentX - s.touches.startX)) * 180 / Math.PI;
- isScrolling = isH() ? touchAngle > s.params.touchAngle : (90 - touchAngle > s.params.touchAngle);
- }
- if (isScrolling) {
- s.emit('onTouchMoveOpposite', s, e);
- }
- if (typeof startMoving === 'undefined' && s.browser.ieTouch) {
- if (s.touches.currentX !== s.touches.startX || s.touches.currentY !== s.touches.startY) {
- startMoving = true;
- }
- }
- if (!isTouched) return;
- if (isScrolling) {
- isTouched = false;
- return;
- }
- if (!startMoving && s.browser.ieTouch) {
- return;
- }
- s.allowClick = false;
- s.emit('onSliderMove', s, e);
- e.preventDefault();
- if (s.params.touchMoveStopPropagation && !s.params.nested) {
- e.stopPropagation();
- }
- if (!isMoved) {
- if (params.loop) {
- s.fixLoop();
- }
- startTranslate = s.getWrapperTranslate();
- s.setWrapperTransition(0);
- if (s.animating) {
- s.wrapper.trigger('webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd msTransitionEnd');
- }
- if (s.params.autoplay && s.autoplaying) {
- if (s.params.autoplayDisableOnInteraction) {
- s.stopAutoplay();
- }
- else {
- s.pauseAutoplay();
- }
- }
- allowMomentumBounce = false;
- //Grab Cursor
- if (s.params.grabCursor) {
- s.container[0].style.cursor = 'move';
- s.container[0].style.cursor = '-webkit-grabbing';
- s.container[0].style.cursor = '-moz-grabbin';
- s.container[0].style.cursor = 'grabbing';
- }
- }
- isMoved = true;
- var diff = s.touches.diff = isH() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
- diff = diff * s.params.touchRatio;
- if (s.rtl) diff = -diff;
- s.swipeDirection = diff > 0 ? 'prev' : 'next';
- currentTranslate = diff + startTranslate;
- var disableParentSwiper = true;
- if ((diff > 0 && currentTranslate > s.minTranslate())) {
- disableParentSwiper = false;
- if (s.params.resistance) currentTranslate = s.minTranslate() - 1 + Math.pow(-s.minTranslate() + startTranslate + diff, s.params.resistanceRatio);
- }
- else if (diff < 0 && currentTranslate < s.maxTranslate()) {
- disableParentSwiper = false;
- if (s.params.resistance) currentTranslate = s.maxTranslate() + 1 - Math.pow(s.maxTranslate() - startTranslate - diff, s.params.resistanceRatio);
- }
- if (disableParentSwiper) {
- e.preventedByNestedSwiper = true;
- }
- // Directions locks
- if (!s.params.allowSwipeToNext && s.swipeDirection === 'next' && currentTranslate < startTranslate) {
- currentTranslate = startTranslate;
- }
- if (!s.params.allowSwipeToPrev && s.swipeDirection === 'prev' && currentTranslate > startTranslate) {
- currentTranslate = startTranslate;
- }
- if (!s.params.followFinger) return;
- // Threshold
- if (s.params.threshold > 0) {
- if (Math.abs(diff) > s.params.threshold || allowThresholdMove) {
- if (!allowThresholdMove) {
- allowThresholdMove = true;
- s.touches.startX = s.touches.currentX;
- s.touches.startY = s.touches.currentY;
- currentTranslate = startTranslate;
- s.touches.diff = isH() ? s.touches.currentX - s.touches.startX : s.touches.currentY - s.touches.startY;
- return;
- }
- }
- else {
- currentTranslate = startTranslate;
- return;
- }
- }
- // Update active index in free mode
- if (s.params.freeMode || s.params.watchSlidesProgress) {
- s.updateActiveIndex();
- }
- if (s.params.freeMode) {
- //Velocity
- if (velocities.length === 0) {
- velocities.push({
- position: s.touches[isH() ? 'startX' : 'startY'],
- time: touchStartTime
- });
- }
- velocities.push({
- position: s.touches[isH() ? 'currentX' : 'currentY'],
- time: (new Date()).getTime()
- });
- }
- // Update progress
- s.updateProgress(currentTranslate);
- // Update translate
- s.setWrapperTranslate(currentTranslate);
- };
- s.onTouchEnd = function (e) {
- if (e.originalEvent) e = e.originalEvent;
- s.emit('onTouchEnd', s, e);
- if (!isTouched) return;
- //Return Grab Cursor
- if (s.params.grabCursor && isMoved && isTouched) {
- s.container[0].style.cursor = 'move';
- s.container[0].style.cursor = '-webkit-grab';
- s.container[0].style.cursor = '-moz-grab';
- s.container[0].style.cursor = 'grab';
- }
- // Time diff
- var touchEndTime = Date.now();
- var timeDiff = touchEndTime - touchStartTime;
- // Tap, doubleTap, Click
- if (s.allowClick) {
- s.updateClickedSlide(e);
- s.emit('onTap', s, e);
- if (timeDiff < 300 && (touchEndTime - lastClickTime) > 300) {
- if (clickTimeout) clearTimeout(clickTimeout);
- clickTimeout = setTimeout(function () {
- if (!s) return;
- if (s.params.paginationHide && s.paginationContainer.length > 0 && !$(e.target).hasClass(s.params.bulletClass)) {
- s.paginationContainer.toggleClass(s.params.paginationHiddenClass);
- }
- s.emit('onClick', s, e);
- }, 300);
- }
- if (timeDiff < 300 && (touchEndTime - lastClickTime) < 300) {
- if (clickTimeout) clearTimeout(clickTimeout);
- s.emit('onDoubleTap', s, e);
- }
- }
- lastClickTime = Date.now();
- setTimeout(function () {
- if (s && s.allowClick) s.allowClick = true;
- }, 0);
- if (!isTouched || !isMoved || !s.swipeDirection || s.touches.diff === 0 || currentTranslate === startTranslate) {
- isTouched = isMoved = false;
- return;
- }
- isTouched = isMoved = false;
- var currentPos;
- if (s.params.followFinger) {
- currentPos = s.rtl ? s.translate : -s.translate;
- }
- else {
- currentPos = -currentTranslate;
- }
- if (s.params.freeMode) {
- if (currentPos < -s.minTranslate()) {
- s.slideTo(s.activeIndex);
- return;
- }
- else if (currentPos > -s.maxTranslate()) {
- s.slideTo(s.slides.length - 1);
- return;
- }
- if (s.params.freeModeMomentum) {
- if (velocities.length > 1) {
- var lastMoveEvent = velocities.pop(), velocityEvent = velocities.pop();
- var distance = lastMoveEvent.position - velocityEvent.position;
- var time = lastMoveEvent.time - velocityEvent.time;
- s.velocity = distance / time;
- s.velocity = s.velocity / 2;
- if (Math.abs(s.velocity) < 0.02) {
- s.velocity = 0;
- }
- // this implies that the user stopped moving a finger then released.
- // There would be no events with distance zero, so the last event is stale.
- if (time > 150 || (new Date().getTime() - lastMoveEvent.time) > 300) {
- s.velocity = 0;
- }
- } else {
- s.velocity = 0;
- }
- velocities.length = 0;
- var momentumDuration = 1000 * s.params.freeModeMomentumRatio;
- var momentumDistance = s.velocity * momentumDuration;
- var newPosition = s.translate + momentumDistance;
- if (s.rtl) newPosition = - newPosition;
- var doBounce = false;
- var afterBouncePosition;
- var bounceAmount = Math.abs(s.velocity) * 20 * s.params.freeModeMomentumBounceRatio;
- if (newPosition < s.maxTranslate()) {
- if (s.params.freeModeMomentumBounce) {
- if (newPosition + s.maxTranslate() < -bounceAmount) {
- newPosition = s.maxTranslate() - bounceAmount;
- }
- afterBouncePosition = s.maxTranslate();
- doBounce = true;
- allowMomentumBounce = true;
- }
- else {
- newPosition = s.maxTranslate();
- }
- }
- if (newPosition > s.minTranslate()) {
- if (s.params.freeModeMomentumBounce) {
- if (newPosition - s.minTranslate() > bounceAmount) {
- newPosition = s.minTranslate() + bounceAmount;
- }
- afterBouncePosition = s.minTranslate();
- doBounce = true;
- allowMomentumBounce = true;
- }
- else {
- newPosition = s.minTranslate();
- }
- }
- //Fix duration
- if (s.velocity !== 0) {
- if (s.rtl) {
- momentumDuration = Math.abs((-newPosition - s.translate) / s.velocity);
- }
- else {
- momentumDuration = Math.abs((newPosition - s.translate) / s.velocity);
- }
- }
- if (s.params.freeModeMomentumBounce && doBounce) {
- s.updateProgress(afterBouncePosition);
- s.setWrapperTransition(momentumDuration);
- s.setWrapperTranslate(newPosition);
- s.onTransitionStart();
- s.animating = true;
- s.wrapper.transitionEnd(function () {
- if (!allowMomentumBounce) return;
- s.emit('onMomentumBounce', s);
- s.setWrapperTransition(s.params.speed);
- s.setWrapperTranslate(afterBouncePosition);
- s.wrapper.transitionEnd(function () {
- s.onTransitionEnd();
- });
- });
- } else if (s.velocity) {
- s.updateProgress(newPosition);
- s.setWrapperTransition(momentumDuration);
- s.setWrapperTranslate(newPosition);
- s.onTransitionStart();
- if (!s.animating) {
- s.animating = true;
- s.wrapper.transitionEnd(function () {
- s.onTransitionEnd();
- });
- }
- } else {
- s.updateProgress(newPosition);
- }
- s.updateActiveIndex();
- }
- if (!s.params.freeModeMomentum || timeDiff >= s.params.longSwipesMs) {
- s.updateProgress();
- s.updateActiveIndex();
- }
- return;
- }
- // Find current slide
- var i, stopIndex = 0, groupSize = s.slidesSizesGrid[0];
- for (i = 0; i < s.slidesGrid.length; i += s.params.slidesPerGroup) {
- if (typeof s.slidesGrid[i + s.params.slidesPerGroup] !== 'undefined') {
- if (currentPos >= s.slidesGrid[i] && currentPos < s.slidesGrid[i + s.params.slidesPerGroup]) {
- stopIndex = i;
- groupSize = s.slidesGrid[i + s.params.slidesPerGroup] - s.slidesGrid[i];
- }
- }
- else {
- if (currentPos >= s.slidesGrid[i]) {
- stopIndex = i;
- groupSize = s.slidesGrid[s.slidesGrid.length - 1] - s.slidesGrid[s.slidesGrid.length - 2];
- }
- }
- }
- // Find current slide size
- var ratio = (currentPos - s.slidesGrid[stopIndex]) / groupSize;
- if (timeDiff > s.params.longSwipesMs) {
- // Long touches
- if (!s.params.longSwipes) {
- s.slideTo(s.activeIndex);
- return;
- }
- if (s.swipeDirection === 'next') {
- if (ratio >= s.params.longSwipesRatio) s.slideTo(stopIndex + s.params.slidesPerGroup);
- else s.slideTo(stopIndex);
- }
- if (s.swipeDirection === 'prev') {
- if (ratio > (1 - s.params.longSwipesRatio)) s.slideTo(stopIndex + s.params.slidesPerGroup);
- else s.slideTo(stopIndex);
- }
- }
- else {
- // Short swipes
- if (!s.params.shortSwipes) {
- s.slideTo(s.activeIndex);
- return;
- }
- if (s.swipeDirection === 'next') {
- s.slideTo(stopIndex + s.params.slidesPerGroup);
- }
- if (s.swipeDirection === 'prev') {
- s.slideTo(stopIndex);
- }
- }
- };
- /*=========================
- Transitions
- ===========================*/
- s._slideTo = function (slideIndex, speed) {
- return s.slideTo(slideIndex, speed, true, true);
- };
- s.slideTo = function (slideIndex, speed, runCallbacks, internal) {
- if (typeof runCallbacks === 'undefined') runCallbacks = true;
- if (typeof slideIndex === 'undefined') slideIndex = 0;
- if (slideIndex < 0) slideIndex = 0;
- s.snapIndex = Math.floor(slideIndex / s.params.slidesPerGroup);
- if (s.snapIndex >= s.snapGrid.length) s.snapIndex = s.snapGrid.length - 1;
- var translate = - s.snapGrid[s.snapIndex];
- // Stop autoplay
- if (s.params.autoplay && s.autoplaying) {
- if (internal || !s.params.autoplayDisableOnInteraction) {
- s.pauseAutoplay(speed);
- }
- else {
- s.stopAutoplay();
- }
- }
- // Update progress
- s.updateProgress(translate);
- // Normalize slideIndex
- for (var i = 0; i < s.slidesGrid.length; i++) {
- if (- translate >= s.slidesGrid[i]) {
- slideIndex = i;
- }
- }
- if (typeof speed === 'undefined') speed = s.params.speed;
- s.previousIndex = s.activeIndex || 0;
- s.activeIndex = slideIndex;
- if (translate === s.translate) {
- s.updateClasses();
- return false;
- }
- s.onTransitionStart(runCallbacks);
- if (speed === 0) {
- s.setWrapperTransition(0);
- s.setWrapperTranslate(translate);
- s.onTransitionEnd(runCallbacks);
- }
- else {
- s.setWrapperTransition(speed);
- s.setWrapperTranslate(translate);
- if (!s.animating) {
- s.animating = true;
- s.wrapper.transitionEnd(function () {
- s.onTransitionEnd(runCallbacks);
- });
- }
- }
- s.updateClasses();
- return true;
- };
- s.onTransitionStart = function (runCallbacks) {
- if (typeof runCallbacks === 'undefined') runCallbacks = true;
- if (s.lazy) s.lazy.onTransitionStart();
- if (runCallbacks) {
- s.emit('onTransitionStart', s);
- if (s.activeIndex !== s.previousIndex) {
- s.emit('onSlideChangeStart', s);
- }
- }
- };
- s.onTransitionEnd = function (runCallbacks) {
- s.animating = false;
- s.setWrapperTransition(0);
- if (typeof runCallbacks === 'undefined') runCallbacks = true;
- if (s.lazy) s.lazy.onTransitionEnd();
- if (runCallbacks) {
- s.emit('onTransitionEnd', s);
- if (s.activeIndex !== s.previousIndex) {
- s.emit('onSlideChangeEnd', s);
- }
- }
- if (s.params.hashnav && s.hashnav) {
- s.hashnav.setHash();
- }
- };
- s.slideNext = function (runCallbacks, speed, internal) {
- if (s.params.loop) {
- if (s.animating) return false;
- s.fixLoop();
- return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
- }
- else return s.slideTo(s.activeIndex + s.params.slidesPerGroup, speed, runCallbacks, internal);
- };
- s._slideNext = function (speed) {
- return s.slideNext(true, speed, true);
- };
- s.slidePrev = function (runCallbacks, speed, internal) {
- if (s.params.loop) {
- if (s.animating) return false;
- s.fixLoop();
- return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
- }
- else return s.slideTo(s.activeIndex - 1, speed, runCallbacks, internal);
- };
- s._slidePrev = function (speed) {
- return s.slidePrev(true, speed, true);
- };
- s.slideReset = function (runCallbacks, speed) {
- return s.slideTo(s.activeIndex, speed, runCallbacks);
- };
- /*=========================
- Translate/transition helpers
- ===========================*/
- s.setWrapperTransition = function (duration, byController) {
- s.wrapper.transition(duration);
- if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
- s.effects[s.params.effect].setTransition(duration);
- }
- if (s.params.parallax && s.parallax) {
- s.parallax.setTransition(duration);
- }
- if (s.params.scrollbar && s.scrollbar) {
- s.scrollbar.setTransition(duration);
- }
- if (s.params.control && s.controller) {
- s.controller.setTransition(duration, byController);
- }
- s.emit('onSetTransition', s, duration);
- };
- s.setWrapperTranslate = function (translate, updateActiveIndex, byController) {
- var x = 0, y = 0, z = 0;
- if (isH()) {
- x = s.rtl ? -translate : translate;
- }
- else {
- y = translate;
- }
- if (!s.params.virtualTranslate) {
- if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)');
- else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)');
- }
- s.translate = isH() ? x : y;
- if (updateActiveIndex) s.updateActiveIndex();
- if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
- s.effects[s.params.effect].setTranslate(s.translate);
- }
- if (s.params.parallax && s.parallax) {
- s.parallax.setTranslate(s.translate);
- }
- if (s.params.scrollbar && s.scrollbar) {
- s.scrollbar.setTranslate(s.translate);
- }
- if (s.params.control && s.controller) {
- s.controller.setTranslate(s.translate, byController);
- }
- s.emit('onSetTranslate', s, s.translate);
- };
- s.getTranslate = function (el, axis) {
- var matrix, curTransform, curStyle, transformMatrix;
- // automatic axis detection
- if (typeof axis === 'undefined') {
- axis = 'x';
- }
- if (s.params.virtualTranslate) {
- return s.rtl ? -s.translate : s.translate;
- }
- curStyle = window.getComputedStyle(el, null);
- if (window.WebKitCSSMatrix) {
- // Some old versions of Webkit choke when 'none' is passed; pass
- // empty string instead in this case
- transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform === 'none' ? '' : curStyle.webkitTransform);
- }
- else {
- transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
- matrix = transformMatrix.toString().split(',');
- }
- if (axis === 'x') {
- //Latest Chrome and webkits Fix
- if (window.WebKitCSSMatrix)
- curTransform = transformMatrix.m41;
- //Crazy IE10 Matrix
- else if (matrix.length === 16)
- curTransform = parseFloat(matrix[12]);
- //Normal Browsers
- else
- curTransform = parseFloat(matrix[4]);
- }
- if (axis === 'y') {
- //Latest Chrome and webkits Fix
- if (window.WebKitCSSMatrix)
- curTransform = transformMatrix.m42;
- //Crazy IE10 Matrix
- else if (matrix.length === 16)
- curTransform = parseFloat(matrix[13]);
- //Normal Browsers
- else
- curTransform = parseFloat(matrix[5]);
- }
- if (s.rtl && curTransform) curTransform = -curTransform;
- return curTransform || 0;
- };
- s.getWrapperTranslate = function (axis) {
- if (typeof axis === 'undefined') {
- axis = isH() ? 'x' : 'y';
- }
- return s.getTranslate(s.wrapper[0], axis);
- };
- /*=========================
- Observer
- ===========================*/
- s.observers = [];
- function initObserver(target, options) {
- options = options || {};
- // create an observer instance
- var ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
- var observer = new ObserverFunc(function (mutations) {
- mutations.forEach(function (mutation) {
- s.onResize();
- s.emit('onObserverUpdate', s, mutation);
- });
- });
- observer.observe(target, {
- attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
- childList: typeof options.childList === 'undefined' ? true : options.childList,
- characterData: typeof options.characterData === 'undefined' ? true : options.characterData
- });
- s.observers.push(observer);
- }
- s.initObservers = function () {
- if (s.params.observeParents) {
- var containerParents = s.container.parents();
- for (var i = 0; i < containerParents.length; i++) {
- initObserver(containerParents[i]);
- }
- }
- // Observe container
- initObserver(s.container[0], {childList: false});
- // Observe wrapper
- initObserver(s.wrapper[0], {attributes: false});
- };
- s.disconnectObservers = function () {
- for (var i = 0; i < s.observers.length; i++) {
- s.observers[i].disconnect();
- }
- s.observers = [];
- };
- /*=========================
- Loop
- ===========================*/
- // Create looped slides
- s.createLoop = function () {
- // Remove duplicated slides
- s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
- var slides = s.wrapper.children('.' + s.params.slideClass);
- s.loopedSlides = parseInt(s.params.loopedSlides || s.params.slidesPerView, 10);
- s.loopedSlides = s.loopedSlides + s.params.loopAdditionalSlides;
- if (s.loopedSlides > slides.length) {
- s.loopedSlides = slides.length;
- }
- var prependSlides = [], appendSlides = [], i;
- slides.each(function (index, el) {
- var slide = $(this);
- if (index < s.loopedSlides) appendSlides.push(el);
- if (index < slides.length && index >= slides.length - s.loopedSlides) prependSlides.push(el);
- slide.attr('data-swiper-slide-index', index);
- });
- for (i = 0; i < appendSlides.length; i++) {
- s.wrapper.append($(appendSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
- }
- for (i = prependSlides.length - 1; i >= 0; i--) {
- s.wrapper.prepend($(prependSlides[i].cloneNode(true)).addClass(s.params.slideDuplicateClass));
- }
- };
- s.destroyLoop = function () {
- s.wrapper.children('.' + s.params.slideClass + '.' + s.params.slideDuplicateClass).remove();
- s.slides.removeAttr('data-swiper-slide-index');
- };
- s.fixLoop = function () {
- var newIndex;
- //Fix For Negative Oversliding
- if (s.activeIndex < s.loopedSlides) {
- newIndex = s.slides.length - s.loopedSlides * 3 + s.activeIndex;
- newIndex = newIndex + s.loopedSlides;
- s.slideTo(newIndex, 0, false, true);
- }
- //Fix For Positive Oversliding
- else if ((s.params.slidesPerView === 'auto' && s.activeIndex >= s.loopedSlides * 2) || (s.activeIndex > s.slides.length - s.params.slidesPerView * 2)) {
- newIndex = -s.slides.length + s.activeIndex + s.loopedSlides;
- newIndex = newIndex + s.loopedSlides;
- s.slideTo(newIndex, 0, false, true);
- }
- };
- /*=========================
- Append/Prepend/Remove Slides
- ===========================*/
- s.appendSlide = function (slides) {
- if (s.params.loop) {
- s.destroyLoop();
- }
- if (typeof slides === 'object' && slides.length) {
- for (var i = 0; i < slides.length; i++) {
- if (slides[i]) s.wrapper.append(slides[i]);
- }
- }
- else {
- s.wrapper.append(slides);
- }
- if (s.params.loop) {
- s.createLoop();
- }
- if (!(s.params.observer && s.support.observer)) {
- s.update(true);
- }
- };
- s.prependSlide = function (slides) {
- if (s.params.loop) {
- s.destroyLoop();
- }
- var newActiveIndex = s.activeIndex + 1;
- if (typeof slides === 'object' && slides.length) {
- for (var i = 0; i < slides.length; i++) {
- if (slides[i]) s.wrapper.prepend(slides[i]);
- }
- newActiveIndex = s.activeIndex + slides.length;
- }
- else {
- s.wrapper.prepend(slides);
- }
- if (s.params.loop) {
- s.createLoop();
- }
- if (!(s.params.observer && s.support.observer)) {
- s.update(true);
- }
- s.slideTo(newActiveIndex, 0, false);
- };
- s.removeSlide = function (slidesIndexes) {
- if (s.params.loop) {
- s.destroyLoop();
- }
- var newActiveIndex = s.activeIndex,
- indexToRemove;
- if (typeof slidesIndexes === 'object' && slidesIndexes.length) {
- for (var i = 0; i < slidesIndexes.length; i++) {
- indexToRemove = slidesIndexes[i];
- if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
- if (indexToRemove < newActiveIndex) newActiveIndex--;
- }
- newActiveIndex = Math.max(newActiveIndex, 0);
- }
- else {
- indexToRemove = slidesIndexes;
- if (s.slides[indexToRemove]) s.slides.eq(indexToRemove).remove();
- if (indexToRemove < newActiveIndex) newActiveIndex--;
- newActiveIndex = Math.max(newActiveIndex, 0);
- }
- if (!(s.params.observer && s.support.observer)) {
- s.update(true);
- }
- s.slideTo(newActiveIndex, 0, false);
- };
- s.removeAllSlides = function () {
- var slidesIndexes = [];
- for (var i = 0; i < s.slides.length; i++) {
- slidesIndexes.push(i);
- }
- s.removeSlide(slidesIndexes);
- };
- /*=========================
- Effects
- ===========================*/
- s.effects = {
- fade: {
- fadeIndex: null,
- setTranslate: function () {
- for (var i = 0; i < s.slides.length; i++) {
- var slide = s.slides.eq(i);
- var offset = slide[0].swiperSlideOffset;
- var tx = -offset;
- if (!s.params.virtualTranslate) tx = tx - s.translate;
- var ty = 0;
- if (!isH()) {
- ty = tx;
- tx = 0;
- }
- var slideOpacity = s.params.fade.crossFade ?
- Math.max(1 - Math.abs(slide[0].progress), 0) :
- 1 + Math.min(Math.max(slide[0].progress, -1), 0);
- if (slideOpacity > 0 && slideOpacity < 1) {
- s.effects.fade.fadeIndex = i;
- }
- slide
- .css({
- opacity: slideOpacity
- })
- .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px)');
- }
- },
- setTransition: function (duration) {
- s.slides.transition(duration);
- if (s.params.virtualTranslate && duration !== 0) {
- var fadeIndex = s.effects.fade.fadeIndex !== null ? s.effects.fade.fadeIndex : s.activeIndex;
- s.slides.eq(fadeIndex).transitionEnd(function () {
- var triggerEvents = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
- for (var i = 0; i < triggerEvents.length; i++) {
- s.wrapper.trigger(triggerEvents[i]);
- }
- });
- }
- }
- },
- cube: {
- setTranslate: function () {
- var wrapperRotate = 0, cubeShadow;
- if (s.params.cube.shadow) {
- if (isH()) {
- cubeShadow = s.wrapper.find('.swiper-cube-shadow');
- if (cubeShadow.length === 0) {
- cubeShadow = $('<div class="swiper-cube-shadow"></div>');
- s.wrapper.append(cubeShadow);
- }
- cubeShadow.css({height: s.width + 'px'});
- }
- else {
- cubeShadow = s.container.find('.swiper-cube-shadow');
- if (cubeShadow.length === 0) {
- cubeShadow = $('<div class="swiper-cube-shadow"></div>');
- s.container.append(cubeShadow);
- }
- }
- }
- for (var i = 0; i < s.slides.length; i++) {
- var slide = s.slides.eq(i);
- var slideAngle = i * 90;
- var round = Math.floor(slideAngle / 360);
- if (s.rtl) {
- slideAngle = -slideAngle;
- round = Math.floor(-slideAngle / 360);
- }
- var progress = Math.max(Math.min(slide[0].progress, 1), -1);
- var tx = 0, ty = 0, tz = 0;
- if (i % 4 === 0) {
- tx = - round * 4 * s.size;
- tz = 0;
- }
- else if ((i - 1) % 4 === 0) {
- tx = 0;
- tz = - round * 4 * s.size;
- }
- else if ((i - 2) % 4 === 0) {
- tx = s.size + round * 4 * s.size;
- tz = s.size;
- }
- else if ((i - 3) % 4 === 0) {
- tx = - s.size;
- tz = 3 * s.size + s.size * 4 * round;
- }
- if (s.rtl) {
- tx = -tx;
- }
- if (!isH()) {
- ty = tx;
- tx = 0;
- }
- var transform = 'rotateX(' + (isH() ? 0 : -slideAngle) + 'deg) rotateY(' + (isH() ? slideAngle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)';
- if (progress <= 1 && progress > -1) {
- wrapperRotate = i * 90 + progress * 90;
- if (s.rtl) wrapperRotate = -i * 90 - progress * 90;
- }
- slide.transform(transform);
- if (s.params.cube.slideShadows) {
- //Set shadows
- var shadowBefore = isH() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
- var shadowAfter = isH() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
- if (shadowBefore.length === 0) {
- shadowBefore = $('<div class="swiper-slide-shadow-' + (isH() ? 'left' : 'top') + '"></div>');
- slide.append(shadowBefore);
- }
- if (shadowAfter.length === 0) {
- shadowAfter = $('<div class="swiper-slide-shadow-' + (isH() ? 'right' : 'bottom') + '"></div>');
- slide.append(shadowAfter);
- }
- if (shadowBefore.length) shadowBefore[0].style.opacity = -slide[0].progress;
- if (shadowAfter.length) shadowAfter[0].style.opacity = slide[0].progress;
- }
- }
- s.wrapper.css({
- '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
- '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
- '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px',
- 'transform-origin': '50% 50% -' + (s.size / 2) + 'px'
- });
- if (s.params.cube.shadow) {
- if (isH()) {
- 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) + ')');
- }
- else {
- var shadowAngle = Math.abs(wrapperRotate) - Math.floor(Math.abs(wrapperRotate) / 90) * 90;
- var multiplier = 1.5 - (Math.sin(shadowAngle * 2 * Math.PI / 360) / 2 + Math.cos(shadowAngle * 2 * Math.PI / 360) / 2);
- var scale1 = s.params.cube.shadowScale,
- scale2 = s.params.cube.shadowScale / multiplier,
- offset = s.params.cube.shadowOffset;
- cubeShadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotateX(-90deg)');
- }
- }
- var zFactor = (s.isSafari || s.isUiWebView) ? (-s.size / 2) : 0;
- s.wrapper.transform('translate3d(0px,0,' + zFactor + 'px) rotateX(' + (isH() ? 0 : wrapperRotate) + 'deg) rotateY(' + (isH() ? -wrapperRotate : 0) + 'deg)');
- },
- setTransition: function (duration) {
- s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
- if (s.params.cube.shadow && !isH()) {
- s.container.find('.swiper-cube-shadow').transition(duration);
- }
- }
- },
- coverflow: {
- setTranslate: function () {
- var transform = s.translate;
- var center = isH() ? -transform + s.width / 2 : -transform + s.height / 2;
- var rotate = isH() ? s.params.coverflow.rotate: -s.params.coverflow.rotate;
- var translate = s.params.coverflow.depth;
- //Each slide offset from center
- for (var i = 0, length = s.slides.length; i < length; i++) {
- var slide = s.slides.eq(i);
- var slideSize = s.slidesSizesGrid[i];
- var slideOffset = slide[0].swiperSlideOffset;
- var offsetMultiplier = (center - slideOffset - slideSize / 2) / slideSize * s.params.coverflow.modifier;
- var rotateY = isH() ? rotate * offsetMultiplier : 0;
- var rotateX = isH() ? 0 : rotate * offsetMultiplier;
- // var rotateZ = 0
- var translateZ = -translate * Math.abs(offsetMultiplier);
- var translateY = isH() ? 0 : s.params.coverflow.stretch * (offsetMultiplier);
- var translateX = isH() ? s.params.coverflow.stretch * (offsetMultiplier) : 0;
- //Fix for ultra small values
- if (Math.abs(translateX) < 0.001) translateX = 0;
- if (Math.abs(translateY) < 0.001) translateY = 0;
- if (Math.abs(translateZ) < 0.001) translateZ = 0;
- if (Math.abs(rotateY) < 0.001) rotateY = 0;
- if (Math.abs(rotateX) < 0.001) rotateX = 0;
- var slideTransform = 'translate3d(' + translateX + 'px,' + translateY + 'px,' + translateZ + 'px) rotateX(' + rotateX + 'deg) rotateY(' + rotateY + 'deg)';
- slide.transform(slideTransform);
- slide[0].style.zIndex = -Math.abs(Math.round(offsetMultiplier)) + 1;
- if (s.params.coverflow.slideShadows) {
- //Set shadows
- var shadowBefore = isH() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top');
- var shadowAfter = isH() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom');
- if (shadowBefore.length === 0) {
- shadowBefore = $('<div class="swiper-slide-shadow-' + (isH() ? 'left' : 'top') + '"></div>');
- slide.append(shadowBefore);
- }
- if (shadowAfter.length === 0) {
- shadowAfter = $('<div class="swiper-slide-shadow-' + (isH() ? 'right' : 'bottom') + '"></div>');
- slide.append(shadowAfter);
- }
- if (shadowBefore.length) shadowBefore[0].style.opacity = offsetMultiplier > 0 ? offsetMultiplier : 0;
- if (shadowAfter.length) shadowAfter[0].style.opacity = (-offsetMultiplier) > 0 ? -offsetMultiplier : 0;
- }
- }
- //Set correct perspective for IE10
- if (s.browser.ie) {
- var ws = s.wrapper[0].style;
- ws.perspectiveOrigin = center + 'px 50%';
- }
- },
- setTransition: function (duration) {
- s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration);
- }
- }
- };
- /*=========================
- Images Lazy Loading
- ===========================*/
- s.lazy = {
- initialImageLoaded: false,
- loadImageInSlide: function (index) {
- if (typeof index === 'undefined') return;
- if (s.slides.length === 0) return;
- var slide = s.slides.eq(index);
- var img = slide.find('img.swiper-lazy:not(.swiper-lazy-loaded):not(.swiper-lazy-loading)');
- if (img.length === 0) return;
- img.each(function () {
- var _img = $(this);
- _img.addClass('swiper-lazy-loading');
- var src = _img.attr('data-src');
- s.loadImage(_img[0], src, false, function () {
- _img.attr('src', src);
- _img.removeAttr('data-src');
- _img.addClass('swiper-lazy-loaded').removeClass('swiper-lazy-loading');
- slide.find('.swiper-lazy-preloader, .preloader').remove();
- s.emit('onLazyImageReady', s, slide[0], _img[0]);
- });
- s.emit('onLazyImageLoad', s, slide[0], _img[0]);
- });
- },
- load: function () {
- if (s.params.watchSlidesVisibility) {
- s.wrapper.children('.' + s.params.slideVisibleClass).each(function () {
- s.lazy.loadImageInSlide($(this).index());
- });
- }
- else {
- if (s.params.slidesPerView > 1) {
- for (var i = s.activeIndex; i < s.activeIndex + s.params.slidesPerView ; i++) {
- if (s.slides[i]) s.lazy.loadImageInSlide(i);
- }
- }
- else {
- s.lazy.loadImageInSlide(s.activeIndex);
- }
- }
- if (s.params.lazyLoadingInPrevNext) {
- var nextSlide = s.wrapper.children('.' + s.params.slideNextClass);
- if (nextSlide.length > 0) s.lazy.loadImageInSlide(nextSlide.index());
- var prevSlide = s.wrapper.children('.' + s.params.slidePrevClass);
- if (prevSlide.length > 0) s.lazy.loadImageInSlide(prevSlide.index());
- }
- },
- onTransitionStart: function () {
- if (s.params.lazyLoading) {
- if (s.params.lazyLoadingOnTransitionStart || (!s.params.lazyLoadingOnTransitionStart && !s.lazy.initialImageLoaded)) {
- s.lazy.initialImageLoaded = true;
- s.lazy.load();
- }
- }
- },
- onTransitionEnd: function () {
- if (s.params.lazyLoading && !s.params.lazyLoadingOnTransitionStart) {
- s.lazy.load();
- }
- }
- };
- /*=========================
- Scrollbar
- ===========================*/
- s.scrollbar = {
- set: function () {
- if (!s.params.scrollbar) return;
- var sb = s.scrollbar;
- sb.track = $(s.params.scrollbar);
- sb.drag = sb.track.find('.swiper-scrollbar-drag');
- if (sb.drag.length === 0) {
- sb.drag = $('<div class="swiper-scrollbar-drag"></div>');
- sb.track.append(sb.drag);
- }
- sb.drag[0].style.width = '';
- sb.drag[0].style.height = '';
- sb.trackSize = isH() ? sb.track[0].offsetWidth : sb.track[0].offsetHeight;
- sb.divider = s.size / s.virtualSize;
- sb.moveDivider = sb.divider * (sb.trackSize / s.size);
- sb.dragSize = sb.trackSize * sb.divider;
- if (isH()) {
- sb.drag[0].style.width = sb.dragSize + 'px';
- }
- else {
- sb.drag[0].style.height = sb.dragSize + 'px';
- }
- if (sb.divider >= 1) {
- sb.track[0].style.display = 'none';
- }
- else {
- sb.track[0].style.display = '';
- }
- if (s.params.scrollbarHide) {
- sb.track[0].style.opacity = 0;
- }
- },
- setTranslate: function () {
- if (!s.params.scrollbar) return;
- var sb = s.scrollbar;
- var newPos;
- var newSize = sb.dragSize;
- newPos = (sb.trackSize - sb.dragSize) * s.progress;
- if (s.rtl && isH()) {
- newPos = -newPos;
- if (newPos > 0) {
- newSize = sb.dragSize - newPos;
- newPos = 0;
- }
- else if (-newPos + sb.dragSize > sb.trackSize) {
- newSize = sb.trackSize + newPos;
- }
- }
- else {
- if (newPos < 0) {
- newSize = sb.dragSize + newPos;
- newPos = 0;
- }
- else if (newPos + sb.dragSize > sb.trackSize) {
- newSize = sb.trackSize - newPos;
- }
- }
- if (isH()) {
- if (s.support.transforms3d) {
- sb.drag.transform('translate3d(' + (newPos) + 'px, 0, 0)');
- }
- else {
- sb.drag.transform('translateX(' + (newPos) + 'px)');
- }
- sb.drag[0].style.width = newSize + 'px';
- }
- else {
- if (s.support.transforms3d) {
- sb.drag.transform('translate3d(0px, ' + (newPos) + 'px, 0)');
- }
- else {
- sb.drag.transform('translateY(' + (newPos) + 'px)');
- }
- sb.drag[0].style.height = newSize + 'px';
- }
- if (s.params.scrollbarHide) {
- clearTimeout(sb.timeout);
- sb.track[0].style.opacity = 1;
- sb.timeout = setTimeout(function () {
- sb.track[0].style.opacity = 0;
- sb.track.transition(400);
- }, 1000);
- }
- },
- setTransition: function (duration) {
- if (!s.params.scrollbar) return;
- s.scrollbar.drag.transition(duration);
- }
- };
- /*=========================
- Controller
- ===========================*/
- s.controller = {
- setTranslate: function (translate, byController) {
- var controlled = s.params.control;
- var multiplier, controlledTranslate;
- if (s.isArray(controlled)) {
- for (var i = 0; i < controlled.length; i++) {
- if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
- translate = controlled[i].rtl && controlled[i].params.direction === 'horizontal' ? -s.translate : s.translate;
- multiplier = (controlled[i].maxTranslate() - controlled[i].minTranslate()) / (s.maxTranslate() - s.minTranslate());
- controlledTranslate = (translate - s.minTranslate()) * multiplier + controlled[i].minTranslate();
- if (s.params.controlInverse) {
- controlledTranslate = controlled[i].maxTranslate() - controlledTranslate;
- }
- controlled[i].updateProgress(controlledTranslate);
- controlled[i].setWrapperTranslate(controlledTranslate, false, s);
- controlled[i].updateActiveIndex();
- }
- }
- }
- else if (controlled instanceof Swiper && byController !== controlled) {
- translate = controlled.rtl && controlled.params.direction === 'horizontal' ? -s.translate : s.translate;
- multiplier = (controlled.maxTranslate() - controlled.minTranslate()) / (s.maxTranslate() - s.minTranslate());
- controlledTranslate = (translate - s.minTranslate()) * multiplier + controlled.minTranslate();
- if (s.params.controlInverse) {
- controlledTranslate = controlled.maxTranslate() - controlledTranslate;
- }
- controlled.updateProgress(controlledTranslate);
- controlled.setWrapperTranslate(controlledTranslate, false, s);
- controlled.updateActiveIndex();
- }
- },
- setTransition: function (duration, byController) {
- var controlled = s.params.control;
- if (s.isArray(controlled)) {
- for (var i = 0; i < controlled.length; i++) {
- if (controlled[i] !== byController && controlled[i] instanceof Swiper) {
- controlled[i].setWrapperTransition(duration, s);
- }
- }
- }
- else if (controlled instanceof Swiper && byController !== controlled) {
- controlled.setWrapperTransition(duration, s);
- }
- }
- };
- /*=========================
- Parallax
- ===========================*/
- function setParallaxTransform(el, progress) {
- el = $(el);
- var p, pX, pY;
- p = el.attr('data-swiper-parallax') || '0';
- pX = el.attr('data-swiper-parallax-x');
- pY = el.attr('data-swiper-parallax-y');
- if (pX || pY) {
- pX = pX || '0';
- pY = pY || '0';
- }
- else {
- if (isH()) {
- pX = p;
- pY = '0';
- }
- else {
- pY = p;
- pX = '0';
- }
- }
- if ((pX).indexOf('%') >= 0) {
- pX = parseInt(pX, 10) * progress + '%';
- }
- else {
- pX = pX * progress + 'px' ;
- }
- if ((pY).indexOf('%') >= 0) {
- pY = parseInt(pY, 10) * progress + '%';
- }
- else {
- pY = pY * progress + 'px' ;
- }
- el.transform('translate3d(' + pX + ', ' + pY + ',0px)');
- }
- s.parallax = {
- setTranslate: function () {
- s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
- setParallaxTransform(this, s.progress);
- });
- s.slides.each(function () {
- var slide = $(this);
- slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () {
- var progress = Math.min(Math.max(slide[0].progress, -1), 1);
- setParallaxTransform(this, progress);
- });
- });
- },
- setTransition: function (duration) {
- if (typeof duration === 'undefined') duration = s.params.speed;
- s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){
- var el = $(this);
- var parallaxDuration = parseInt(el.attr('data-swiper-parallax-duration'), 10) || duration;
- if (duration === 0) parallaxDuration = 0;
- el.transition(parallaxDuration);
- });
- }
- };
- /*=========================
- Plugins API. Collect all and init all plugins
- ===========================*/
- s._plugins = [];
- for (var plugin in s.plugins) {
- if(s.plugins.hasOwnProperty(plugin)){
- var p = s.plugins[plugin](s, s.params[plugin]);
- if (p) s._plugins.push(p);
- }
- }
- // Method to call all plugins event/method
- s.callPlugins = function (eventName) {
- for (var i = 0; i < s._plugins.length; i++) {
- if (eventName in s._plugins[i]) {
- s._plugins[i][eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
- }
- }
- };
- /*=========================
- Events/Callbacks/Plugins Emitter
- ===========================*/
- function normalizeEventName (eventName) {
- if (eventName.indexOf('on') !== 0) {
- if (eventName[0] !== eventName[0].toUpperCase()) {
- eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1);
- }
- else {
- eventName = 'on' + eventName;
- }
- }
- return eventName;
- }
- s.emitterEventListeners = {
- };
- s.emit = function (eventName) {
- // Trigger callbacks
- if (s.params[eventName]) {
- s.params[eventName](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
- }
- var i;
- // 图片浏览器点击关闭后,swiper也关闭了,但会执行到此处
- if (!s) return;
- // Trigger events
- if (s.emitterEventListeners[eventName]) {
- for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
- s.emitterEventListeners[eventName][i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
- }
- }
- // Trigger plugins
- if (s.callPlugins) s.callPlugins(eventName, arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
- };
- s.on = function (eventName, handler) {
- eventName = normalizeEventName(eventName);
- if (!s.emitterEventListeners[eventName]) s.emitterEventListeners[eventName] = [];
- s.emitterEventListeners[eventName].push(handler);
- return s;
- };
- s.off = function (eventName, handler) {
- var i;
- eventName = normalizeEventName(eventName);
- if (typeof handler === 'undefined') {
- // Remove all handlers for such event
- s.emitterEventListeners[eventName] = [];
- return s;
- }
- if (!s.emitterEventListeners[eventName] || s.emitterEventListeners[eventName].length === 0) return;
- for (i = 0; i < s.emitterEventListeners[eventName].length; i++) {
- if(s.emitterEventListeners[eventName][i] === handler) s.emitterEventListeners[eventName].splice(i, 1);
- }
- return s;
- };
- s.once = function (eventName, handler) {
- eventName = normalizeEventName(eventName);
- var _handler = function () {
- handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
- s.off(eventName, _handler);
- };
- s.on(eventName, _handler);
- return s;
- };
- // Accessibility tools
- s.a11y = {
- makeFocusable: function ($el) {
- $el[0].tabIndex = '0';
- return $el;
- },
- addRole: function ($el, role) {
- $el.attr('role', role);
- return $el;
- },
- addLabel: function ($el, label) {
- $el.attr('aria-label', label);
- return $el;
- },
- disable: function ($el) {
- $el.attr('aria-disabled', true);
- return $el;
- },
- enable: function ($el) {
- $el.attr('aria-disabled', false);
- return $el;
- },
- onEnterKey: function (event) {
- if (event.keyCode !== 13) return;
- if ($(event.target).is(s.params.nextButton)) {
- s.onClickNext(event);
- if (s.isEnd) {
- s.a11y.notify(s.params.lastSlideMsg);
- }
- else {
- s.a11y.notify(s.params.nextSlideMsg);
- }
- }
- else if ($(event.target).is(s.params.prevButton)) {
- s.onClickPrev(event);
- if (s.isBeginning) {
- s.a11y.notify(s.params.firstSlideMsg);
- }
- else {
- s.a11y.notify(s.params.prevSlideMsg);
- }
- }
- },
- liveRegion: $('<span class="swiper-notification" aria-live="assertive" aria-atomic="true"></span>'),
- notify: function (message) {
- var notification = s.a11y.liveRegion;
- if (notification.length === 0) return;
- notification.html('');
- notification.html(message);
- },
- init: function () {
- // Setup accessibility
- if (s.params.nextButton) {
- var nextButton = $(s.params.nextButton);
- s.a11y.makeFocusable(nextButton);
- s.a11y.addRole(nextButton, 'button');
- s.a11y.addLabel(nextButton, s.params.nextSlideMsg);
- }
- if (s.params.prevButton) {
- var prevButton = $(s.params.prevButton);
- s.a11y.makeFocusable(prevButton);
- s.a11y.addRole(prevButton, 'button');
- s.a11y.addLabel(prevButton, s.params.prevSlideMsg);
- }
- $(s.container).append(s.a11y.liveRegion);
- },
- destroy: function () {
- if (s.a11y.liveRegion && s.a11y.liveRegion.length > 0) s.a11y.liveRegion.remove();
- }
- };
- /*=========================
- Init/Destroy
- ===========================*/
- s.init = function () {
- if (s.params.loop) s.createLoop();
- s.updateContainerSize();
- s.updateSlidesSize();
- s.updatePagination();
- if (s.params.scrollbar && s.scrollbar) {
- s.scrollbar.set();
- }
- if (s.params.effect !== 'slide' && s.effects[s.params.effect]) {
- if (!s.params.loop) s.updateProgress();
- s.effects[s.params.effect].setTranslate();
- }
- if (s.params.loop) {
- s.slideTo(s.params.initialSlide + s.loopedSlides, 0, s.params.runCallbacksOnInit);
- }
- else {
- s.slideTo(s.params.initialSlide, 0, s.params.runCallbacksOnInit);
- if (s.params.initialSlide === 0) {
- if (s.parallax && s.params.parallax) s.parallax.setTranslate();
- if (s.lazy && s.params.lazyLoading) s.lazy.load();
- }
- }
- s.attachEvents();
- if (s.params.observer && s.support.observer) {
- s.initObservers();
- }
- if (s.params.preloadImages && !s.params.lazyLoading) {
- s.preloadImages();
- }
- if (s.params.autoplay) {
- s.startAutoplay();
- }
- if (s.params.keyboardControl) {
- if (s.enableKeyboardControl) s.enableKeyboardControl();
- }
- if (s.params.mousewheelControl) {
- if (s.enableMousewheelControl) s.enableMousewheelControl();
- }
- if (s.params.hashnav) {
- if (s.hashnav) s.hashnav.init();
- }
- if (s.params.a11y && s.a11y) s.a11y.init();
- s.emit('onInit', s);
- };
- // Cleanup dynamic styles
- s.cleanupStyles = function () {
- // Container
- s.container.removeClass(s.classNames.join(' ')).removeAttr('style');
- // Wrapper
- s.wrapper.removeAttr('style');
- // Slides
- if (s.slides && s.slides.length) {
- s.slides
- .removeClass([
- s.params.slideVisibleClass,
- s.params.slideActiveClass,
- s.params.slideNextClass,
- s.params.slidePrevClass
- ].join(' '))
- .removeAttr('style')
- .removeAttr('data-swiper-column')
- .removeAttr('data-swiper-row');
- }
- // Pagination/Bullets
- if (s.paginationContainer && s.paginationContainer.length) {
- s.paginationContainer.removeClass(s.params.paginationHiddenClass);
- }
- if (s.bullets && s.bullets.length) {
- s.bullets.removeClass(s.params.bulletActiveClass);
- }
- // Buttons
- if (s.params.prevButton) $(s.params.prevButton).removeClass(s.params.buttonDisabledClass);
- if (s.params.nextButton) $(s.params.nextButton).removeClass(s.params.buttonDisabledClass);
- // Scrollbar
- if (s.params.scrollbar && s.scrollbar) {
- if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeAttr('style');
- if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeAttr('style');
- }
- };
- // Destroy
- s.destroy = function (deleteInstance, cleanupStyles) {
- // Detach evebts
- s.detachEvents();
- // Stop autoplay
- s.stopAutoplay();
- // Destroy loop
- if (s.params.loop) {
- s.destroyLoop();
- }
- // Cleanup styles
- if (cleanupStyles) {
- s.cleanupStyles();
- }
- // Disconnect observer
- s.disconnectObservers();
- // Disable keyboard/mousewheel
- if (s.params.keyboardControl) {
- if (s.disableKeyboardControl) s.disableKeyboardControl();
- }
- if (s.params.mousewheelControl) {
- if (s.disableMousewheelControl) s.disableMousewheelControl();
- }
- // Disable a11y
- if (s.params.a11y && s.a11y) s.a11y.destroy();
- // Destroy callback
- s.emit('onDestroy');
- // Delete instance
- if (deleteInstance !== false) s = null;
- };
- s.init();
- // Return swiper instance
- return s;
- };
- /*==================================================
- Prototype
- ====================================================*/
- Swiper.prototype = {
- defaults: {
- direction: 'horizontal',
- touchEventsTarget: 'container',
- initialSlide: 0,
- speed: 300,
- // autoplay
- autoplay: false,
- autoplayDisableOnInteraction: true,
- // Free mode
- freeMode: false,
- freeModeMomentum: true,
- freeModeMomentumRatio: 1,
- freeModeMomentumBounce: true,
- freeModeMomentumBounceRatio: 1,
- // Set wrapper width
- setWrapperSize: false,
- // Virtual Translate
- virtualTranslate: false,
- // Effects
- effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow'
- coverflow: {
- rotate: 50,
- stretch: 0,
- depth: 100,
- modifier: 1,
- slideShadows : true
- },
- cube: {
- slideShadows: true,
- shadow: true,
- shadowOffset: 20,
- shadowScale: 0.94
- },
- fade: {
- crossFade: false
- },
- // Parallax
- parallax: false,
- // Scrollbar
- scrollbar: null,
- scrollbarHide: true,
- // Keyboard Mousewheel
- keyboardControl: false,
- mousewheelControl: false,
- mousewheelForceToAxis: false,
- // Hash Navigation
- hashnav: false,
- // Slides grid
- spaceBetween: 0,
- slidesPerView: 1,
- slidesPerColumn: 1,
- slidesPerColumnFill: 'column',
- slidesPerGroup: 1,
- centeredSlides: false,
- // Touches
- touchRatio: 1,
- touchAngle: 45,
- simulateTouch: true,
- shortSwipes: true,
- longSwipes: true,
- longSwipesRatio: 0.5,
- longSwipesMs: 300,
- followFinger: true,
- onlyExternal: false,
- threshold: 0,
- touchMoveStopPropagation: true,
- // Pagination
- pagination: null,
- paginationClickable: false,
- paginationHide: false,
- paginationBulletRender: null,
- // Resistance
- resistance: true,
- resistanceRatio: 0.85,
- // Next/prev buttons
- nextButton: null,
- prevButton: null,
- // Progress
- watchSlidesProgress: false,
- watchSlidesVisibility: false,
- // Cursor
- grabCursor: false,
- // Clicks
- preventClicks: true,
- preventClicksPropagation: true,
- slideToClickedSlide: false,
- // Lazy Loading
- lazyLoading: false,
- lazyLoadingInPrevNext: false,
- lazyLoadingOnTransitionStart: false,
- // Images
- preloadImages: true,
- updateOnImagesReady: true,
- // loop
- loop: false,
- loopAdditionalSlides: 0,
- loopedSlides: null,
- // Control
- control: undefined,
- controlInverse: false,
- // Swiping/no swiping
- allowSwipeToPrev: true,
- allowSwipeToNext: true,
- swipeHandler: null, //'.swipe-handler',
- noSwiping: true,
- noSwipingClass: 'swiper-no-swiping',
- // NS
- slideClass: 'swiper-slide',
- slideActiveClass: 'swiper-slide-active',
- slideVisibleClass: 'swiper-slide-visible',
- slideDuplicateClass: 'swiper-slide-duplicate',
- slideNextClass: 'swiper-slide-next',
- slidePrevClass: 'swiper-slide-prev',
- wrapperClass: 'swiper-wrapper',
- bulletClass: 'swiper-pagination-bullet',
- bulletActiveClass: 'swiper-pagination-bullet-active',
- buttonDisabledClass: 'swiper-button-disabled',
- paginationHiddenClass: 'swiper-pagination-hidden',
- // Observer
- observer: false,
- observeParents: false,
- // Accessibility
- a11y: false,
- prevSlideMessage: 'Previous slide',
- nextSlideMessage: 'Next slide',
- firstSlideMessage: 'This is the first slide',
- lastSlideMessage: 'This is the last slide',
- // Callbacks
- runCallbacksOnInit: true,
- /*
- Callbacks:
- onInit: function (swiper)
- onDestroy: function (swiper)
- onClick: function (swiper, e)
- onTap: function (swiper, e)
- onDoubleTap: function (swiper, e)
- onSliderMove: function (swiper, e)
- onSlideChangeStart: function (swiper)
- onSlideChangeEnd: function (swiper)
- onTransitionStart: function (swiper)
- onTransitionEnd: function (swiper)
- onImagesReady: function (swiper)
- onProgress: function (swiper, progress)
- onTouchStart: function (swiper, e)
- onTouchMove: function (swiper, e)
- onTouchMoveOpposite: function (swiper, e)
- onTouchEnd: function (swiper, e)
- onReachBeginning: function (swiper)
- onReachEnd: function (swiper)
- onSetTransition: function (swiper, duration)
- onSetTranslate: function (swiper, translate)
- onAutoplayStart: function (swiper)
- onAutoplayStop: function (swiper),
- onLazyImageLoad: function (swiper, slide, image)
- onLazyImageReady: function (swiper, slide, image)
- */
- },
- isSafari: (function () {
- var ua = navigator.userAgent.toLowerCase();
- return (ua.indexOf('safari') >= 0 && ua.indexOf('chrome') < 0 && ua.indexOf('android') < 0);
- })(),
- isUiWebView: /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent),
- isArray: function (arr) {
- return Object.prototype.toString.apply(arr) === '[object Array]';
- },
- /*==================================================
- Browser
- ====================================================*/
- browser: {
- ie: window.navigator.pointerEnabled || window.navigator.msPointerEnabled,
- ieTouch: (window.navigator.msPointerEnabled && window.navigator.msMaxTouchPoints > 1) || (window.navigator.pointerEnabled && window.navigator.maxTouchPoints > 1),
- },
- /*==================================================
- Devices
- ====================================================*/
- device: (function () {
- var ua = navigator.userAgent;
- var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
- var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
- var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
- return {
- ios: ipad || iphone || ipad,
- android: android
- };
- })(),
- /*==================================================
- Feature Detection
- ====================================================*/
- support: {
- touch : (window.Modernizr && Modernizr.touch === true) || (function () {
- return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
- })(),
- transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () {
- var div = document.createElement('div').style;
- return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
- })(),
- flexbox: (function () {
- var div = document.createElement('div').style;
- var styles = ('alignItems webkitAlignItems webkitBoxAlign msFlexAlign mozBoxAlign webkitFlexDirection msFlexDirection mozBoxDirection mozBoxOrient webkitBoxDirection webkitBoxOrient').split(' ');
- for (var i = 0; i < styles.length; i++) {
- if (styles[i] in div) return true;
- }
- })(),
- observer: (function () {
- return ('MutationObserver' in window || 'WebkitMutationObserver' in window);
- })()
- },
- /*==================================================
- Plugins
- ====================================================*/
- plugins: {}
- };
- $.Swiper = Swiper;
- }(Zepto);
- +function($){
- 'use strict';
- $.Swiper.prototype.defaults.pagination = '.page-current .swiper-pagination';
- $.swiper = function (container, params) {
- return new $.Swiper(container, params);
- };
- $.fn.swiper = function (params) {
- return new $.Swiper(this, params);
- };
- $.initSwiper = function (pageContainer) {
- var page = $(pageContainer || document.body);
- var swipers = page.find('.swiper-container');
- if (swipers.length === 0) return;
- function destroySwiperOnRemove(slider) {
- function destroySwiper() {
- slider.destroy();
- page.off('pageBeforeRemove', destroySwiper);
- }
- page.on('pageBeforeRemove', destroySwiper);
- }
- for (var i = 0; i < swipers.length; i++) {
- var swiper = swipers.eq(i);
- var params;
- if (swiper.data('swiper')) {
- swiper.data("swiper").update(true);
- continue;
- }
- else {
- params = swiper.dataset();
- }
- var _slider = $.swiper(swiper[0], params);
- destroySwiperOnRemove(_slider);
- }
- };
- $.reinitSwiper = function (pageContainer) {
- var page = $(pageContainer || '.page-current');
- var sliders = page.find('.swiper-container');
- if (sliders.length === 0) return;
- for (var i = 0; i < sliders.length; i++) {
- var sliderInstance = sliders[0].swiper;
- if (sliderInstance) {
- sliderInstance.update(true);
- }
- }
- };
- }(Zepto);
- /*======================================================
- ************ Photo Browser ************
- ======================================================*/
- +function($){
- 'use strict';
- var PhotoBrowser = function (params) {
- var pb = this, i;
- var defaults = this.defaults;
- params = params || {};
- for (var def in defaults) {
- if (typeof params[def] === 'undefined') {
- params[def] = defaults[def];
- }
- }
- pb.params = params;
- var navbarTemplate = pb.params.navbarTemplate ||
- '<header class="bar bar-nav">' +
- '<a class="icon icon-left pull-left photo-browser-close-link' + (pb.params.type === 'popup' ? " close-popup" : "") + '"></a>' +
- '<h1 class="title"><div class="center sliding"><span class="photo-browser-current"></span> <span class="photo-browser-of">' + pb.params.ofText + '</span> <span class="photo-browser-total"></span></div></h1>' +
- '</header>';
- var toolbarTemplate = pb.params.toolbarTemplate ||
- '<nav class="bar bar-tab">' +
- '<a class="tab-item photo-browser-prev" href="#">' +
- '<i class="icon icon-prev"></i>' +
- '</a>' +
- '<a class="tab-item photo-browser-next" href="#">' +
- '<i class="icon icon-next"></i>' +
- '</a>' +
- '</nav>';
- var template = pb.params.template ||
- '<div class="photo-browser photo-browser-' + pb.params.theme + '">' +
- '{{navbar}}' +
- '{{toolbar}}' +
- '<div data-page="photo-browser-slides" class="content">' +
- '{{captions}}' +
- '<div class="photo-browser-swiper-container swiper-container">' +
- '<div class="photo-browser-swiper-wrapper swiper-wrapper">' +
- '{{photos}}' +
- '</div>' +
- '</div>' +
- '</div>' +
- '</div>';
- var photoTemplate = !pb.params.lazyLoading ?
- (pb.params.photoTemplate || '<div class="photo-browser-slide swiper-slide"><span class="photo-browser-zoom-container"><img src="{{url}}"></span></div>') :
- (pb.params.photoLazyTemplate || '<div class="photo-browser-slide photo-browser-slide-lazy swiper-slide"><div class="preloader' + (pb.params.theme === 'dark' ? ' preloader-white' : '') + '"></div><span class="photo-browser-zoom-container"><img data-src="{{url}}" class="swiper-lazy"></span></div>');
- var captionsTheme = pb.params.captionsTheme || pb.params.theme;
- var captionsTemplate = pb.params.captionsTemplate || '<div class="photo-browser-captions photo-browser-captions-' + captionsTheme + '">{{captions}}</div>';
- var captionTemplate = pb.params.captionTemplate || '<div class="photo-browser-caption" data-caption-index="{{captionIndex}}">{{caption}}</div>';
- var objectTemplate = pb.params.objectTemplate || '<div class="photo-browser-slide photo-browser-object-slide swiper-slide">{{html}}</div>';
- var photosHtml = '';
- var captionsHtml = '';
- for (i = 0; i < pb.params.photos.length; i ++) {
- var photo = pb.params.photos[i];
- var thisTemplate = '';
- //check if photo is a string or string-like object, for backwards compatibility
- if (typeof(photo) === 'string' || photo instanceof String) {
- //check if "photo" is html object
- if (photo.indexOf('<') >= 0 || photo.indexOf('>') >= 0) {
- thisTemplate = objectTemplate.replace(/{{html}}/g, photo);
- } else {
- thisTemplate = photoTemplate.replace(/{{url}}/g, photo);
- }
- //photo is a string, thus has no caption, so remove the caption template placeholder
- //otherwise check if photo is an object with a url property
- } else if (typeof(photo) === 'object') {
- //check if "photo" is html object
- if (photo.hasOwnProperty('html') && photo.html.length > 0) {
- thisTemplate = objectTemplate.replace(/{{html}}/g, photo.html);
- } else if (photo.hasOwnProperty('url') && photo.url.length > 0) {
- thisTemplate = photoTemplate.replace(/{{url}}/g, photo.url);
- }
- //check if photo has a caption
- if (photo.hasOwnProperty('caption') && photo.caption.length > 0) {
- captionsHtml += captionTemplate.replace(/{{caption}}/g, photo.caption).replace(/{{captionIndex}}/g, i);
- } else {
- thisTemplate = thisTemplate.replace(/{{caption}}/g, '');
- }
- }
- photosHtml += thisTemplate;
- }
- var htmlTemplate = template
- .replace('{{navbar}}', (pb.params.navbar ? navbarTemplate : ''))
- .replace('{{noNavbar}}', (pb.params.navbar ? '' : 'no-navbar'))
- .replace('{{photos}}', photosHtml)
- .replace('{{captions}}', captionsTemplate.replace(/{{captions}}/g, captionsHtml))
- .replace('{{toolbar}}', (pb.params.toolbar ? toolbarTemplate : ''));
- pb.activeIndex = pb.params.initialSlide;
- pb.openIndex = pb.activeIndex;
- pb.opened = false;
- pb.open = function (index) {
- if (typeof index === 'undefined') index = pb.activeIndex;
- index = parseInt(index, 10);
- if (pb.opened && pb.swiper) {
- pb.swiper.slideTo(index);
- return;
- }
- pb.opened = true;
- pb.openIndex = index;
- // pb.initialLazyLoaded = false;
- if (pb.params.type === 'standalone') {
- $(pb.params.container).append(htmlTemplate);
- }
- if (pb.params.type === 'popup') {
- pb.popup = $.popup('<div class="popup photo-browser-popup">' + htmlTemplate + '</div>');
- $(pb.popup).on('closed', pb.onPopupClose);
- }
- if (pb.params.type === 'page') {
- $(document).on('pageBeforeInit', pb.onPageBeforeInit);
- $(document).on('pageBeforeRemove', pb.onPageBeforeRemove);
- if (!pb.params.view) pb.params.view = $.mainView;
- pb.params.view.loadContent(htmlTemplate);
- return;
- }
- pb.layout(pb.openIndex);
- if (pb.params.onOpen) {
- pb.params.onOpen(pb);
- }
- };
- pb.close = function () {
- pb.opened = false;
- if (!pb.swiperContainer || pb.swiperContainer.length === 0) {
- return;
- }
- if (pb.params.onClose) {
- pb.params.onClose(pb);
- }
- // Detach events
- pb.attachEvents(true);
- // Delete from DOM
- if (pb.params.type === 'standalone') {
- pb.container.removeClass('photo-browser-in').addClass('photo-browser-out').animationEnd(function () {
- pb.container.remove();
- });
- }
- // Destroy slider
- pb.swiper.destroy();
- // Delete references
- pb.swiper = pb.swiperContainer = pb.swiperWrapper = pb.slides = gestureSlide = gestureImg = gestureImgWrap = undefined;
- };
- pb.onPopupClose = function () {
- pb.close();
- $(pb.popup).off('pageBeforeInit', pb.onPopupClose);
- };
- pb.onPageBeforeInit = function (e) {
- if (e.detail.page.name === 'photo-browser-slides') {
- pb.layout(pb.openIndex);
- }
- $(document).off('pageBeforeInit', pb.onPageBeforeInit);
- };
- pb.onPageBeforeRemove = function (e) {
- if (e.detail.page.name === 'photo-browser-slides') {
- pb.close();
- }
- $(document).off('pageBeforeRemove', pb.onPageBeforeRemove);
- };
- pb.onSliderTransitionStart = function (swiper) {
- pb.activeIndex = swiper.activeIndex;
- var current = swiper.activeIndex + 1;
- var total = swiper.slides.length;
- if (pb.params.loop) {
- total = total - 2;
- current = current - swiper.loopedSlides;
- if (current < 1) current = total + current;
- if (current > total) current = current - total;
- }
- pb.container.find('.photo-browser-current').text(current);
- pb.container.find('.photo-browser-total').text(total);
- $('.photo-browser-prev, .photo-browser-next').removeClass('photo-browser-link-inactive');
- if (swiper.isBeginning && !pb.params.loop) {
- $('.photo-browser-prev').addClass('photo-browser-link-inactive');
- }
- if (swiper.isEnd && !pb.params.loop) {
- $('.photo-browser-next').addClass('photo-browser-link-inactive');
- }
- // Update captions
- if (pb.captions.length > 0) {
- pb.captionsContainer.find('.photo-browser-caption-active').removeClass('photo-browser-caption-active');
- var captionIndex = pb.params.loop ? swiper.slides.eq(swiper.activeIndex).attr('data-swiper-slide-index') : pb.activeIndex;
- pb.captionsContainer.find('[data-caption-index="' + captionIndex + '"]').addClass('photo-browser-caption-active');
- }
- // Stop Video
- var previousSlideVideo = swiper.slides.eq(swiper.previousIndex).find('video');
- if (previousSlideVideo.length > 0) {
- if ('pause' in previousSlideVideo[0]) previousSlideVideo[0].pause();
- }
- // Callback
- if (pb.params.onSlideChangeStart) pb.params.onSlideChangeStart(swiper);
- };
- pb.onSliderTransitionEnd = function (swiper) {
- // Reset zoom
- if (pb.params.zoom && gestureSlide && swiper.previousIndex !== swiper.activeIndex) {
- gestureImg.transform('translate3d(0,0,0) scale(1)');
- gestureImgWrap.transform('translate3d(0,0,0)');
- gestureSlide = gestureImg = gestureImgWrap = undefined;
- scale = currentScale = 1;
- }
- if (pb.params.onSlideChangeEnd) pb.params.onSlideChangeEnd(swiper);
- };
- pb.layout = function (index) {
- if (pb.params.type === 'page') {
- pb.container = $('.photo-browser-swiper-container').parents('.view');
- }
- else {
- pb.container = $('.photo-browser');
- }
- if (pb.params.type === 'standalone') {
- pb.container.addClass('photo-browser-in');
- // $.sizeNavbars(pb.container);
- }
- pb.swiperContainer = pb.container.find('.photo-browser-swiper-container');
- pb.swiperWrapper = pb.container.find('.photo-browser-swiper-wrapper');
- pb.slides = pb.container.find('.photo-browser-slide');
- pb.captionsContainer = pb.container.find('.photo-browser-captions');
- pb.captions = pb.container.find('.photo-browser-caption');
- var sliderSettings = {
- nextButton: pb.params.nextButton || '.photo-browser-next',
- prevButton: pb.params.prevButton || '.photo-browser-prev',
- indexButton: pb.params.indexButton,
- initialSlide: index,
- spaceBetween: pb.params.spaceBetween,
- speed: pb.params.speed,
- loop: pb.params.loop,
- lazyLoading: pb.params.lazyLoading,
- lazyLoadingInPrevNext: pb.params.lazyLoadingInPrevNext,
- lazyLoadingOnTransitionStart: pb.params.lazyLoadingOnTransitionStart,
- preloadImages: pb.params.lazyLoading ? false : true,
- onTap: function (swiper, e) {
- if (pb.params.onTap) pb.params.onTap(swiper, e);
- },
- onClick: function (swiper, e) {
- if (pb.params.exposition) pb.toggleExposition();
- if (pb.params.onClick) pb.params.onClick(swiper, e);
- },
- onDoubleTap: function (swiper, e) {
- pb.toggleZoom($(e.target).parents('.photo-browser-slide'));
- if (pb.params.onDoubleTap) pb.params.onDoubleTap(swiper, e);
- },
- onTransitionStart: function (swiper) {
- pb.onSliderTransitionStart(swiper);
- },
- onTransitionEnd: function (swiper) {
- pb.onSliderTransitionEnd(swiper);
- },
- onLazyImageLoad: function (swiper, slide, img) {
- if (pb.params.onLazyImageLoad) pb.params.onLazyImageLoad(pb, slide, img);
- },
- onLazyImageReady: function (swiper, slide, img) {
- $(slide).removeClass('photo-browser-slide-lazy');
- if (pb.params.onLazyImageReady) pb.params.onLazyImageReady(pb, slide, img);
- }
- };
- if (pb.params.swipeToClose && pb.params.type !== 'page') {
- sliderSettings.onTouchStart = pb.swipeCloseTouchStart;
- sliderSettings.onTouchMoveOpposite = pb.swipeCloseTouchMove;
- sliderSettings.onTouchEnd = pb.swipeCloseTouchEnd;
- }
- pb.swiper = $.swiper(pb.swiperContainer, sliderSettings);
- if (index === 0) {
- pb.onSliderTransitionStart(pb.swiper);
- }
- pb.attachEvents();
- };
- pb.attachEvents = function (detach) {
- var action = detach ? 'off' : 'on';
- // Slide between photos
- if (pb.params.zoom) {
- var target = pb.params.loop ? pb.swiper.slides : pb.slides;
- // Scale image
- target[action]('gesturestart', pb.onSlideGestureStart);
- target[action]('gesturechange', pb.onSlideGestureChange);
- target[action]('gestureend', pb.onSlideGestureEnd);
- // Move image
- target[action]('touchstart', pb.onSlideTouchStart);
- target[action]('touchmove', pb.onSlideTouchMove);
- target[action]('touchend', pb.onSlideTouchEnd);
- }
- pb.container.find('.photo-browser-close-link')[action]('click', pb.close);
- };
- // Expose
- pb.exposed = false;
- pb.toggleExposition = function () {
- if (pb.container) pb.container.toggleClass('photo-browser-exposed');
- if (pb.params.expositionHideCaptions) pb.captionsContainer.toggleClass('photo-browser-captions-exposed');
- pb.exposed = !pb.exposed;
- };
- pb.enableExposition = function () {
- if (pb.container) pb.container.addClass('photo-browser-exposed');
- if (pb.params.expositionHideCaptions) pb.captionsContainer.addClass('photo-browser-captions-exposed');
- pb.exposed = true;
- };
- pb.disableExposition = function () {
- if (pb.container) pb.container.removeClass('photo-browser-exposed');
- if (pb.params.expositionHideCaptions) pb.captionsContainer.removeClass('photo-browser-captions-exposed');
- pb.exposed = false;
- };
- // Gestures
- var gestureSlide, gestureImg, gestureImgWrap, scale = 1, currentScale = 1, isScaling = false;
- pb.onSlideGestureStart = function () {
- if (!gestureSlide) {
- gestureSlide = $(this);
- gestureImg = gestureSlide.find('img, svg, canvas');
- gestureImgWrap = gestureImg.parent('.photo-browser-zoom-container');
- if (gestureImgWrap.length === 0) {
- gestureImg = undefined;
- return;
- }
- }
- gestureImg.transition(0);
- isScaling = true;
- };
- pb.onSlideGestureChange = function (e) {
- if (!gestureImg || gestureImg.length === 0) return;
- scale = e.scale * currentScale;
- if (scale > pb.params.maxZoom) {
- scale = pb.params.maxZoom - 1 + Math.pow((scale - pb.params.maxZoom + 1), 0.5);
- }
- if (scale < pb.params.minZoom) {
- scale = pb.params.minZoom + 1 - Math.pow((pb.params.minZoom - scale + 1), 0.5);
- }
- gestureImg.transform('translate3d(0,0,0) scale(' + scale + ')');
- };
- pb.onSlideGestureEnd = function () {
- if (!gestureImg || gestureImg.length === 0) return;
- scale = Math.max(Math.min(scale, pb.params.maxZoom), pb.params.minZoom);
- gestureImg.transition(pb.params.speed).transform('translate3d(0,0,0) scale(' + scale + ')');
- currentScale = scale;
- isScaling = false;
- if (scale === 1) gestureSlide = undefined;
- };
- pb.toggleZoom = function () {
- if (!gestureSlide) {
- gestureSlide = pb.swiper.slides.eq(pb.swiper.activeIndex);
- gestureImg = gestureSlide.find('img, svg, canvas');
- gestureImgWrap = gestureImg.parent('.photo-browser-zoom-container');
- }
- if (!gestureImg || gestureImg.length === 0) return;
- gestureImgWrap.transition(300).transform('translate3d(0,0,0)');
- if (scale && scale !== 1) {
- scale = currentScale = 1;
- gestureImg.transition(300).transform('translate3d(0,0,0) scale(1)');
- gestureSlide = undefined;
- }
- else {
- scale = currentScale = pb.params.maxZoom;
- gestureImg.transition(300).transform('translate3d(0,0,0) scale(' + scale + ')');
- }
- };
- var imageIsTouched, imageIsMoved, imageCurrentX, imageCurrentY, imageMinX, imageMinY, imageMaxX, imageMaxY, imageWidth, imageHeight, imageTouchesStart = {}, imageTouchesCurrent = {}, imageStartX, imageStartY, velocityPrevPositionX, velocityPrevTime, velocityX, velocityPrevPositionY, velocityY;
- pb.onSlideTouchStart = function (e) {
- if (!gestureImg || gestureImg.length === 0) return;
- if (imageIsTouched) return;
- if ($.device.os === 'android') e.preventDefault();
- imageIsTouched = true;
- imageTouchesStart.x = e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX;
- imageTouchesStart.y = e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY;
- };
- pb.onSlideTouchMove = function (e) {
- if (!gestureImg || gestureImg.length === 0) return;
- pb.swiper.allowClick = false;
- if (!imageIsTouched || !gestureSlide) return;
- if (!imageIsMoved) {
- imageWidth = gestureImg[0].offsetWidth;
- imageHeight = gestureImg[0].offsetHeight;
- imageStartX = $.getTranslate(gestureImgWrap[0], 'x') || 0;
- imageStartY = $.getTranslate(gestureImgWrap[0], 'y') || 0;
- gestureImgWrap.transition(0);
- }
- // Define if we need image drag
- var scaledWidth = imageWidth * scale;
- var scaledHeight = imageHeight * scale;
- if (scaledWidth < pb.swiper.width && scaledHeight < pb.swiper.height) return;
- imageMinX = Math.min((pb.swiper.width / 2 - scaledWidth / 2), 0);
- imageMaxX = -imageMinX;
- imageMinY = Math.min((pb.swiper.height / 2 - scaledHeight / 2), 0);
- imageMaxY = -imageMinY;
- imageTouchesCurrent.x = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX;
- imageTouchesCurrent.y = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
- if (!imageIsMoved && !isScaling) {
- if (
- (Math.floor(imageMinX) === Math.floor(imageStartX) && imageTouchesCurrent.x < imageTouchesStart.x) ||
- (Math.floor(imageMaxX) === Math.floor(imageStartX) && imageTouchesCurrent.x > imageTouchesStart.x)
- ) {
- imageIsTouched = false;
- return;
- }
- }
- e.preventDefault();
- e.stopPropagation();
- imageIsMoved = true;
- imageCurrentX = imageTouchesCurrent.x - imageTouchesStart.x + imageStartX;
- imageCurrentY = imageTouchesCurrent.y - imageTouchesStart.y + imageStartY;
- if (imageCurrentX < imageMinX) {
- imageCurrentX = imageMinX + 1 - Math.pow((imageMinX - imageCurrentX + 1), 0.8);
- }
- if (imageCurrentX > imageMaxX) {
- imageCurrentX = imageMaxX - 1 + Math.pow((imageCurrentX - imageMaxX + 1), 0.8);
- }
- if (imageCurrentY < imageMinY) {
- imageCurrentY = imageMinY + 1 - Math.pow((imageMinY - imageCurrentY + 1), 0.8);
- }
- if (imageCurrentY > imageMaxY) {
- imageCurrentY = imageMaxY - 1 + Math.pow((imageCurrentY - imageMaxY + 1), 0.8);
- }
- //Velocity
- if (!velocityPrevPositionX) velocityPrevPositionX = imageTouchesCurrent.x;
- if (!velocityPrevPositionY) velocityPrevPositionY = imageTouchesCurrent.y;
- if (!velocityPrevTime) velocityPrevTime = Date.now();
- velocityX = (imageTouchesCurrent.x - velocityPrevPositionX) / (Date.now() - velocityPrevTime) / 2;
- velocityY = (imageTouchesCurrent.y - velocityPrevPositionY) / (Date.now() - velocityPrevTime) / 2;
- if (Math.abs(imageTouchesCurrent.x - velocityPrevPositionX) < 2) velocityX = 0;
- if (Math.abs(imageTouchesCurrent.y - velocityPrevPositionY) < 2) velocityY = 0;
- velocityPrevPositionX = imageTouchesCurrent.x;
- velocityPrevPositionY = imageTouchesCurrent.y;
- velocityPrevTime = Date.now();
- gestureImgWrap.transform('translate3d(' + imageCurrentX + 'px, ' + imageCurrentY + 'px,0)');
- };
- pb.onSlideTouchEnd = function () {
- if (!gestureImg || gestureImg.length === 0) return;
- if (!imageIsTouched || !imageIsMoved) {
- imageIsTouched = false;
- imageIsMoved = false;
- return;
- }
- imageIsTouched = false;
- imageIsMoved = false;
- var momentumDurationX = 300;
- var momentumDurationY = 300;
- var momentumDistanceX = velocityX * momentumDurationX;
- var newPositionX = imageCurrentX + momentumDistanceX;
- var momentumDistanceY = velocityY * momentumDurationY;
- var newPositionY = imageCurrentY + momentumDistanceY;
- //Fix duration
- if (velocityX !== 0) momentumDurationX = Math.abs((newPositionX - imageCurrentX) / velocityX);
- if (velocityY !== 0) momentumDurationY = Math.abs((newPositionY - imageCurrentY) / velocityY);
- var momentumDuration = Math.max(momentumDurationX, momentumDurationY);
- imageCurrentX = newPositionX;
- imageCurrentY = newPositionY;
- // Define if we need image drag
- var scaledWidth = imageWidth * scale;
- var scaledHeight = imageHeight * scale;
- imageMinX = Math.min((pb.swiper.width / 2 - scaledWidth / 2), 0);
- imageMaxX = -imageMinX;
- imageMinY = Math.min((pb.swiper.height / 2 - scaledHeight / 2), 0);
- imageMaxY = -imageMinY;
- imageCurrentX = Math.max(Math.min(imageCurrentX, imageMaxX), imageMinX);
- imageCurrentY = Math.max(Math.min(imageCurrentY, imageMaxY), imageMinY);
- gestureImgWrap.transition(momentumDuration).transform('translate3d(' + imageCurrentX + 'px, ' + imageCurrentY + 'px,0)');
- };
- // Swipe Up To Close
- var swipeToCloseIsTouched = false;
- var allowSwipeToClose = true;
- var swipeToCloseDiff, swipeToCloseStart, swipeToCloseCurrent, swipeToCloseStarted = false, swipeToCloseActiveSlide, swipeToCloseTimeStart;
- pb.swipeCloseTouchStart = function () {
- if (!allowSwipeToClose) return;
- swipeToCloseIsTouched = true;
- };
- pb.swipeCloseTouchMove = function (swiper, e) {
- if (!swipeToCloseIsTouched) return;
- if (!swipeToCloseStarted) {
- swipeToCloseStarted = true;
- swipeToCloseStart = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
- swipeToCloseActiveSlide = pb.swiper.slides.eq(pb.swiper.activeIndex);
- swipeToCloseTimeStart = (new Date()).getTime();
- }
- e.preventDefault();
- swipeToCloseCurrent = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY;
- swipeToCloseDiff = swipeToCloseStart - swipeToCloseCurrent;
- var opacity = 1 - Math.abs(swipeToCloseDiff) / 300;
- swipeToCloseActiveSlide.transform('translate3d(0,' + (-swipeToCloseDiff) + 'px,0)');
- pb.swiper.container.css('opacity', opacity).transition(0);
- };
- pb.swipeCloseTouchEnd = function () {
- swipeToCloseIsTouched = false;
- if (!swipeToCloseStarted) {
- swipeToCloseStarted = false;
- return;
- }
- swipeToCloseStarted = false;
- allowSwipeToClose = false;
- var diff = Math.abs(swipeToCloseDiff);
- var timeDiff = (new Date()).getTime() - swipeToCloseTimeStart;
- if ((timeDiff < 300 && diff > 20) || (timeDiff >= 300 && diff > 100)) {
- setTimeout(function () {
- if (pb.params.type === 'standalone') {
- pb.close();
- }
- if (pb.params.type === 'popup') {
- $.closeModal(pb.popup);
- }
- if (pb.params.onSwipeToClose) {
- pb.params.onSwipeToClose(pb);
- }
- allowSwipeToClose = true;
- }, 0);
- return;
- }
- if (diff !== 0) {
- swipeToCloseActiveSlide.addClass('transitioning').transitionEnd(function () {
- allowSwipeToClose = true;
- swipeToCloseActiveSlide.removeClass('transitioning');
- });
- }
- else {
- allowSwipeToClose = true;
- }
- pb.swiper.container.css('opacity', '').transition('');
- swipeToCloseActiveSlide.transform('');
- };
- return pb;
- };
- PhotoBrowser.prototype = {
- defaults: {
- photos : [],
- container: 'body',
- initialSlide: 0,
- spaceBetween: 20,
- speed: 300,
- zoom: true,
- maxZoom: 3,
- minZoom: 1,
- exposition: true,
- expositionHideCaptions: false,
- type: 'standalone',
- navbar: true,
- toolbar: true,
- theme: 'light',
- swipeToClose: true,
- backLinkText: 'Close',
- ofText: 'of',
- loop: false,
- lazyLoading: false,
- lazyLoadingInPrevNext: false,
- lazyLoadingOnTransitionStart: false,
- /*
- Callbacks:
- onLazyImageLoad(pb, slide, img)
- onLazyImageReady(pb, slide, img)
- onOpen(pb)
- onClose(pb)
- onSlideChangeStart(swiper)
- onSlideChangeEnd(swiper)
- onTap(swiper, e)
- onClick(swiper, e)
- onDoubleTap(swiper, e)
- onSwipeToClose(pb)
- */
- }
- };
- $.photoBrowser = function (params) {
- $.extend(params, $.photoBrowser.prototype.defaults);
- return new PhotoBrowser(params);
- };
- $.photoBrowser.prototype = {
- defaults: {}
- };
- }(Zepto);
|