/** * swiper 3.4.2 * most modern mobile touch slider and framework with hardware accelerated transitions * * http://www.idangero.us/swiper/ * * copyright 2017, vladimir kharlampidi * the idangero.us * http://www.idangero.us/ * * licensed under mit * * released on: march 10, 2017 */ (function () { 'use strict'; var $; /*=========================== swiper ===========================*/ var swiper = function (container, params) { if (!(this instanceof swiper)) return new swiper(container, params); var defaults = { direction: 'horizontal', toucheventstarget: 'container', initialslide: 0, speed: 300, // autoplay autoplay: false, autoplaydisableoninteraction: true, autoplaystoponlast: false, // to support ios's swipe-to-go-back gesture (when being used in-app, with uiwebview). iosedgeswipedetection: false, iosedgeswipethreshold: 20, // free mode freemode: false, freemodemomentum: true, freemodemomentumratio: 1, freemodemomentumbounce: true, freemodemomentumbounceratio: 1, freemodemomentumvelocityratio: 1, freemodesticky: false, freemodeminimumvelocity: 0.02, // autoheight autoheight: false, // set wrapper width setwrappersize: false, // virtual translate virtualtranslate: false, // effects effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow' or 'flip' coverflow: { rotate: 50, stretch: 0, depth: 100, modifier: 1, slideshadows : true }, flip: { slideshadows : true, limitrotation: true }, cube: { slideshadows: true, shadow: true, shadowoffset: 20, shadowscale: 0.94 }, fade: { crossfade: false }, // parallax parallax: false, // zoom zoom: false, zoommax: 3, zoommin: 1, zoomtoggle: true, // scrollbar scrollbar: null, scrollbarhide: true, scrollbardraggable: false, scrollbarsnaponrelease: false, // keyboard mousewheel keyboardcontrol: false, mousewheelcontrol: false, mousewheelreleaseonedges: false, mousewheelinvert: false, mousewheelforcetoaxis: false, mousewheelsensitivity: 1, mousewheeleventstarged: 'container', // hash navigation hashnav: false, hashnavwatchstate: false, // history history: false, // commong nav state replacestate: false, // breakpoints breakpoints: undefined, // slides grid spacebetween: 0, slidesperview: 1, slidespercolumn: 1, slidespercolumnfill: 'column', slidespergroup: 1, centeredslides: false, slidesoffsetbefore: 0, // in px slidesoffsetafter: 0, // in px // round length roundlengths: 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, touchreleaseonedges: false, // unique navigation elements uniquenavelements: true, // pagination pagination: null, paginationelement: 'span', paginationclickable: false, paginationhide: false, paginationbulletrender: null, paginationprogressrender: null, paginationfractionrender: null, paginationcustomrender: null, paginationtype: 'bullets', // 'bullets' or 'progress' or 'fraction' or 'custom' // 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, lazyloadinginprevnextamount: 1, lazyloadingontransitionstart: false, // images preloadimages: true, updateonimagesready: true, // loop loop: false, loopadditionalslides: 0, loopedslides: null, // control control: undefined, controlinverse: false, controlby: 'slide', //or 'container' normalizeslideindex: true, // swiping/no swiping allowswipetoprev: true, allowswipetonext: true, swipehandler: null, //'.swipe-handler', noswiping: true, noswipingclass: 'swiper-no-swiping', // passive listeners passivelisteners: true, // ns containermodifierclass: 'swiper-container-', // new slideclass: 'swiper-slide', slideactiveclass: 'swiper-slide-active', slideduplicateactiveclass: 'swiper-slide-duplicate-active', slidevisibleclass: 'swiper-slide-visible', slideduplicateclass: 'swiper-slide-duplicate', slidenextclass: 'swiper-slide-next', slideduplicatenextclass: 'swiper-slide-duplicate-next', slideprevclass: 'swiper-slide-prev', slideduplicateprevclass: 'swiper-slide-duplicate-prev', wrapperclass: 'swiper-wrapper', bulletclass: 'swiper-pagination-bullet', bulletactiveclass: 'swiper-pagination-bullet-active', buttondisabledclass: 'swiper-button-disabled', paginationcurrentclass: 'swiper-pagination-current', paginationtotalclass: 'swiper-pagination-total', paginationhiddenclass: 'swiper-pagination-hidden', paginationprogressbarclass: 'swiper-pagination-progressbar', paginationclickableclass: 'swiper-pagination-clickable', // new paginationmodifierclass: 'swiper-pagination-', // new lazyloadingclass: 'swiper-lazy', lazystatusloadingclass: 'swiper-lazy-loading', lazystatusloadedclass: 'swiper-lazy-loaded', lazypreloaderclass: 'swiper-lazy-preloader', notificationclass: 'swiper-notification', preloaderclass: 'preloader', zoomcontainerclass: 'swiper-zoom-container', // 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', paginationbulletmessage: 'go to slide {{index}}', // callbacks runcallbacksoninit: true /* callbacks: oninit: function (swiper) ondestroy: function (swiper) onbeforeresize: function (swiper) onafterresize: 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) onkeypress: function (swiper, keycode) */ }; var initialvirtualtranslate = params && params.virtualtranslate; params = params || {}; var originalparams = {}; for (var param in params) { if (typeof params[param] === 'object' && params[param] !== null && !(params[param].nodetype || params[param] === window || params[param] === document || (typeof dom7 !== 'undefined' && params[param] instanceof dom7) || (typeof jquery !== 'undefined' && params[param] instanceof jquery))) { originalparams[param] = {}; for (var deepparam in params[param]) { originalparams[param][deepparam] = params[param][deepparam]; } } else { originalparams[param] = params[param]; } } 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; s.originalparams = originalparams; // classname s.classnames = []; /*========================= dom library and plugins ===========================*/ if (typeof $ !== 'undefined' && typeof dom7 !== 'undefined'){ $ = dom7; } if (typeof $ === 'undefined') { if (typeof dom7 === 'undefined') { $ = window.dom7 || window.zepto || window.jquery; } else { $ = dom7; } if (!$) return; } // export it to swiper instance s.$ = $; /*========================= breakpoints ===========================*/ s.currentbreakpoint = undefined; s.getactivebreakpoint = function () { //get breakpoint for window width if (!s.params.breakpoints) return false; var breakpoint = false; var points = [], point; for ( point in s.params.breakpoints ) { if (s.params.breakpoints.hasownproperty(point)) { points.push(point); } } points.sort(function (a, b) { return parseint(a, 10) > parseint(b, 10); }); for (var i = 0; i < points.length; i++) { point = points[i]; if (point >= window.innerwidth && !breakpoint) { breakpoint = point; } } return breakpoint || 'max'; }; s.setbreakpoint = function () { //set breakpoint for window width and update parameters var breakpoint = s.getactivebreakpoint(); if (breakpoint && s.currentbreakpoint !== breakpoint) { var breakpointsparams = breakpoint in s.params.breakpoints ? s.params.breakpoints[breakpoint] : s.originalparams; var needsreloop = s.params.loop && (breakpointsparams.slidesperview !== s.params.slidesperview); for ( var param in breakpointsparams ) { s.params[param] = breakpointsparams[param]; } s.currentbreakpoint = breakpoint; if(needsreloop && s.destroyloop) { s.reloop(true); } } }; // set breakpoint on load if (s.params.breakpoints) { s.setbreakpoint(); } /*========================= preparation - define container, wrapper and pagination ===========================*/ s.container = $(container); if (s.container.length === 0) return; if (s.container.length > 1) { var swipers = []; s.container.each(function () { var container = this; swipers.push(new swiper(this, params)); }); return swipers; } // save instance in container html element and in data s.container[0].swiper = s; s.container.data('swiper', s); s.classnames.push(s.params.containermodifierclass + s.params.direction); if (s.params.freemode) { s.classnames.push(s.params.containermodifierclass + 'free-mode'); } if (!s.support.flexbox) { s.classnames.push(s.params.containermodifierclass + 'no-flexbox'); s.params.slidespercolumn = 1; } if (s.params.autoheight) { s.classnames.push(s.params.containermodifierclass + 'autoheight'); } // enable slides progress when required if (s.params.parallax || s.params.watchslidesvisibility) { s.params.watchslidesprogress = true; } // max resistance when touchreleaseonedges if (s.params.touchreleaseonedges) { s.params.resistanceratio = 0; } // coverflow / 3d if (['cube', 'coverflow', 'flip'].indexof(s.params.effect) >= 0) { if (s.support.transforms3d) { s.params.watchslidesprogress = true; s.classnames.push(s.params.containermodifierclass + '3d'); } else { s.params.effect = 'slide'; } } if (s.params.effect !== 'slide') { s.classnames.push(s.params.containermodifierclass + 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; } if (s.params.effect === 'fade' || s.params.effect === 'flip') { s.params.slidesperview = 1; s.params.slidespercolumn = 1; s.params.slidespergroup = 1; s.params.watchslidesprogress = true; s.params.spacebetween = 0; if (typeof initialvirtualtranslate === '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.uniquenavelements && typeof s.params.pagination === 'string' && s.paginationcontainer.length > 1 && s.container.find(s.params.pagination).length === 1) { s.paginationcontainer = s.container.find(s.params.pagination); } if (s.params.paginationtype === 'bullets' && s.params.paginationclickable) { s.paginationcontainer.addclass(s.params.paginationmodifierclass + 'clickable'); } else { s.params.paginationclickable = false; } s.paginationcontainer.addclass(s.params.paginationmodifierclass + s.params.paginationtype); } // next/prev buttons if (s.params.nextbutton || s.params.prevbutton) { if (s.params.nextbutton) { s.nextbutton = $(s.params.nextbutton); if (s.params.uniquenavelements && typeof s.params.nextbutton === 'string' && s.nextbutton.length > 1 && s.container.find(s.params.nextbutton).length === 1) { s.nextbutton = s.container.find(s.params.nextbutton); } } if (s.params.prevbutton) { s.prevbutton = $(s.params.prevbutton); if (s.params.uniquenavelements && typeof s.params.prevbutton === 'string' && s.prevbutton.length > 1 && s.container.find(s.params.prevbutton).length === 1) { s.prevbutton = s.container.find(s.params.prevbutton); } } } // is horizontal s.ishorizontal = function () { return s.params.direction === 'horizontal'; }; // s.ish = ish; // rtl s.rtl = s.ishorizontal() && (s.container[0].dir.tolowercase() === 'rtl' || s.container.css('direction') === 'rtl'); if (s.rtl) { s.classnames.push(s.params.containermodifierclass + 'rtl'); } // wrong rtl support if (s.rtl) { s.wrongrtl = s.wrapper.css('display') === '-webkit-box'; } // columns if (s.params.slidespercolumn > 1) { s.classnames.push(s.params.containermodifierclass + 'multirow'); } // check for android if (s.device.android) { s.classnames.push(s.params.containermodifierclass + '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; if (s.params.allowswipetoprev === false && s.params.grabcursor) { s.unsetgrabcursor(); } }; s.lockswipetoprev = function () { s.params.allowswipetoprev = false; if (s.params.allowswipetonext === false && s.params.grabcursor) { s.unsetgrabcursor(); } }; s.lockswipes = function () { s.params.allowswipetonext = s.params.allowswipetoprev = false; if (s.params.grabcursor) s.unsetgrabcursor(); }; s.unlockswipetonext = function () { s.params.allowswipetonext = true; if (s.params.allowswipetoprev === true && s.params.grabcursor) { s.setgrabcursor(); } }; s.unlockswipetoprev = function () { s.params.allowswipetoprev = true; if (s.params.allowswipetonext === true && s.params.grabcursor) { s.setgrabcursor(); } }; s.unlockswipes = function () { s.params.allowswipetonext = s.params.allowswipetoprev = true; if (s.params.grabcursor) s.setgrabcursor(); }; /*========================= round helper ===========================*/ function round(a) { return math.floor(a); } /*========================= set grab cursor ===========================*/ s.setgrabcursor = function(moving) { s.container[0].style.cursor = 'move'; s.container[0].style.cursor = moving ? '-webkit-grabbing' : '-webkit-grab'; s.container[0].style.cursor = moving ? '-moz-grabbin' : '-moz-grab'; s.container[0].style.cursor = moving ? 'grabbing': 'grab'; }; s.unsetgrabcursor = function () { s.container[0].style.cursor = ''; }; if (s.params.grabcursor) { s.setgrabcursor(); } /*========================= update on images ready ===========================*/ s.imagestoload = []; s.imagesloaded = 0; s.loadimage = function (imgelement, src, srcset, sizes, checkforcomplete, callback) { var image; function onready () { if (callback) callback(); } if (!imgelement.complete || !checkforcomplete) { if (src) { image = new window.image(); image.onload = onready; image.onerror = onready; if (sizes) { image.sizes = sizes; } if (srcset) { image.srcset = srcset; } if (src) { 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 || !s) 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')), (s.imagestoload[i].srcset || s.imagestoload[i].getattribute('srcset')), s.imagestoload[i].sizes || s.imagestoload[i].getattribute('sizes'), true, _onready); } }; /*========================= autoplay ===========================*/ s.autoplaytimeoutid = undefined; s.autoplaying = false; s.autoplaypaused = false; function autoplay() { var autoplaydelay = s.params.autoplay; var activeslide = s.slides.eq(s.activeindex); if (activeslide.attr('data-swiper-autoplay')) { autoplaydelay = activeslide.attr('data-swiper-autoplay') || s.params.autoplay; } s.autoplaytimeoutid = settimeout(function () { if (s.params.loop) { s.fixloop(); s._slidenext(); s.emit('onautoplay', s); } else { if (!s.isend) { s._slidenext(); s.emit('onautoplay', s); } else { if (!params.autoplaystoponlast) { s._slideto(0); s.emit('onautoplay', s); } else { s.stopautoplay(); } } } }, autoplaydelay); } 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 (internal) { 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 () { if (!s) return; 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.updateautoheight = function () { var activeslides = []; var newheight = 0; var i; // find slides currently in view if(s.params.slidesperview !== 'auto' && s.params.slidesperview > 1) { for (i = 0; i < math.ceil(s.params.slidesperview); i++) { var index = s.activeindex + i; if(index > s.slides.length) break; activeslides.push(s.slides.eq(index)[0]); } } else { activeslides.push(s.slides.eq(s.activeindex)[0]); } // find new height from heighest slide in view for (i = 0; i < activeslides.length; i++) { if (typeof activeslides[i] !== 'undefined') { var height = activeslides[i].offsetheight; newheight = height > newheight ? height : newheight; } } // update height if (newheight) s.wrapper.css('height', newheight + 'px'); }; s.updatecontainersize = function () { var width, height; if (typeof s.params.width !== 'undefined') { width = s.params.width; } else { width = s.container[0].clientwidth; } if (typeof s.params.height !== 'undefined') { height = s.params.height; } else { height = s.container[0].clientheight; } if (width === 0 && s.ishorizontal() || height === 0 && !s.ishorizontal()) { return; } //subtract paddings width = width - parseint(s.container.css('padding-left'), 10) - parseint(s.container.css('padding-right'), 10); height = height - parseint(s.container.css('padding-top'), 10) - parseint(s.container.css('padding-bottom'), 10); // store values s.width = width; s.height = height; s.size = s.ishorizontal() ? 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 = -s.params.slidesoffsetbefore, i, prevslidesize = 0, index = 0; if (typeof s.size === 'undefined') return; 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; } if (s.params.slidesperview !== 'auto' && s.params.slidespercolumnfill === 'row') { slidesnumbereventorows = math.max(slidesnumbereventorows, s.params.slidesperview * s.params.slidespercolumn); } } // calc slides var slidesize; var slidespercolumn = s.params.slidespercolumn; var slidesperrow = slidesnumbereventorows / slidespercolumn; var numfullcolumns = slidesperrow - (s.params.slidespercolumn * slidesperrow - s.slides.length); 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; if (s.params.slidespercolumnfill === 'column') { column = math.floor(i / slidespercolumn); row = i - column * slidespercolumn; if (column > numfullcolumns || (column === numfullcolumns && row === slidespercolumn-1)) { if (++row >= slidespercolumn) { row = 0; column++; } } 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 { row = math.floor(i / slidesperrow); column = i - row * slidesperrow; } slide .css( 'margin-' + (s.ishorizontal() ? 'top' : 'left'), (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 = s.ishorizontal() ? slide.outerwidth(true) : slide.outerheight(true); if (s.params.roundlengths) slidesize = round(slidesize); } else { slidesize = (s.size - (s.params.slidesperview - 1) * spacebetween) / s.params.slidesperview; if (s.params.roundlengths) slidesize = round(slidesize); if (s.ishorizontal()) { 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(prevslidesize === 0 && i !== 0) slideposition = slideposition - s.size / 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) + s.params.slidesoffsetafter; 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 (s.ishorizontal()) 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; if (s.ishorizontal()) s.wrapper.css({width: s.virtualsize + s.params.spacebetween + 'px'}); else s.wrapper.css({height: 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]) > 1) { s.snapgrid.push(s.virtualsize - s.size); } } if (s.snapgrid.length === 0) s.snapgrid = [0]; if (s.params.spacebetween !== 0) { if (s.ishorizontal()) { 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 = s.ishorizontal() ? s.slides[i].offsetleft : s.slides[i].offsettop; } }; /*========================= dynamic slides per view ===========================*/ s.currentslidesperview = function () { var spv = 1, i, j; if (s.params.centeredslides) { var size = s.slides[s.activeindex].swiperslidesize; var breakloop; for (i = s.activeindex + 1; i < s.slides.length; i++) { if (s.slides[i] && !breakloop) { size += s.slides[i].swiperslidesize; spv ++; if (size > s.size) breakloop = true; } } for (j = s.activeindex - 1; j >= 0; j--) { if (s.slides[j] && !breakloop) { size += s.slides[j].swiperslidesize; spv ++; if (size > s.size) breakloop = true; } } } else { for (i = s.activeindex + 1; i < s.slides.length; i++) { if (s.slidesgrid[i] - s.slidesgrid[s.activeindex] < s.size) { spv++; } } } return spv; }; /*========================= 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 = -translate; if (s.rtl) offsetcenter = translate; // visible slides s.slides.removeclass(s.params.slidevisibleclass); for (var i = 0; i < s.slides.length; i++) { var slide = s.slides[i]; var slideprogress = (offsetcenter + (s.params.centeredslides ? s.mintranslate() : 0) - slide.swiperslideoffset) / (slide.swiperslidesize + s.params.spacebetween); if (s.params.watchslidesvisibility) { var slidebefore = -(offsetcenter - slide.swiperslideoffset); 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(); var wasbeginning = s.isbeginning; var wasend = s.isend; 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 && !wasbeginning) s.emit('onreachbeginning', s); if (s.isend && !wasend) 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(s.params.normalizeslideindex){ 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(); s.updaterealindex(); }; s.updaterealindex = function(){ s.realindex = parseint(s.slides.eq(s.activeindex).attr('data-swiper-slide-index') || s.activeindex, 10); }; /*========================= classes ===========================*/ s.updateclasses = function () { s.slides.removeclass(s.params.slideactiveclass + ' ' + s.params.slidenextclass + ' ' + s.params.slideprevclass + ' ' + s.params.slideduplicateactiveclass + ' ' + s.params.slideduplicatenextclass + ' ' + s.params.slideduplicateprevclass); var activeslide = s.slides.eq(s.activeindex); // active classes activeslide.addclass(s.params.slideactiveclass); if (params.loop) { // duplicate to all looped slides if (activeslide.hasclass(s.params.slideduplicateclass)) { s.wrapper.children('.' + s.params.slideclass + ':not(.' + s.params.slideduplicateclass + ')[data-swiper-slide-index="' + s.realindex + '"]').addclass(s.params.slideduplicateactiveclass); } else { s.wrapper.children('.' + s.params.slideclass + '.' + s.params.slideduplicateclass + '[data-swiper-slide-index="' + s.realindex + '"]').addclass(s.params.slideduplicateactiveclass); } } // next slide var nextslide = activeslide.next('.' + s.params.slideclass).addclass(s.params.slidenextclass); if (s.params.loop && nextslide.length === 0) { nextslide = s.slides.eq(0); nextslide.addclass(s.params.slidenextclass); } // prev slide var prevslide = activeslide.prev('.' + s.params.slideclass).addclass(s.params.slideprevclass); if (s.params.loop && prevslide.length === 0) { prevslide = s.slides.eq(-1); prevslide.addclass(s.params.slideprevclass); } if (params.loop) { // duplicate to all looped slides if (nextslide.hasclass(s.params.slideduplicateclass)) { s.wrapper.children('.' + s.params.slideclass + ':not(.' + s.params.slideduplicateclass + ')[data-swiper-slide-index="' + nextslide.attr('data-swiper-slide-index') + '"]').addclass(s.params.slideduplicatenextclass); } else { s.wrapper.children('.' + s.params.slideclass + '.' + s.params.slideduplicateclass + '[data-swiper-slide-index="' + nextslide.attr('data-swiper-slide-index') + '"]').addclass(s.params.slideduplicatenextclass); } if (prevslide.hasclass(s.params.slideduplicateclass)) { s.wrapper.children('.' + s.params.slideclass + ':not(.' + s.params.slideduplicateclass + ')[data-swiper-slide-index="' + prevslide.attr('data-swiper-slide-index') + '"]').addclass(s.params.slideduplicateprevclass); } else { s.wrapper.children('.' + s.params.slideclass + '.' + s.params.slideduplicateclass + '[data-swiper-slide-index="' + prevslide.attr('data-swiper-slide-index') + '"]').addclass(s.params.slideduplicateprevclass); } } // pagination if (s.paginationcontainer && s.paginationcontainer.length > 0) { // current/total var current, total = s.params.loop ? math.ceil((s.slides.length - s.loopedslides * 2) / s.params.slidespergroup) : s.snapgrid.length; if (s.params.loop) { current = math.ceil((s.activeindex - s.loopedslides)/s.params.slidespergroup); if (current > s.slides.length - 1 - s.loopedslides * 2) { current = current - (s.slides.length - s.loopedslides * 2); } if (current > total - 1) current = current - total; if (current < 0 && s.params.paginationtype !== 'bullets') current = total + current; } else { if (typeof s.snapindex !== 'undefined') { current = s.snapindex; } else { current = s.activeindex || 0; } } // types if (s.params.paginationtype === 'bullets' && s.bullets && s.bullets.length > 0) { s.bullets.removeclass(s.params.bulletactiveclass); if (s.paginationcontainer.length > 1) { s.bullets.each(function () { if ($(this).index() === current) $(this).addclass(s.params.bulletactiveclass); }); } else { s.bullets.eq(current).addclass(s.params.bulletactiveclass); } } if (s.params.paginationtype === 'fraction') { s.paginationcontainer.find('.' + s.params.paginationcurrentclass).text(current + 1); s.paginationcontainer.find('.' + s.params.paginationtotalclass).text(total); } if (s.params.paginationtype === 'progress') { var scale = (current + 1) / total, scalex = scale, scaley = 1; if (!s.ishorizontal()) { scaley = scale; scalex = 1; } s.paginationcontainer.find('.' + s.params.paginationprogressbarclass).transform('translate3d(0,0,0) scalex(' + scalex + ') scaley(' + scaley + ')').transition(s.params.speed); } if (s.params.paginationtype === 'custom' && s.params.paginationcustomrender) { s.paginationcontainer.html(s.params.paginationcustomrender(s, current + 1, total)); s.emit('onpaginationrendered', s, s.paginationcontainer[0]); } } // next/active buttons if (!s.params.loop) { if (s.params.prevbutton && s.prevbutton && s.prevbutton.length > 0) { if (s.isbeginning) { s.prevbutton.addclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.disable(s.prevbutton); } else { s.prevbutton.removeclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.enable(s.prevbutton); } } if (s.params.nextbutton && s.nextbutton && s.nextbutton.length > 0) { if (s.isend) { s.nextbutton.addclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.disable(s.nextbutton); } else { s.nextbutton.removeclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.enable(s.nextbutton); } } } }; /*========================= pagination ===========================*/ s.updatepagination = function () { if (!s.params.pagination) return; if (s.paginationcontainer && s.paginationcontainer.length > 0) { var paginationhtml = ''; if (s.params.paginationtype === 'bullets') { 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) { paginationhtml += s.params.paginationbulletrender(s, i, s.params.bulletclass); } else { paginationhtml += '<' + s.params.paginationelement+' class="' + s.params.bulletclass + '">'; } } s.paginationcontainer.html(paginationhtml); s.bullets = s.paginationcontainer.find('.' + s.params.bulletclass); if (s.params.paginationclickable && s.params.a11y && s.a11y) { s.a11y.initpagination(); } } if (s.params.paginationtype === 'fraction') { if (s.params.paginationfractionrender) { paginationhtml = s.params.paginationfractionrender(s, s.params.paginationcurrentclass, s.params.paginationtotalclass); } else { paginationhtml = '' + ' / ' + ''; } s.paginationcontainer.html(paginationhtml); } if (s.params.paginationtype === 'progress') { if (s.params.paginationprogressrender) { paginationhtml = s.params.paginationprogressrender(s, s.params.paginationprogressbarclass); } else { paginationhtml = ''; } s.paginationcontainer.html(paginationhtml); } if (s.params.paginationtype !== 'custom') { s.emit('onpaginationrendered', s, s.paginationcontainer[0]); } } }; /*========================= common update method ===========================*/ s.update = function (updatetranslate) { if (!s) return; s.updatecontainersize(); s.updateslidessize(); s.updateprogress(); s.updatepagination(); s.updateclasses(); if (s.params.scrollbar && s.scrollbar) { s.scrollbar.set(); } var newtranslate; function forcesettranslate() { var translate = s.rtl ? -s.translate : s.translate; newtranslate = math.min(math.max(s.translate, s.maxtranslate()), s.mintranslate()); s.setwrappertranslate(newtranslate); s.updateactiveindex(); s.updateclasses(); } if (updatetranslate) { var translated; if (s.controller && s.controller.spline) { s.controller.spline = undefined; } if (s.params.freemode) { forcesettranslate(); if (s.params.autoheight) { s.updateautoheight(); } } else { if ((s.params.slidesperview === 'auto' || s.params.slidesperview > 1) && 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(); } } } else if (s.params.autoheight) { s.updateautoheight(); } }; /*========================= resize handler ===========================*/ s.onresize = function (forceupdatepagination) { if (s.params.onbeforeresize) s.params.onbeforeresize(s); //breakpoints if (s.params.breakpoints) { s.setbreakpoint(); } // disable locks on resize var allowswipetoprev = s.params.allowswipetoprev; var allowswipetonext = s.params.allowswipetonext; s.params.allowswipetoprev = s.params.allowswipetonext = true; s.updatecontainersize(); s.updateslidessize(); if (s.params.slidesperview === 'auto' || s.params.freemode || forceupdatepagination) s.updatepagination(); if (s.params.scrollbar && s.scrollbar) { s.scrollbar.set(); } if (s.controller && s.controller.spline) { s.controller.spline = undefined; } var slidechangedbyslideto = false; if (s.params.freemode) { var newtranslate = math.min(math.max(s.translate, s.maxtranslate()), s.mintranslate()); s.setwrappertranslate(newtranslate); s.updateactiveindex(); s.updateclasses(); if (s.params.autoheight) { s.updateautoheight(); } } else { s.updateclasses(); if ((s.params.slidesperview === 'auto' || s.params.slidesperview > 1) && s.isend && !s.params.centeredslides) { slidechangedbyslideto = s.slideto(s.slides.length - 1, 0, false, true); } else { slidechangedbyslideto = s.slideto(s.activeindex, 0, false, true); } } if (s.params.lazyloading && !slidechangedbyslideto && s.lazy) { s.lazy.load(); } // return locks after resize s.params.allowswipetoprev = allowswipetoprev; s.params.allowswipetonext = allowswipetonext; if (s.params.onafterresize) s.params.onafterresize(s); }; /*========================= events ===========================*/ //define touch events s.toucheventsdesktop = {start: 'mousedown', move: 'mousemove', end: 'mouseup'}; if (window.navigator.pointerenabled) s.toucheventsdesktop = {start: 'pointerdown', move: 'pointermove', end: 'pointerup'}; else if (window.navigator.mspointerenabled) s.toucheventsdesktop = {start: 'mspointerdown', move: 'mspointermove', end: 'mspointerup'}; s.touchevents = { start : s.support.touch || !s.params.simulatetouch ? 'touchstart' : s.toucheventsdesktop.start, move : s.support.touch || !s.params.simulatetouch ? 'touchmove' : s.toucheventsdesktop.move, end : s.support.touch || !s.params.simulatetouch ? 'touchend' : s.toucheventsdesktop.end }; // 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) { var passivelistener = s.touchevents.start === 'touchstart' && s.support.passivelistener && s.params.passivelisteners ? {passive: true, capture: false} : false; toucheventstarget[action](s.touchevents.start, s.ontouchstart, passivelistener); toucheventstarget[action](s.touchevents.move, s.ontouchmove, movecapture); toucheventstarget[action](s.touchevents.end, s.ontouchend, passivelistener); } if ((params.simulatetouch && !s.device.ios && !s.device.android) || (params.simulatetouch && !s.support.touch && s.device.ios)) { toucheventstarget[action]('mousedown', s.ontouchstart, false); document[action]('mousemove', s.ontouchmove, movecapture); document[action]('mouseup', s.ontouchend, false); } } window[action]('resize', s.onresize); // next, prev, index if (s.params.nextbutton && s.nextbutton && s.nextbutton.length > 0) { s.nextbutton[actiondom]('click', s.onclicknext); if (s.params.a11y && s.a11y) s.nextbutton[actiondom]('keydown', s.a11y.onenterkey); } if (s.params.prevbutton && s.prevbutton && s.prevbutton.length > 0) { s.prevbutton[actiondom]('click', s.onclickprev); if (s.params.a11y && s.a11y) s.prevbutton[actiondom]('keydown', s.a11y.onenterkey); } if (s.params.pagination && s.params.paginationclickable) { s.paginationcontainer[actiondom]('click', '.' + s.params.bulletclass, s.onclickindex); if (s.params.a11y && s.a11y) s.paginationcontainer[actiondom]('keydown', '.' + s.params.bulletclass, s.a11y.onenterkey); } // 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 && s.animating) { e.stoppropagation(); e.stopimmediatepropagation(); } } }; // clicks s.onclicknext = function (e) { e.preventdefault(); if (s.isend && !s.params.loop) return; s.slidenext(); }; s.onclickprev = function (e) { e.preventdefault(); if (s.isbeginning && !s.params.loop) return; 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); var slidefound = false; if (slide) { for (var i = 0; i < s.slides.length; i++) { if (s.slides[i] === slide) slidefound = true; } } if (slide && slidefound) { 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, duplicatedslides, slidesperview = s.params.slidesperview === 'auto' ? s.currentslidesperview() : s.params.slidesperview; if (s.params.loop) { if (s.animating) return; realindex = parseint($(s.clickedslide).attr('data-swiper-slide-index'), 10); if (s.params.centeredslides) { if ((slidetoindex < s.loopedslides - slidesperview/2) || (slidetoindex > s.slides.length - s.loopedslides + slidesperview/2)) { s.fixloop(); slidetoindex = s.wrapper.children('.' + s.params.slideclass + '[data-swiper-slide-index="' + realindex + '"]:not(.' + s.params.slideduplicateclass + ')').eq(0).index(); settimeout(function () { s.slideto(slidetoindex); }, 0); } else { s.slideto(slidetoindex); } } else { if (slidetoindex > s.slides.length - slidesperview) { s.fixloop(); slidetoindex = s.wrapper.children('.' + s.params.slideclass + '[data-swiper-slide-index="' + realindex + '"]:not(.' + s.params.slideduplicateclass + ')').eq(0).index(); settimeout(function () { s.slideto(slidetoindex); }, 0); } else { s.slideto(slidetoindex); } } } else { s.slideto(slidetoindex); } } }; var istouched, ismoved, allowtouchcallbacks, touchstarttime, isscrolling, currenttranslate, starttranslate, allowthresholdmove, // form elements to match formelements = 'input, select, textarea, button, video', // 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; } var startx = s.touches.currentx = e.type === 'touchstart' ? e.targettouches[0].pagex : e.pagex; var starty = s.touches.currenty = e.type === 'touchstart' ? e.targettouches[0].pagey : e.pagey; // do not start if ios edge swipe is detected. otherwise ios app (uiwebview) cannot swipe-to-go-back anymore if(s.device.ios && s.params.iosedgeswipedetection && startx <= s.params.iosedgeswipethreshold) { return; } istouched = true; ismoved = false; allowtouchcallbacks = true; isscrolling = undefined; startmoving = undefined; s.touches.startx = startx; s.touches.starty = starty; 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) { s.touches.startx = e.type === 'touchmove' ? e.targettouches[0].pagex : e.pagex; s.touches.starty = e.type === 'touchmove' ? e.targettouches[0].pagey : e.pagey; return; } if (s.params.onlyexternal) { // ismoved = true; s.allowclick = false; if (istouched) { s.touches.startx = s.touches.currentx = e.type === 'touchmove' ? e.targettouches[0].pagex : e.pagex; s.touches.starty = s.touches.currenty = e.type === 'touchmove' ? e.targettouches[0].pagey : e.pagey; touchstarttime = date.now(); } return; } if (istouchevent && s.params.touchreleaseonedges && !s.params.loop) { if (!s.ishorizontal()) { // vertical if ( (s.touches.currenty < s.touches.starty && s.translate <= s.maxtranslate()) || (s.touches.currenty > s.touches.starty && s.translate >= s.mintranslate()) ) { return; } } else { if ( (s.touches.currentx < s.touches.startx && s.translate <= s.maxtranslate()) || (s.touches.currentx > s.touches.startx && s.translate >= s.mintranslate()) ) { return; } } } if (istouchevent && document.activeelement) { if (e.target === document.activeelement && $(e.target).is(formelements)) { ismoved = true; s.allowclick = false; return; } } if (allowtouchcallbacks) { 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; if (s.ishorizontal() && s.touches.currenty === s.touches.starty || !s.ishorizontal() && s.touches.currentx === s.touches.startx) { isscrolling = false; } else { touchangle = math.atan2(math.abs(s.touches.currenty - s.touches.starty), math.abs(s.touches.currentx - s.touches.startx)) * 180 / math.pi; isscrolling = s.ishorizontal() ? touchangle > s.params.touchangle : (90 - touchangle > s.params.touchangle); } } if (isscrolling) { s.emit('ontouchmoveopposite', s, e); } if (typeof startmoving === 'undefined') { 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) { 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.params.allowswipetonext === true || s.params.allowswipetoprev === true)) { s.setgrabcursor(true); } } ismoved = true; var diff = s.touches.diff = s.ishorizontal() ? 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; } // 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 = s.ishorizontal() ? s.touches.currentx - s.touches.startx : s.touches.currenty - s.touches.starty; return; } } else { currenttranslate = starttranslate; return; } } if (!s.params.followfinger) 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[s.ishorizontal() ? 'startx' : 'starty'], time: touchstarttime }); } velocities.push({ position: s.touches[s.ishorizontal() ? 'currentx' : 'currenty'], time: (new window.date()).gettime() }); } // update progress s.updateprogress(currenttranslate); // update translate s.setwrappertranslate(currenttranslate); }; s.ontouchend = function (e) { if (e.originalevent) e = e.originalevent; if (allowtouchcallbacks) { s.emit('ontouchend', s, e); } allowtouchcallbacks = false; if (!istouched) return; //return grab cursor if (s.params.grabcursor && ismoved && istouched && (s.params.allowswipetonext === true || s.params.allowswipetoprev === true)) { s.setgrabcursor(false); } // 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 = 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()) { if (s.slides.length < s.snapgrid.length) { s.slideto(s.snapgrid.length - 1); } else { 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) < s.params.freemodeminimumvelocity) { 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 window.date().gettime() - lastmoveevent.time) > 300) { s.velocity = 0; } } else { s.velocity = 0; } s.velocity = s.velocity * s.params.freemodemomentumvelocityratio; 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(); } } else 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(); } } else if (s.params.freemodesticky) { var j = 0, nextslide; for (j = 0; j < s.snapgrid.length; j += 1) { if (s.snapgrid[j] > -newposition) { nextslide = j; break; } } if (math.abs(s.snapgrid[nextslide] - newposition) < math.abs(s.snapgrid[nextslide - 1] - newposition) || s.swipedirection === 'next') { newposition = s.snapgrid[nextslide]; } else { newposition = s.snapgrid[nextslide - 1]; } if (!s.rtl) newposition = - newposition; } //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); } } else if (s.params.freemodesticky) { s.slidereset(); return; } if (s.params.freemodemomentumbounce && dobounce) { s.updateprogress(afterbounceposition); s.setwrappertransition(momentumduration); s.setwrappertranslate(newposition); s.ontransitionstart(); s.animating = true; s.wrapper.transitionend(function () { if (!s || !allowmomentumbounce) return; s.emit('onmomentumbounce', s); s.setwrappertransition(s.params.speed); s.setwrappertranslate(afterbounceposition); s.wrapper.transitionend(function () { if (!s) return; 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 () { if (!s) return; 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 if(s.params.normalizeslideindex){ for (var i = 0; i < s.slidesgrid.length; i++) { if (- math.floor(translate * 100) >= math.floor(s.slidesgrid[i] * 100)) { slideindex = i; } } } // directions locks if (!s.params.allowswipetonext && translate < s.translate && translate < s.mintranslate()) { return false; } if (!s.params.allowswipetoprev && translate > s.translate && translate > s.maxtranslate()) { if ((s.activeindex || 0) !== slideindex ) return false; } // update index if (typeof speed === 'undefined') speed = s.params.speed; s.previousindex = s.activeindex || 0; s.activeindex = slideindex; s.updaterealindex(); if ((s.rtl && -translate === s.translate) || (!s.rtl && translate === s.translate)) { // update height if (s.params.autoheight) { s.updateautoheight(); } s.updateclasses(); if (s.params.effect !== 'slide') { s.setwrappertranslate(translate); } return false; } s.updateclasses(); s.ontransitionstart(runcallbacks); if (speed === 0 || s.browser.lteie9) { s.setwrappertranslate(translate); s.setwrappertransition(0); s.ontransitionend(runcallbacks); } else { s.setwrappertranslate(translate); s.setwrappertransition(speed); if (!s.animating) { s.animating = true; s.wrapper.transitionend(function () { if (!s) return; s.ontransitionend(runcallbacks); }); } } return true; }; s.ontransitionstart = function (runcallbacks) { if (typeof runcallbacks === 'undefined') runcallbacks = true; if (s.params.autoheight) { s.updateautoheight(); } if (s.lazy) s.lazy.ontransitionstart(); if (runcallbacks) { s.emit('ontransitionstart', s); if (s.activeindex !== s.previousindex) { s.emit('onslidechangestart', s); if (s.activeindex > s.previousindex) { s.emit('onslidenextstart', s); } else { s.emit('onslideprevstart', 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.activeindex > s.previousindex) { s.emit('onslidenextend', s); } else { s.emit('onslideprevend', s); } } } if (s.params.history && s.history) { s.history.sethistory(s.params.history, s.activeindex); } 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(); var clientleft = s.container[0].clientleft; 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(); var clientleft = s.container[0].clientleft; 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, internal) { return s.slideto(s.activeindex, speed, runcallbacks); }; s.disabletouchcontrol = function () { s.params.onlyexternal = true; return true; }; s.enabletouchcontrol = function () { s.params.onlyexternal = false; return true; }; /*========================= 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 (s.ishorizontal()) { x = s.rtl ? -translate : translate; } else { y = translate; } if (s.params.roundlengths) { x = round(x); y = round(y); } 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 = s.ishorizontal() ? x : y; // check if we need to update progress var progress; var translatesdiff = s.maxtranslate() - s.mintranslate(); if (translatesdiff === 0) { progress = 0; } else { progress = (translate - s.mintranslate()) / (translatesdiff); } if (progress !== s.progress) { s.updateprogress(translate); } 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) { curtransform = curstyle.transform || curstyle.webkittransform; if (curtransform.split(',').length > 6) { curtransform = curtransform.split(', ').map(function(a){ return a.replace(',','.'); }).join(', '); } // some old versions of webkit choke when 'none' is passed; pass // empty string instead in this case transformmatrix = new window.webkitcssmatrix(curtransform === 'none' ? '' : curtransform); } 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 = s.ishorizontal() ? '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(true); 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); if(s.params.slidesperview === 'auto' && !s.params.loopedslides) s.params.loopedslides = slides.length; 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.reloop = function (updateposition) { var oldindex = s.activeindex - s.loopedslides; s.destroyloop(); s.createloop(); s.updateslidessize(); if (updateposition) { s.slideto(oldindex + s.loopedslides, 0, false); } }; 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(); s.slides = s.wrapper.children('.' + s.params.slideclass); } 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.loop) { s.createloop(); } if (!(s.params.observer && s.support.observer)) { s.update(true); } if (s.params.loop) { s.slideto(newactiveindex + s.loopedslides, 0, false); } else { 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: { 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 (!s.ishorizontal()) { 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); 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 eventtriggered = false; s.slides.transitionend(function () { if (eventtriggered) return; if (!s) return; eventtriggered = true; s.animating = false; var triggerevents = ['webkittransitionend', 'transitionend', 'otransitionend', 'mstransitionend', 'mstransitionend']; for (var i = 0; i < triggerevents.length; i++) { s.wrapper.trigger(triggerevents[i]); } }); } } }, flip: { settranslate: function () { for (var i = 0; i < s.slides.length; i++) { var slide = s.slides.eq(i); var progress = slide[0].progress; if (s.params.flip.limitrotation) { progress = math.max(math.min(slide[0].progress, 1), -1); } var offset = slide[0].swiperslideoffset; var rotate = -180 * progress, rotatey = rotate, rotatex = 0, tx = -offset, ty = 0; if (!s.ishorizontal()) { ty = tx; tx = 0; rotatex = -rotatey; rotatey = 0; } else if (s.rtl) { rotatey = -rotatey; } slide[0].style.zindex = -math.abs(math.round(progress)) + s.slides.length; if (s.params.flip.slideshadows) { //set shadows var shadowbefore = s.ishorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); var shadowafter = s.ishorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); if (shadowbefore.length === 0) { shadowbefore = $('
'); slide.append(shadowbefore); } if (shadowafter.length === 0) { shadowafter = $('
'); slide.append(shadowafter); } if (shadowbefore.length) shadowbefore[0].style.opacity = math.max(-progress, 0); if (shadowafter.length) shadowafter[0].style.opacity = math.max(progress, 0); } slide .transform('translate3d(' + tx + 'px, ' + ty + 'px, 0px) rotatex(' + rotatex + 'deg) rotatey(' + rotatey + '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.virtualtranslate && duration !== 0) { var eventtriggered = false; s.slides.eq(s.activeindex).transitionend(function () { if (eventtriggered) return; if (!s) return; if (!$(this).hasclass(s.params.slideactiveclass)) return; eventtriggered = true; s.animating = false; 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 (s.ishorizontal()) { cubeshadow = s.wrapper.find('.swiper-cube-shadow'); if (cubeshadow.length === 0) { cubeshadow = $('
'); s.wrapper.append(cubeshadow); } cubeshadow.css({height: s.width + 'px'}); } else { cubeshadow = s.container.find('.swiper-cube-shadow'); if (cubeshadow.length === 0) { cubeshadow = $('
'); 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 (!s.ishorizontal()) { ty = tx; tx = 0; } var transform = 'rotatex(' + (s.ishorizontal() ? 0 : -slideangle) + 'deg) rotatey(' + (s.ishorizontal() ? 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 = s.ishorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); var shadowafter = s.ishorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); if (shadowbefore.length === 0) { shadowbefore = $('
'); slide.append(shadowbefore); } if (shadowafter.length === 0) { shadowafter = $('
'); slide.append(shadowafter); } if (shadowbefore.length) shadowbefore[0].style.opacity = math.max(-progress, 0); if (shadowafter.length) shadowafter[0].style.opacity = math.max(progress, 0); } } 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 (s.ishorizontal()) { 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(' + (s.ishorizontal() ? 0 : wrapperrotate) + 'deg) rotatey(' + (s.ishorizontal() ? -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 && !s.ishorizontal()) { s.container.find('.swiper-cube-shadow').transition(duration); } } }, coverflow: { settranslate: function () { var transform = s.translate; var center = s.ishorizontal() ? -transform + s.width / 2 : -transform + s.height / 2; var rotate = s.ishorizontal() ? 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 = s.ishorizontal() ? rotate * offsetmultiplier : 0; var rotatex = s.ishorizontal() ? 0 : rotate * offsetmultiplier; // var rotatez = 0 var translatez = -translate * math.abs(offsetmultiplier); var translatey = s.ishorizontal() ? 0 : s.params.coverflow.stretch * (offsetmultiplier); var translatex = s.ishorizontal() ? 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 = s.ishorizontal() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); var shadowafter = s.ishorizontal() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); if (shadowbefore.length === 0) { shadowbefore = $('
'); slide.append(shadowbefore); } if (shadowafter.length === 0) { shadowafter = $('
'); 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, loadinduplicate) { if (typeof index === 'undefined') return; if (typeof loadinduplicate === 'undefined') loadinduplicate = true; if (s.slides.length === 0) return; var slide = s.slides.eq(index); var img = slide.find('.' + s.params.lazyloadingclass + ':not(.' + s.params.lazystatusloadedclass + '):not(.' + s.params.lazystatusloadingclass + ')'); if (slide.hasclass(s.params.lazyloadingclass) && !slide.hasclass(s.params.lazystatusloadedclass) && !slide.hasclass(s.params.lazystatusloadingclass)) { img = img.add(slide[0]); } if (img.length === 0) return; img.each(function () { var _img = $(this); _img.addclass(s.params.lazystatusloadingclass); var background = _img.attr('data-background'); var src = _img.attr('data-src'), srcset = _img.attr('data-srcset'), sizes = _img.attr('data-sizes'); s.loadimage(_img[0], (src || background), srcset, sizes, false, function () { if (typeof s === 'undefined' || s === null || !s) return; if (background) { _img.css('background-image', 'url("' + background + '")'); _img.removeattr('data-background'); } else { if (srcset) { _img.attr('srcset', srcset); _img.removeattr('data-srcset'); } if (sizes) { _img.attr('sizes', sizes); _img.removeattr('data-sizes'); } if (src) { _img.attr('src', src); _img.removeattr('data-src'); } } _img.addclass(s.params.lazystatusloadedclass).removeclass(s.params.lazystatusloadingclass); slide.find('.' + s.params.lazypreloaderclass + ', .' + s.params.preloaderclass).remove(); if (s.params.loop && loadinduplicate) { var slideoriginalindex = slide.attr('data-swiper-slide-index'); if (slide.hasclass(s.params.slideduplicateclass)) { var originalslide = s.wrapper.children('[data-swiper-slide-index="' + slideoriginalindex + '"]:not(.' + s.params.slideduplicateclass + ')'); s.lazy.loadimageinslide(originalslide.index(), false); } else { var duplicatedslide = s.wrapper.children('.' + s.params.slideduplicateclass + '[data-swiper-slide-index="' + slideoriginalindex + '"]'); s.lazy.loadimageinslide(duplicatedslide.index(), false); } } s.emit('onlazyimageready', s, slide[0], _img[0]); }); s.emit('onlazyimageload', s, slide[0], _img[0]); }); }, load: function () { var i; var slidesperview = s.params.slidesperview; if (slidesperview === 'auto') { slidesperview = 0; } if (!s.lazy.initialimageloaded) s.lazy.initialimageloaded = true; if (s.params.watchslidesvisibility) { s.wrapper.children('.' + s.params.slidevisibleclass).each(function () { s.lazy.loadimageinslide($(this).index()); }); } else { if (slidesperview > 1) { for (i = s.activeindex; i < s.activeindex + slidesperview ; i++) { if (s.slides[i]) s.lazy.loadimageinslide(i); } } else { s.lazy.loadimageinslide(s.activeindex); } } if (s.params.lazyloadinginprevnext) { if (slidesperview > 1 || (s.params.lazyloadinginprevnextamount && s.params.lazyloadinginprevnextamount > 1)) { var amount = s.params.lazyloadinginprevnextamount; var spv = slidesperview; var maxindex = math.min(s.activeindex + spv + math.max(amount, spv), s.slides.length); var minindex = math.max(s.activeindex - math.max(spv, amount), 0); // next slides for (i = s.activeindex + slidesperview; i < maxindex; i++) { if (s.slides[i]) s.lazy.loadimageinslide(i); } // prev slides for (i = minindex; i < s.activeindex ; i++) { if (s.slides[i]) s.lazy.loadimageinslide(i); } } else { 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.load(); } } }, ontransitionend: function () { if (s.params.lazyloading && !s.params.lazyloadingontransitionstart) { s.lazy.load(); } } }; /*========================= scrollbar ===========================*/ s.scrollbar = { istouched: false, setdragposition: function (e) { var sb = s.scrollbar; var x = 0, y = 0; var translate; var pointerposition = s.ishorizontal() ? ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targettouches[0].pagex : e.pagex || e.clientx) : ((e.type === 'touchstart' || e.type === 'touchmove') ? e.targettouches[0].pagey : e.pagey || e.clienty) ; var position = (pointerposition) - sb.track.offset()[s.ishorizontal() ? 'left' : 'top'] - sb.dragsize / 2; var positionmin = -s.mintranslate() * sb.movedivider; var positionmax = -s.maxtranslate() * sb.movedivider; if (position < positionmin) { position = positionmin; } else if (position > positionmax) { position = positionmax; } position = -position / sb.movedivider; s.updateprogress(position); s.setwrappertranslate(position, true); }, dragstart: function (e) { var sb = s.scrollbar; sb.istouched = true; e.preventdefault(); e.stoppropagation(); sb.setdragposition(e); cleartimeout(sb.dragtimeout); sb.track.transition(0); if (s.params.scrollbarhide) { sb.track.css('opacity', 1); } s.wrapper.transition(100); sb.drag.transition(100); s.emit('onscrollbardragstart', s); }, dragmove: function (e) { var sb = s.scrollbar; if (!sb.istouched) return; if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; sb.setdragposition(e); s.wrapper.transition(0); sb.track.transition(0); sb.drag.transition(0); s.emit('onscrollbardragmove', s); }, dragend: function (e) { var sb = s.scrollbar; if (!sb.istouched) return; sb.istouched = false; if (s.params.scrollbarhide) { cleartimeout(sb.dragtimeout); sb.dragtimeout = settimeout(function () { sb.track.css('opacity', 0); sb.track.transition(400); }, 1000); } s.emit('onscrollbardragend', s); if (s.params.scrollbarsnaponrelease) { s.slidereset(); } }, draggableevents: (function () { if ((s.params.simulatetouch === false && !s.support.touch)) return s.toucheventsdesktop; else return s.touchevents; })(), enabledraggable: function () { var sb = s.scrollbar; var target = s.support.touch ? sb.track : document; $(sb.track).on(sb.draggableevents.start, sb.dragstart); $(target).on(sb.draggableevents.move, sb.dragmove); $(target).on(sb.draggableevents.end, sb.dragend); }, disabledraggable: function () { var sb = s.scrollbar; var target = s.support.touch ? sb.track : document; $(sb.track).off(sb.draggableevents.start, sb.dragstart); $(target).off(sb.draggableevents.move, sb.dragmove); $(target).off(sb.draggableevents.end, sb.dragend); }, set: function () { if (!s.params.scrollbar) return; var sb = s.scrollbar; sb.track = $(s.params.scrollbar); if (s.params.uniquenavelements && typeof s.params.scrollbar === 'string' && sb.track.length > 1 && s.container.find(s.params.scrollbar).length === 1) { sb.track = s.container.find(s.params.scrollbar); } sb.drag = sb.track.find('.swiper-scrollbar-drag'); if (sb.drag.length === 0) { sb.drag = $('
'); sb.track.append(sb.drag); } sb.drag[0].style.width = ''; sb.drag[0].style.height = ''; sb.tracksize = s.ishorizontal() ? 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 (s.ishorizontal()) { 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 diff; var sb = s.scrollbar; var translate = s.translate || 0; var newpos; var newsize = sb.dragsize; newpos = (sb.tracksize - sb.dragsize) * s.progress; if (s.rtl && s.ishorizontal()) { 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 (s.ishorizontal()) { 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 = { linearspline: function (x, y) { var binarysearch = (function() { var maxindex, minindex, guess; return function(array, val) { minindex = -1; maxindex = array.length; while (maxindex - minindex > 1) if (array[guess = maxindex + minindex >> 1] <= val) { minindex = guess; } else { maxindex = guess; } return maxindex; }; })(); this.x = x; this.y = y; this.lastindex = x.length - 1; // given an x value (x2), return the expected y2 value: // (x1,y1) is the known point before given value, // (x3,y3) is the known point after given value. var i1, i3; var l = this.x.length; this.interpolate = function (x2) { if (!x2) return 0; // get the indexes of x1 and x3 (the array indexes before and after given x2): i3 = binarysearch(this.x, x2); i1 = i3 - 1; // we have our indexes i1 & i3, so we can calculate already: // y2 := ((x2鈭抶1) 脳 (y3鈭抷1)) 梅 (x3鈭抶1) + y1 return ((x2 - this.x[i1]) * (this.y[i3] - this.y[i1])) / (this.x[i3] - this.x[i1]) + this.y[i1]; }; }, //xxx: for now i will just save one spline function to to getinterpolatefunction: function(c){ if(!s.controller.spline) s.controller.spline = s.params.loop ? new s.controller.linearspline(s.slidesgrid, c.slidesgrid) : new s.controller.linearspline(s.snapgrid, c.snapgrid); }, settranslate: function (translate, bycontroller) { var controlled = s.params.control; var multiplier, controlledtranslate; function setcontrolledtranslate(c) { // this will create an interpolate function based on the snapgrids // x is the grid of the scrolled scroller and y will be the controlled scroller // it makes sense to create this only once and recall it for the interpolation // the function does a lot of value caching for performance translate = c.rtl && c.params.direction === 'horizontal' ? -s.translate : s.translate; if (s.params.controlby === 'slide') { s.controller.getinterpolatefunction(c); // i am not sure why the values have to be multiplicated this way, tried to invert the snapgrid // but it did not work out controlledtranslate = -s.controller.spline.interpolate(-translate); } if(!controlledtranslate || s.params.controlby === 'container'){ multiplier = (c.maxtranslate() - c.mintranslate()) / (s.maxtranslate() - s.mintranslate()); controlledtranslate = (translate - s.mintranslate()) * multiplier + c.mintranslate(); } if (s.params.controlinverse) { controlledtranslate = c.maxtranslate() - controlledtranslate; } c.updateprogress(controlledtranslate); c.setwrappertranslate(controlledtranslate, false, s); c.updateactiveindex(); } if (array.isarray(controlled)) { for (var i = 0; i < controlled.length; i++) { if (controlled[i] !== bycontroller && controlled[i] instanceof swiper) { setcontrolledtranslate(controlled[i]); } } } else if (controlled instanceof swiper && bycontroller !== controlled) { setcontrolledtranslate(controlled); } }, settransition: function (duration, bycontroller) { var controlled = s.params.control; var i; function setcontrolledtransition(c) { c.setwrappertransition(duration, s); if (duration !== 0) { c.ontransitionstart(); c.wrapper.transitionend(function(){ if (!controlled) return; if (c.params.loop && s.params.controlby === 'slide') { c.fixloop(); } c.ontransitionend(); }); } } if (array.isarray(controlled)) { for (i = 0; i < controlled.length; i++) { if (controlled[i] !== bycontroller && controlled[i] instanceof swiper) { setcontrolledtransition(controlled[i]); } } } else if (controlled instanceof swiper && bycontroller !== controlled) { setcontrolledtransition(controlled); } } }; /*========================= hash navigation ===========================*/ s.hashnav = { onhashcange: function (e, a) { var newhash = document.location.hash.replace('#', ''); var activeslidehash = s.slides.eq(s.activeindex).attr('data-hash'); if (newhash !== activeslidehash) { s.slideto(s.wrapper.children('.' + s.params.slideclass + '[data-hash="' + (newhash) + '"]').index()); } }, attachevents: function (detach) { var action = detach ? 'off' : 'on'; $(window)[action]('hashchange', s.hashnav.onhashcange); }, sethash: function () { if (!s.hashnav.initialized || !s.params.hashnav) return; if (s.params.replacestate && window.history && window.history.replacestate) { window.history.replacestate(null, null, ('#' + s.slides.eq(s.activeindex).attr('data-hash') || '')); } else { var slide = s.slides.eq(s.activeindex); var hash = slide.attr('data-hash') || slide.attr('data-history'); document.location.hash = hash || ''; } }, init: function () { if (!s.params.hashnav || s.params.history) return; s.hashnav.initialized = true; var hash = document.location.hash.replace('#', ''); if (hash) { var speed = 0; for (var i = 0, length = s.slides.length; i < length; i++) { var slide = s.slides.eq(i); var slidehash = slide.attr('data-hash') || slide.attr('data-history'); if (slidehash === hash && !slide.hasclass(s.params.slideduplicateclass)) { var index = slide.index(); s.slideto(index, speed, s.params.runcallbacksoninit, true); } } } if (s.params.hashnavwatchstate) s.hashnav.attachevents(); }, destroy: function () { if (s.params.hashnavwatchstate) s.hashnav.attachevents(true); } }; /*========================= history api with fallback to hashnav ===========================*/ s.history = { init: function () { if (!s.params.history) return; if (!window.history || !window.history.pushstate) { s.params.history = false; s.params.hashnav = true; return; } s.history.initialized = true; this.paths = this.getpathvalues(); if (!this.paths.key && !this.paths.value) return; this.scrolltoslide(0, this.paths.value, s.params.runcallbacksoninit); if (!s.params.replacestate) { window.addeventlistener('popstate', this.sethistorypopstate); } }, sethistorypopstate: function() { s.history.paths = s.history.getpathvalues(); s.history.scrolltoslide(s.params.speed, s.history.paths.value, false); }, getpathvalues: function() { var patharray = window.location.pathname.slice(1).split('/'); var total = patharray.length; var key = patharray[total - 2]; var value = patharray[total - 1]; return { key: key, value: value }; }, sethistory: function (key, index) { if (!s.history.initialized || !s.params.history) return; var slide = s.slides.eq(index); var value = this.slugify(slide.attr('data-history')); if (!window.location.pathname.includes(key)) { value = key + '/' + value; } if (s.params.replacestate) { window.history.replacestate(null, null, value); } else { window.history.pushstate(null, null, value); } }, slugify: function(text) { return text.tostring().tolowercase() .replace(/\s+/g, '-') .replace(/[^\w\-]+/g, '') .replace(/\-\-+/g, '-') .replace(/^-+/, '') .replace(/-+$/, ''); }, scrolltoslide: function(speed, value, runcallbacks) { if (value) { for (var i = 0, length = s.slides.length; i < length; i++) { var slide = s.slides.eq(i); var slidehistory = this.slugify(slide.attr('data-history')); if (slidehistory === value && !slide.hasclass(s.params.slideduplicateclass)) { var index = slide.index(); s.slideto(index, speed, runcallbacks); } } } else { s.slideto(0, speed, runcallbacks); } } }; /*========================= keyboard control ===========================*/ function handlekeyboard(e) { if (e.originalevent) e = e.originalevent; //jquery fix var kc = e.keycode || e.charcode; // directions locks if (!s.params.allowswipetonext && (s.ishorizontal() && kc === 39 || !s.ishorizontal() && kc === 40)) { return false; } if (!s.params.allowswipetoprev && (s.ishorizontal() && kc === 37 || !s.ishorizontal() && kc === 38)) { return false; } if (e.shiftkey || e.altkey || e.ctrlkey || e.metakey) { return; } if (document.activeelement && document.activeelement.nodename && (document.activeelement.nodename.tolowercase() === 'input' || document.activeelement.nodename.tolowercase() === 'textarea')) { return; } if (kc === 37 || kc === 39 || kc === 38 || kc === 40) { var inview = false; //check that swiper should be inside of visible area of window if (s.container.parents('.' + s.params.slideclass).length > 0 && s.container.parents('.' + s.params.slideactiveclass).length === 0) { return; } var windowscroll = { left: window.pagexoffset, top: window.pageyoffset }; var windowwidth = window.innerwidth; var windowheight = window.innerheight; var swiperoffset = s.container.offset(); if (s.rtl) swiperoffset.left = swiperoffset.left - s.container[0].scrollleft; var swipercoord = [ [swiperoffset.left, swiperoffset.top], [swiperoffset.left + s.width, swiperoffset.top], [swiperoffset.left, swiperoffset.top + s.height], [swiperoffset.left + s.width, swiperoffset.top + s.height] ]; for (var i = 0; i < swipercoord.length; i++) { var point = swipercoord[i]; if ( point[0] >= windowscroll.left && point[0] <= windowscroll.left + windowwidth && point[1] >= windowscroll.top && point[1] <= windowscroll.top + windowheight ) { inview = true; } } if (!inview) return; } if (s.ishorizontal()) { if (kc === 37 || kc === 39) { if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; } if ((kc === 39 && !s.rtl) || (kc === 37 && s.rtl)) s.slidenext(); if ((kc === 37 && !s.rtl) || (kc === 39 && s.rtl)) s.slideprev(); } else { if (kc === 38 || kc === 40) { if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; } if (kc === 40) s.slidenext(); if (kc === 38) s.slideprev(); } s.emit('onkeypress', s, kc); } s.disablekeyboardcontrol = function () { s.params.keyboardcontrol = false; $(document).off('keydown', handlekeyboard); }; s.enablekeyboardcontrol = function () { s.params.keyboardcontrol = true; $(document).on('keydown', handlekeyboard); }; /*========================= mousewheel control ===========================*/ s.mousewheel = { event: false, lastscrolltime: (new window.date()).gettime() }; function iseventsupported() { var eventname = 'onwheel'; var issupported = eventname in document; if (!issupported) { var element = document.createelement('div'); element.setattribute(eventname, 'return;'); issupported = typeof element[eventname] === 'function'; } if (!issupported && document.implementation && document.implementation.hasfeature && // always returns true in newer browsers as per the standard. // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature document.implementation.hasfeature('', '') !== true ) { // this is the only way to test support for the `wheel` event in ie9+. issupported = document.implementation.hasfeature('events.wheel', '3.0'); } return issupported; } /** * mouse wheel (and 2-finger trackpad) support on the web sucks. it is * complicated, thus this doc is long and (hopefully) detailed enough to answer * your questions. * * if you need to react to the mouse wheel in a predictable way, this code is * like your bestest friend. * hugs * * * as of today, there are 4 dom event types you can listen to: * * 'wheel' -- chrome(31+), ff(17+), ie(9+) * 'mousewheel' -- chrome, ie(6+), opera, safari * 'mozmousepixelscroll' -- ff(3.5 only!) (2010-2013) -- don't bother! * 'dommousescroll' -- ff(0.9.7+) since 2003 * * so what to do? the is the best: * * normalizewheel.geteventtype(); * * in your event callback, use this code to get sane interpretation of the * deltas. this code will return an object with properties: * * spinx -- normalized spin speed (use for zoom) - x plane * spiny -- " - y plane * pixelx -- normalized distance (to pixels) - x plane * pixely -- " - y plane * * wheel values are provided by the browser assuming you are using the wheel to * scroll a web page by a number of lines or pixels (or pages). values can vary * significantly on different platforms and browsers, forgetting that you can * scroll at different speeds. some devices (like trackpads) emit more events * at smaller increments with fine granularity, and some emit massive jumps with * linear speed or acceleration. * * this code does its best to normalize the deltas for you: * * - spin is trying to normalize how far the wheel was spun (or trackpad * dragged). this is super useful for zoom support where you want to * throw away the chunky scroll steps on the pc and make those equal to * the slow and smooth tiny steps on the mac. key data: this code tries to * resolve a single slow step on a wheel to 1. * * - pixel is normalizing the desired scroll delta in pixel units. you'll * get the crazy differences between browsers, but at least it'll be in * pixels! * * - positive value indicates scrolling down/right, negative up/left. this * should translate to positive value zooming in, negative zooming out. * this matches the newer 'wheel' event. * * why are there spinx, spiny (or pixels)? * * - spinx is a 2-finger side drag on the trackpad, and a shift + wheel turn * with a mouse. it results in side-scrolling in the browser by default. * * - spiny is what you expect -- it's the classic axis of a mouse wheel. * * - i dropped spinz/pixelz. it is supported by the dom 3 'wheel' event and * probably is by browsers in conjunction with fancy 3d controllers .. but * you know. * * implementation info: * * examples of 'wheel' event if you scroll slowly (down) by one step with an * average mouse: * * os x + chrome (mouse) - 4 pixel delta (wheeldelta -120) * os x + safari (mouse) - n/a pixel delta (wheeldelta -12) * os x + firefox (mouse) - 0.1 line delta (wheeldelta n/a) * win8 + chrome (mouse) - 100 pixel delta (wheeldelta -120) * win8 + firefox (mouse) - 3 line delta (wheeldelta -120) * * on the trackpad: * * os x + chrome (trackpad) - 2 pixel delta (wheeldelta -6) * os x + firefox (trackpad) - 1 pixel delta (wheeldelta n/a) * * on other/older browsers.. it's more complicated as there can be multiple and * also missing delta values. * * the 'wheel' event is more standard: * * http://www.w3.org/tr/dom-level-3-events/#events-wheelevents * * the basics is that it includes a unit, deltamode (pixels, lines, pages), and * deltax, deltay and deltaz. some browsers provide other values to maintain * backward compatibility with older events. those other values help us * better normalize spin speed. example of what the browsers provide: * * | event.wheeldelta | event.detail * ------------------+------------------+-------------- * safari v5/os x | -120 | 0 * safari v5/win7 | -120 | 0 * chrome v17/os x | -120 | 0 * chrome v17/win7 | -120 | 0 * ie9/win7 | -120 | undefined * firefox v4/os x | undefined | 1 * firefox v4/win7 | undefined | 3 * */ function normalizewheel( /*object*/ event ) /*object*/ { // reasonable defaults var pixel_step = 10; var line_height = 40; var page_height = 800; var sx = 0, sy = 0, // spinx, spiny px = 0, py = 0; // pixelx, pixely // legacy if( 'detail' in event ) { sy = event.detail; } if( 'wheeldelta' in event ) { sy = -event.wheeldelta / 120; } if( 'wheeldeltay' in event ) { sy = -event.wheeldeltay / 120; } if( 'wheeldeltax' in event ) { sx = -event.wheeldeltax / 120; } // side scrolling on ff with dommousescroll if( 'axis' in event && event.axis === event.horizontal_axis ) { sx = sy; sy = 0; } px = sx * pixel_step; py = sy * pixel_step; if( 'deltay' in event ) { py = event.deltay; } if( 'deltax' in event ) { px = event.deltax; } if( (px || py) && event.deltamode ) { if( event.deltamode === 1 ) { // delta in line units px *= line_height; py *= line_height; } else { // delta in page units px *= page_height; py *= page_height; } } // fall-back if spin cannot be determined if( px && !sx ) { sx = (px < 1) ? -1 : 1; } if( py && !sy ) { sy = (py < 1) ? -1 : 1; } return { spinx: sx, spiny: sy, pixelx: px, pixely: py }; } if (s.params.mousewheelcontrol) { /** * the best combination if you prefer spinx + spiny normalization. it favors * the older dommousescroll for firefox, as ff does not include wheeldelta with * 'wheel' event, making spin speed determination impossible. */ s.mousewheel.event = (navigator.useragent.indexof('firefox') > -1) ? 'dommousescroll' : iseventsupported() ? 'wheel' : 'mousewheel'; } function handlemousewheel(e) { if (e.originalevent) e = e.originalevent; //jquery fix var delta = 0; var rtlfactor = s.rtl ? -1 : 1; var data = normalizewheel( e ); if (s.params.mousewheelforcetoaxis) { if (s.ishorizontal()) { if (math.abs(data.pixelx) > math.abs(data.pixely)) delta = data.pixelx * rtlfactor; else return; } else { if (math.abs(data.pixely) > math.abs(data.pixelx)) delta = data.pixely; else return; } } else { delta = math.abs(data.pixelx) > math.abs(data.pixely) ? - data.pixelx * rtlfactor : - data.pixely; } if (delta === 0) return; if (s.params.mousewheelinvert) delta = -delta; if (!s.params.freemode) { if ((new window.date()).gettime() - s.mousewheel.lastscrolltime > 60) { if (delta < 0) { if ((!s.isend || s.params.loop) && !s.animating) { s.slidenext(); s.emit('onscroll', s, e); } else if (s.params.mousewheelreleaseonedges) return true; } else { if ((!s.isbeginning || s.params.loop) && !s.animating) { s.slideprev(); s.emit('onscroll', s, e); } else if (s.params.mousewheelreleaseonedges) return true; } } s.mousewheel.lastscrolltime = (new window.date()).gettime(); } else { //freemode or scrollcontainer: var position = s.getwrappertranslate() + delta * s.params.mousewheelsensitivity; var wasbeginning = s.isbeginning, wasend = s.isend; if (position >= s.mintranslate()) position = s.mintranslate(); if (position <= s.maxtranslate()) position = s.maxtranslate(); s.setwrappertransition(0); s.setwrappertranslate(position); s.updateprogress(); s.updateactiveindex(); if (!wasbeginning && s.isbeginning || !wasend && s.isend) { s.updateclasses(); } if (s.params.freemodesticky) { cleartimeout(s.mousewheel.timeout); s.mousewheel.timeout = settimeout(function () { s.slidereset(); }, 300); } else { if (s.params.lazyloading && s.lazy) { s.lazy.load(); } } // emit event s.emit('onscroll', s, e); // stop autoplay if (s.params.autoplay && s.params.autoplaydisableoninteraction) s.stopautoplay(); // return page scroll on edge positions if (position === 0 || position === s.maxtranslate()) return; } if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; return false; } s.disablemousewheelcontrol = function () { if (!s.mousewheel.event) return false; var target = s.container; if (s.params.mousewheeleventstarged !== 'container') { target = $(s.params.mousewheeleventstarged); } target.off(s.mousewheel.event, handlemousewheel); s.params.mousewheelcontrol = false; return true; }; s.enablemousewheelcontrol = function () { if (!s.mousewheel.event) return false; var target = s.container; if (s.params.mousewheeleventstarged !== 'container') { target = $(s.params.mousewheeleventstarged); } target.on(s.mousewheel.event, handlemousewheel); s.params.mousewheelcontrol = true; return true; }; /*========================= parallax ===========================*/ function setparallaxtransform(el, progress) { el = $(el); var p, px, py; var rtlfactor = s.rtl ? -1 : 1; 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 (s.ishorizontal()) { px = p; py = '0'; } else { py = p; px = '0'; } } if ((px).indexof('%') >= 0) { px = parseint(px, 10) * progress * rtlfactor + '%'; } else { px = px * progress * rtlfactor + '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); }); } }; /*========================= zoom ===========================*/ s.zoom = { // "global" props scale: 1, currentscale: 1, isscaling: false, gesture: { slide: undefined, slidewidth: undefined, slideheight: undefined, image: undefined, imagewrap: undefined, zoommax: s.params.zoommax }, image: { istouched: undefined, ismoved: undefined, currentx: undefined, currenty: undefined, minx: undefined, miny: undefined, maxx: undefined, maxy: undefined, width: undefined, height: undefined, startx: undefined, starty: undefined, touchesstart: {}, touchescurrent: {} }, velocity: { x: undefined, y: undefined, prevpositionx: undefined, prevpositiony: undefined, prevtime: undefined }, // calc scale from multi-touches getdistancebetweentouches: function (e) { if (e.targettouches.length < 2) return 1; var x1 = e.targettouches[0].pagex, y1 = e.targettouches[0].pagey, x2 = e.targettouches[1].pagex, y2 = e.targettouches[1].pagey; var distance = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2)); return distance; }, // events ongesturestart: function (e) { var z = s.zoom; if (!s.support.gestures) { if (e.type !== 'touchstart' || e.type === 'touchstart' && e.targettouches.length < 2) { return; } z.gesture.scalestart = z.getdistancebetweentouches(e); } if (!z.gesture.slide || !z.gesture.slide.length) { z.gesture.slide = $(this); if (z.gesture.slide.length === 0) z.gesture.slide = s.slides.eq(s.activeindex); z.gesture.image = z.gesture.slide.find('img, svg, canvas'); z.gesture.imagewrap = z.gesture.image.parent('.' + s.params.zoomcontainerclass); z.gesture.zoommax = z.gesture.imagewrap.attr('data-swiper-zoom') || s.params.zoommax ; if (z.gesture.imagewrap.length === 0) { z.gesture.image = undefined; return; } } z.gesture.image.transition(0); z.isscaling = true; }, ongesturechange: function (e) { var z = s.zoom; if (!s.support.gestures) { if (e.type !== 'touchmove' || e.type === 'touchmove' && e.targettouches.length < 2) { return; } z.gesture.scalemove = z.getdistancebetweentouches(e); } if (!z.gesture.image || z.gesture.image.length === 0) return; if (s.support.gestures) { z.scale = e.scale * z.currentscale; } else { z.scale = (z.gesture.scalemove / z.gesture.scalestart) * z.currentscale; } if (z.scale > z.gesture.zoommax) { z.scale = z.gesture.zoommax - 1 + math.pow((z.scale - z.gesture.zoommax + 1), 0.5); } if (z.scale < s.params.zoommin) { z.scale = s.params.zoommin + 1 - math.pow((s.params.zoommin - z.scale + 1), 0.5); } z.gesture.image.transform('translate3d(0,0,0) scale(' + z.scale + ')'); }, ongestureend: function (e) { var z = s.zoom; if (!s.support.gestures) { if (e.type !== 'touchend' || e.type === 'touchend' && e.changedtouches.length < 2) { return; } } if (!z.gesture.image || z.gesture.image.length === 0) return; z.scale = math.max(math.min(z.scale, z.gesture.zoommax), s.params.zoommin); z.gesture.image.transition(s.params.speed).transform('translate3d(0,0,0) scale(' + z.scale + ')'); z.currentscale = z.scale; z.isscaling = false; if (z.scale === 1) z.gesture.slide = undefined; }, ontouchstart: function (s, e) { var z = s.zoom; if (!z.gesture.image || z.gesture.image.length === 0) return; if (z.image.istouched) return; if (s.device.os === 'android') e.preventdefault(); z.image.istouched = true; z.image.touchesstart.x = e.type === 'touchstart' ? e.targettouches[0].pagex : e.pagex; z.image.touchesstart.y = e.type === 'touchstart' ? e.targettouches[0].pagey : e.pagey; }, ontouchmove: function (e) { var z = s.zoom; if (!z.gesture.image || z.gesture.image.length === 0) return; s.allowclick = false; if (!z.image.istouched || !z.gesture.slide) return; if (!z.image.ismoved) { z.image.width = z.gesture.image[0].offsetwidth; z.image.height = z.gesture.image[0].offsetheight; z.image.startx = s.gettranslate(z.gesture.imagewrap[0], 'x') || 0; z.image.starty = s.gettranslate(z.gesture.imagewrap[0], 'y') || 0; z.gesture.slidewidth = z.gesture.slide[0].offsetwidth; z.gesture.slideheight = z.gesture.slide[0].offsetheight; z.gesture.imagewrap.transition(0); if (s.rtl) z.image.startx = -z.image.startx; if (s.rtl) z.image.starty = -z.image.starty; } // define if we need image drag var scaledwidth = z.image.width * z.scale; var scaledheight = z.image.height * z.scale; if (scaledwidth < z.gesture.slidewidth && scaledheight < z.gesture.slideheight) return; z.image.minx = math.min((z.gesture.slidewidth / 2 - scaledwidth / 2), 0); z.image.maxx = -z.image.minx; z.image.miny = math.min((z.gesture.slideheight / 2 - scaledheight / 2), 0); z.image.maxy = -z.image.miny; z.image.touchescurrent.x = e.type === 'touchmove' ? e.targettouches[0].pagex : e.pagex; z.image.touchescurrent.y = e.type === 'touchmove' ? e.targettouches[0].pagey : e.pagey; if (!z.image.ismoved && !z.isscaling) { if (s.ishorizontal() && (math.floor(z.image.minx) === math.floor(z.image.startx) && z.image.touchescurrent.x < z.image.touchesstart.x) || (math.floor(z.image.maxx) === math.floor(z.image.startx) && z.image.touchescurrent.x > z.image.touchesstart.x) ) { z.image.istouched = false; return; } else if (!s.ishorizontal() && (math.floor(z.image.miny) === math.floor(z.image.starty) && z.image.touchescurrent.y < z.image.touchesstart.y) || (math.floor(z.image.maxy) === math.floor(z.image.starty) && z.image.touchescurrent.y > z.image.touchesstart.y) ) { z.image.istouched = false; return; } } e.preventdefault(); e.stoppropagation(); z.image.ismoved = true; z.image.currentx = z.image.touchescurrent.x - z.image.touchesstart.x + z.image.startx; z.image.currenty = z.image.touchescurrent.y - z.image.touchesstart.y + z.image.starty; if (z.image.currentx < z.image.minx) { z.image.currentx = z.image.minx + 1 - math.pow((z.image.minx - z.image.currentx + 1), 0.8); } if (z.image.currentx > z.image.maxx) { z.image.currentx = z.image.maxx - 1 + math.pow((z.image.currentx - z.image.maxx + 1), 0.8); } if (z.image.currenty < z.image.miny) { z.image.currenty = z.image.miny + 1 - math.pow((z.image.miny - z.image.currenty + 1), 0.8); } if (z.image.currenty > z.image.maxy) { z.image.currenty = z.image.maxy - 1 + math.pow((z.image.currenty - z.image.maxy + 1), 0.8); } //velocity if (!z.velocity.prevpositionx) z.velocity.prevpositionx = z.image.touchescurrent.x; if (!z.velocity.prevpositiony) z.velocity.prevpositiony = z.image.touchescurrent.y; if (!z.velocity.prevtime) z.velocity.prevtime = date.now(); z.velocity.x = (z.image.touchescurrent.x - z.velocity.prevpositionx) / (date.now() - z.velocity.prevtime) / 2; z.velocity.y = (z.image.touchescurrent.y - z.velocity.prevpositiony) / (date.now() - z.velocity.prevtime) / 2; if (math.abs(z.image.touchescurrent.x - z.velocity.prevpositionx) < 2) z.velocity.x = 0; if (math.abs(z.image.touchescurrent.y - z.velocity.prevpositiony) < 2) z.velocity.y = 0; z.velocity.prevpositionx = z.image.touchescurrent.x; z.velocity.prevpositiony = z.image.touchescurrent.y; z.velocity.prevtime = date.now(); z.gesture.imagewrap.transform('translate3d(' + z.image.currentx + 'px, ' + z.image.currenty + 'px,0)'); }, ontouchend: function (s, e) { var z = s.zoom; if (!z.gesture.image || z.gesture.image.length === 0) return; if (!z.image.istouched || !z.image.ismoved) { z.image.istouched = false; z.image.ismoved = false; return; } z.image.istouched = false; z.image.ismoved = false; var momentumdurationx = 300; var momentumdurationy = 300; var momentumdistancex = z.velocity.x * momentumdurationx; var newpositionx = z.image.currentx + momentumdistancex; var momentumdistancey = z.velocity.y * momentumdurationy; var newpositiony = z.image.currenty + momentumdistancey; //fix duration if (z.velocity.x !== 0) momentumdurationx = math.abs((newpositionx - z.image.currentx) / z.velocity.x); if (z.velocity.y !== 0) momentumdurationy = math.abs((newpositiony - z.image.currenty) / z.velocity.y); var momentumduration = math.max(momentumdurationx, momentumdurationy); z.image.currentx = newpositionx; z.image.currenty = newpositiony; // define if we need image drag var scaledwidth = z.image.width * z.scale; var scaledheight = z.image.height * z.scale; z.image.minx = math.min((z.gesture.slidewidth / 2 - scaledwidth / 2), 0); z.image.maxx = -z.image.minx; z.image.miny = math.min((z.gesture.slideheight / 2 - scaledheight / 2), 0); z.image.maxy = -z.image.miny; z.image.currentx = math.max(math.min(z.image.currentx, z.image.maxx), z.image.minx); z.image.currenty = math.max(math.min(z.image.currenty, z.image.maxy), z.image.miny); z.gesture.imagewrap.transition(momentumduration).transform('translate3d(' + z.image.currentx + 'px, ' + z.image.currenty + 'px,0)'); }, ontransitionend: function (s) { var z = s.zoom; if (z.gesture.slide && s.previousindex !== s.activeindex) { z.gesture.image.transform('translate3d(0,0,0) scale(1)'); z.gesture.imagewrap.transform('translate3d(0,0,0)'); z.gesture.slide = z.gesture.image = z.gesture.imagewrap = undefined; z.scale = z.currentscale = 1; } }, // toggle zoom togglezoom: function (s, e) { var z = s.zoom; if (!z.gesture.slide) { z.gesture.slide = s.clickedslide ? $(s.clickedslide) : s.slides.eq(s.activeindex); z.gesture.image = z.gesture.slide.find('img, svg, canvas'); z.gesture.imagewrap = z.gesture.image.parent('.' + s.params.zoomcontainerclass); } if (!z.gesture.image || z.gesture.image.length === 0) return; var touchx, touchy, offsetx, offsety, diffx, diffy, translatex, translatey, imagewidth, imageheight, scaledwidth, scaledheight, translateminx, translateminy, translatemaxx, translatemaxy, slidewidth, slideheight; if (typeof z.image.touchesstart.x === 'undefined' && e) { touchx = e.type === 'touchend' ? e.changedtouches[0].pagex : e.pagex; touchy = e.type === 'touchend' ? e.changedtouches[0].pagey : e.pagey; } else { touchx = z.image.touchesstart.x; touchy = z.image.touchesstart.y; } if (z.scale && z.scale !== 1) { // zoom out z.scale = z.currentscale = 1; z.gesture.imagewrap.transition(300).transform('translate3d(0,0,0)'); z.gesture.image.transition(300).transform('translate3d(0,0,0) scale(1)'); z.gesture.slide = undefined; } else { // zoom in z.scale = z.currentscale = z.gesture.imagewrap.attr('data-swiper-zoom') || s.params.zoommax; if (e) { slidewidth = z.gesture.slide[0].offsetwidth; slideheight = z.gesture.slide[0].offsetheight; offsetx = z.gesture.slide.offset().left; offsety = z.gesture.slide.offset().top; diffx = offsetx + slidewidth/2 - touchx; diffy = offsety + slideheight/2 - touchy; imagewidth = z.gesture.image[0].offsetwidth; imageheight = z.gesture.image[0].offsetheight; scaledwidth = imagewidth * z.scale; scaledheight = imageheight * z.scale; translateminx = math.min((slidewidth / 2 - scaledwidth / 2), 0); translateminy = math.min((slideheight / 2 - scaledheight / 2), 0); translatemaxx = -translateminx; translatemaxy = -translateminy; translatex = diffx * z.scale; translatey = diffy * z.scale; if (translatex < translateminx) { translatex = translateminx; } if (translatex > translatemaxx) { translatex = translatemaxx; } if (translatey < translateminy) { translatey = translateminy; } if (translatey > translatemaxy) { translatey = translatemaxy; } } else { translatex = 0; translatey = 0; } z.gesture.imagewrap.transition(300).transform('translate3d(' + translatex + 'px, ' + translatey + 'px,0)'); z.gesture.image.transition(300).transform('translate3d(0,0,0) scale(' + z.scale + ')'); } }, // attach/detach events attachevents: function (detach) { var action = detach ? 'off' : 'on'; if (s.params.zoom) { var target = s.slides; var passivelistener = s.touchevents.start === 'touchstart' && s.support.passivelistener && s.params.passivelisteners ? {passive: true, capture: false} : false; // scale image if (s.support.gestures) { s.slides[action]('gesturestart', s.zoom.ongesturestart, passivelistener); s.slides[action]('gesturechange', s.zoom.ongesturechange, passivelistener); s.slides[action]('gestureend', s.zoom.ongestureend, passivelistener); } else if (s.touchevents.start === 'touchstart') { s.slides[action](s.touchevents.start, s.zoom.ongesturestart, passivelistener); s.slides[action](s.touchevents.move, s.zoom.ongesturechange, passivelistener); s.slides[action](s.touchevents.end, s.zoom.ongestureend, passivelistener); } // move image s[action]('touchstart', s.zoom.ontouchstart); s.slides.each(function (index, slide){ if ($(slide).find('.' + s.params.zoomcontainerclass).length > 0) { $(slide)[action](s.touchevents.move, s.zoom.ontouchmove); } }); s[action]('touchend', s.zoom.ontouchend); // scale out s[action]('transitionend', s.zoom.ontransitionend); if (s.params.zoomtoggle) { s.on('doubletap', s.zoom.togglezoom); } } }, init: function () { s.zoom.attachevents(); }, destroy: function () { s.zoom.attachevents(true); } }; /*========================= plugins api. collect all and init all plugins ===========================*/ s._plugins = []; for (var plugin in s.plugins) { 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; // 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.attr('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.lastslidemessage); } else { s.a11y.notify(s.params.nextslidemessage); } } else if ($(event.target).is(s.params.prevbutton)) { s.onclickprev(event); if (s.isbeginning) { s.a11y.notify(s.params.firstslidemessage); } else { s.a11y.notify(s.params.prevslidemessage); } } if ($(event.target).is('.' + s.params.bulletclass)) { $(event.target)[0].click(); } }, liveregion: $(''), 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 && s.nextbutton && s.nextbutton.length > 0) { s.a11y.makefocusable(s.nextbutton); s.a11y.addrole(s.nextbutton, 'button'); s.a11y.addlabel(s.nextbutton, s.params.nextslidemessage); } if (s.params.prevbutton && s.prevbutton && s.prevbutton.length > 0) { s.a11y.makefocusable(s.prevbutton); s.a11y.addrole(s.prevbutton, 'button'); s.a11y.addlabel(s.prevbutton, s.params.prevslidemessage); } $(s.container).append(s.a11y.liveregion); }, initpagination: function () { if (s.params.pagination && s.params.paginationclickable && s.bullets && s.bullets.length) { s.bullets.each(function () { var bullet = $(this); s.a11y.makefocusable(bullet); s.a11y.addrole(bullet, 'button'); s.a11y.addlabel(bullet, s.params.paginationbulletmessage.replace(/{{index}}/, bullet.index() + 1)); }); } }, 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.scrollbardraggable) { s.scrollbar.enabledraggable(); } } 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.lazy.initialimageloaded = true; } } } s.attachevents(); if (s.params.observer && s.support.observer) { s.initobservers(); } if (s.params.preloadimages && !s.params.lazyloading) { s.preloadimages(); } if (s.params.zoom && s.zoom) { s.zoom.init(); } if (s.params.autoplay) { s.startautoplay(); } if (s.params.keyboardcontrol) { if (s.enablekeyboardcontrol) s.enablekeyboardcontrol(); } if (s.params.mousewheelcontrol) { if (s.enablemousewheelcontrol) s.enablemousewheelcontrol(); } // deprecated hashnavreplacestate changed to replacestate for use in hashnav and history if (s.params.hashnavreplacestate) { s.params.replacestate = s.params.hashnavreplacestate; } if (s.params.history) { if (s.history) s.history.init(); } 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(); // disable draggable if (s.params.scrollbar && s.scrollbar) { if (s.params.scrollbardraggable) { s.scrollbar.disabledraggable(); } } // destroy loop if (s.params.loop) { s.destroyloop(); } // cleanup styles if (cleanupstyles) { s.cleanupstyles(); } // disconnect observer s.disconnectobservers(); // destroy zoom if (s.params.zoom && s.zoom) { s.zoom.destroy(); } // 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(); // delete history popstate if (s.params.history && !s.params.replacestate) { window.removeeventlistener('popstate', s.history.sethistorypopstate); } if (s.params.hashnav && s.hashnav) { s.hashnav.destroy(); } // destroy callback s.emit('ondestroy'); // delete instance if (deleteinstance !== false) s = null; }; s.init(); // return swiper instance return s; }; /*================================================== prototype ====================================================*/ swiper.prototype = { issafari: (function () { var ua = window.navigator.useragent.tolowercase(); return (ua.indexof('safari') >= 0 && ua.indexof('chrome') < 0 && ua.indexof('android') < 0); })(), isuiwebview: /(iphone|ipod|ipad).*applewebkit(?!.*safari)/i.test(window.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), lteie9: (function() { // create temporary div var div = document.createelement('div'); // add content to tmp div which is wrapped into the ie html conditional statement div.innerhtml = ''; // return true / false value based on what will browser render return div.getelementsbytagname('i').length === 1; })() }, /*================================================== devices ====================================================*/ device: (function () { var ua = window.navigator.useragent; var android = ua.match(/(android);?[\s\/]+([\d.]+)?/); var ipad = ua.match(/(ipad).*os\s([\d_]+)/); var ipod = ua.match(/(ipod)(.*os\s([\d_]+))?/); var iphone = !ipad && ua.match(/(iphone\sos|ios)\s([\d_]+)/); return { ios: ipad || iphone || ipod, 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); })(), passivelistener: (function () { var supportspassive = false; try { var opts = object.defineproperty({}, 'passive', { get: function() { supportspassive = true; } }); window.addeventlistener('testpassivelistener', null, opts); } catch (e) {} return supportspassive; })(), gestures: (function () { return 'ongesturestart' in window; })() }, /*================================================== plugins ====================================================*/ plugins: {} }; /*=========================== dom7 library ===========================*/ var dom7 = (function () { var dom7 = function (arr) { var _this = this, i = 0; // create array-like object for (i = 0; i < arr.length; i++) { _this[i] = arr[i]; } _this.length = arr.length; // return collection with methods return this; }; var $ = function (selector, context) { var arr = [], i = 0; if (selector && !context) { if (selector instanceof dom7) { return selector; } } if (selector) { // string if (typeof selector === 'string') { var els, tempparent, html = selector.trim(); if (html.indexof('<') >= 0 && html.indexof('>') >= 0) { var tocreate = 'div'; if (html.indexof(':~]/)) { // pure id selector els = [document.getelementbyid(selector.split('#')[1])]; } else { // other selectors els = (context || document).queryselectorall(selector); } for (i = 0; i < els.length; i++) { if (els[i]) arr.push(els[i]); } } } // node/element else if (selector.nodetype || selector === window || selector === document) { arr.push(selector); } //array of elements or instance of dom else if (selector.length > 0 && selector[0].nodetype) { for (i = 0; i < selector.length; i++) { arr.push(selector[i]); } } } return new dom7(arr); }; dom7.prototype = { // classes and attriutes addclass: function (classname) { if (typeof classname === 'undefined') { return this; } var classes = classname.split(' '); for (var i = 0; i < classes.length; i++) { for (var j = 0; j < this.length; j++) { this[j].classlist.add(classes[i]); } } return this; }, removeclass: function (classname) { var classes = classname.split(' '); for (var i = 0; i < classes.length; i++) { for (var j = 0; j < this.length; j++) { this[j].classlist.remove(classes[i]); } } return this; }, hasclass: function (classname) { if (!this[0]) return false; else return this[0].classlist.contains(classname); }, toggleclass: function (classname) { var classes = classname.split(' '); for (var i = 0; i < classes.length; i++) { for (var j = 0; j < this.length; j++) { this[j].classlist.toggle(classes[i]); } } return this; }, attr: function (attrs, value) { if (arguments.length === 1 && typeof attrs === 'string') { // get attr if (this[0]) return this[0].getattribute(attrs); else return undefined; } else { // set attrs for (var i = 0; i < this.length; i++) { if (arguments.length === 2) { // string this[i].setattribute(attrs, value); } else { // object for (var attrname in attrs) { this[i][attrname] = attrs[attrname]; this[i].setattribute(attrname, attrs[attrname]); } } } return this; } }, removeattr: function (attr) { for (var i = 0; i < this.length; i++) { this[i].removeattribute(attr); } return this; }, data: function (key, value) { if (typeof value === 'undefined') { // get value if (this[0]) { var datakey = this[0].getattribute('data-' + key); if (datakey) return datakey; else if (this[0].dom7elementdatastorage && (key in this[0].dom7elementdatastorage)) return this[0].dom7elementdatastorage[key]; else return undefined; } else return undefined; } else { // set value for (var i = 0; i < this.length; i++) { var el = this[i]; if (!el.dom7elementdatastorage) el.dom7elementdatastorage = {}; el.dom7elementdatastorage[key] = value; } return this; } }, // transforms transform : function (transform) { for (var i = 0; i < this.length; i++) { var elstyle = this[i].style; elstyle.webkittransform = elstyle.mstransform = elstyle.mstransform = elstyle.moztransform = elstyle.otransform = elstyle.transform = transform; } return this; }, transition: function (duration) { if (typeof duration !== 'string') { duration = duration + 'ms'; } for (var i = 0; i < this.length; i++) { var elstyle = this[i].style; elstyle.webkittransitionduration = elstyle.mstransitionduration = elstyle.mstransitionduration = elstyle.moztransitionduration = elstyle.otransitionduration = elstyle.transitionduration = duration; } return this; }, //events on: function (eventname, targetselector, listener, capture) { function handleliveevent(e) { var target = e.target; if ($(target).is(targetselector)) listener.call(target, e); else { var parents = $(target).parents(); for (var k = 0; k < parents.length; k++) { if ($(parents[k]).is(targetselector)) listener.call(parents[k], e); } } } var events = eventname.split(' '); var i, j; for (i = 0; i < this.length; i++) { if (typeof targetselector === 'function' || targetselector === false) { // usual events if (typeof targetselector === 'function') { listener = arguments[1]; capture = arguments[2] || false; } for (j = 0; j < events.length; j++) { this[i].addeventlistener(events[j], listener, capture); } } else { //live events for (j = 0; j < events.length; j++) { if (!this[i].dom7livelisteners) this[i].dom7livelisteners = []; this[i].dom7livelisteners.push({listener: listener, livelistener: handleliveevent}); this[i].addeventlistener(events[j], handleliveevent, capture); } } } return this; }, off: function (eventname, targetselector, listener, capture) { var events = eventname.split(' '); for (var i = 0; i < events.length; i++) { for (var j = 0; j < this.length; j++) { if (typeof targetselector === 'function' || targetselector === false) { // usual events if (typeof targetselector === 'function') { listener = arguments[1]; capture = arguments[2] || false; } this[j].removeeventlistener(events[i], listener, capture); } else { // live event if (this[j].dom7livelisteners) { for (var k = 0; k < this[j].dom7livelisteners.length; k++) { if (this[j].dom7livelisteners[k].listener === listener) { this[j].removeeventlistener(events[i], this[j].dom7livelisteners[k].livelistener, capture); } } } } } } return this; }, once: function (eventname, targetselector, listener, capture) { var dom = this; if (typeof targetselector === 'function') { targetselector = false; listener = arguments[1]; capture = arguments[2]; } function proxy(e) { listener(e); dom.off(eventname, targetselector, proxy, capture); } dom.on(eventname, targetselector, proxy, capture); }, trigger: function (eventname, eventdata) { for (var i = 0; i < this.length; i++) { var evt; try { evt = new window.customevent(eventname, {detail: eventdata, bubbles: true, cancelable: true}); } catch (e) { evt = document.createevent('event'); evt.initevent(eventname, true, true); evt.detail = eventdata; } this[i].dispatchevent(evt); } return this; }, transitionend: function (callback) { var events = ['webkittransitionend', 'transitionend', 'otransitionend', 'mstransitionend', 'mstransitionend'], i, j, dom = this; function firecallback(e) { /*jshint validthis:true */ if (e.target !== this) return; callback.call(this, e); for (i = 0; i < events.length; i++) { dom.off(events[i], firecallback); } } if (callback) { for (i = 0; i < events.length; i++) { dom.on(events[i], firecallback); } } return this; }, // sizing/styles width: function () { if (this[0] === window) { return window.innerwidth; } else { if (this.length > 0) { return parsefloat(this.css('width')); } else { return null; } } }, outerwidth: function (includemargins) { if (this.length > 0) { if (includemargins) return this[0].offsetwidth + parsefloat(this.css('margin-right')) + parsefloat(this.css('margin-left')); else return this[0].offsetwidth; } else return null; }, height: function () { if (this[0] === window) { return window.innerheight; } else { if (this.length > 0) { return parsefloat(this.css('height')); } else { return null; } } }, outerheight: function (includemargins) { if (this.length > 0) { if (includemargins) return this[0].offsetheight + parsefloat(this.css('margin-top')) + parsefloat(this.css('margin-bottom')); else return this[0].offsetheight; } else return null; }, offset: function () { if (this.length > 0) { var el = this[0]; var box = el.getboundingclientrect(); var body = document.body; var clienttop = el.clienttop || body.clienttop || 0; var clientleft = el.clientleft || body.clientleft || 0; var scrolltop = window.pageyoffset || el.scrolltop; var scrollleft = window.pagexoffset || el.scrollleft; return { top: box.top + scrolltop - clienttop, left: box.left + scrollleft - clientleft }; } else { return null; } }, css: function (props, value) { var i; if (arguments.length === 1) { if (typeof props === 'string') { if (this[0]) return window.getcomputedstyle(this[0], null).getpropertyvalue(props); } else { for (i = 0; i < this.length; i++) { for (var prop in props) { this[i].style[prop] = props[prop]; } } return this; } } if (arguments.length === 2 && typeof props === 'string') { for (i = 0; i < this.length; i++) { this[i].style[props] = value; } return this; } return this; }, //dom manipulation each: function (callback) { for (var i = 0; i < this.length; i++) { callback.call(this[i], i, this[i]); } return this; }, html: function (html) { if (typeof html === 'undefined') { return this[0] ? this[0].innerhtml : undefined; } else { for (var i = 0; i < this.length; i++) { this[i].innerhtml = html; } return this; } }, text: function (text) { if (typeof text === 'undefined') { if (this[0]) { return this[0].textcontent.trim(); } else return null; } else { for (var i = 0; i < this.length; i++) { this[i].textcontent = text; } return this; } }, is: function (selector) { if (!this[0]) return false; var comparewith, i; if (typeof selector === 'string') { var el = this[0]; if (el === document) return selector === document; if (el === window) return selector === window; if (el.matches) return el.matches(selector); else if (el.webkitmatchesselector) return el.webkitmatchesselector(selector); else if (el.mozmatchesselector) return el.mozmatchesselector(selector); else if (el.msmatchesselector) return el.msmatchesselector(selector); else { comparewith = $(selector); for (i = 0; i < comparewith.length; i++) { if (comparewith[i] === this[0]) return true; } return false; } } else if (selector === document) return this[0] === document; else if (selector === window) return this[0] === window; else { if (selector.nodetype || selector instanceof dom7) { comparewith = selector.nodetype ? [selector] : selector; for (i = 0; i < comparewith.length; i++) { if (comparewith[i] === this[0]) return true; } return false; } return false; } }, index: function () { if (this[0]) { var child = this[0]; var i = 0; while ((child = child.previoussibling) !== null) { if (child.nodetype === 1) i++; } return i; } else return undefined; }, eq: function (index) { if (typeof index === 'undefined') return this; var length = this.length; var returnindex; if (index > length - 1) { return new dom7([]); } if (index < 0) { returnindex = length + index; if (returnindex < 0) return new dom7([]); else return new dom7([this[returnindex]]); } return new dom7([this[index]]); }, append: function (newchild) { var i, j; for (i = 0; i < this.length; i++) { if (typeof newchild === 'string') { var tempdiv = document.createelement('div'); tempdiv.innerhtml = newchild; while (tempdiv.firstchild) { this[i].appendchild(tempdiv.firstchild); } } else if (newchild instanceof dom7) { for (j = 0; j < newchild.length; j++) { this[i].appendchild(newchild[j]); } } else { this[i].appendchild(newchild); } } return this; }, prepend: function (newchild) { var i, j; for (i = 0; i < this.length; i++) { if (typeof newchild === 'string') { var tempdiv = document.createelement('div'); tempdiv.innerhtml = newchild; for (j = tempdiv.childnodes.length - 1; j >= 0; j--) { this[i].insertbefore(tempdiv.childnodes[j], this[i].childnodes[0]); } // this[i].insertadjacenthtml('afterbegin', newchild); } else if (newchild instanceof dom7) { for (j = 0; j < newchild.length; j++) { this[i].insertbefore(newchild[j], this[i].childnodes[0]); } } else { this[i].insertbefore(newchild, this[i].childnodes[0]); } } return this; }, insertbefore: function (selector) { var before = $(selector); for (var i = 0; i < this.length; i++) { if (before.length === 1) { before[0].parentnode.insertbefore(this[i], before[0]); } else if (before.length > 1) { for (var j = 0; j < before.length; j++) { before[j].parentnode.insertbefore(this[i].clonenode(true), before[j]); } } } }, insertafter: function (selector) { var after = $(selector); for (var i = 0; i < this.length; i++) { if (after.length === 1) { after[0].parentnode.insertbefore(this[i], after[0].nextsibling); } else if (after.length > 1) { for (var j = 0; j < after.length; j++) { after[j].parentnode.insertbefore(this[i].clonenode(true), after[j].nextsibling); } } } }, next: function (selector) { if (this.length > 0) { if (selector) { if (this[0].nextelementsibling && $(this[0].nextelementsibling).is(selector)) return new dom7([this[0].nextelementsibling]); else return new dom7([]); } else { if (this[0].nextelementsibling) return new dom7([this[0].nextelementsibling]); else return new dom7([]); } } else return new dom7([]); }, nextall: function (selector) { var nextels = []; var el = this[0]; if (!el) return new dom7([]); while (el.nextelementsibling) { var next = el.nextelementsibling; if (selector) { if($(next).is(selector)) nextels.push(next); } else nextels.push(next); el = next; } return new dom7(nextels); }, prev: function (selector) { if (this.length > 0) { if (selector) { if (this[0].previouselementsibling && $(this[0].previouselementsibling).is(selector)) return new dom7([this[0].previouselementsibling]); else return new dom7([]); } else { if (this[0].previouselementsibling) return new dom7([this[0].previouselementsibling]); else return new dom7([]); } } else return new dom7([]); }, prevall: function (selector) { var prevels = []; var el = this[0]; if (!el) return new dom7([]); while (el.previouselementsibling) { var prev = el.previouselementsibling; if (selector) { if($(prev).is(selector)) prevels.push(prev); } else prevels.push(prev); el = prev; } return new dom7(prevels); }, parent: function (selector) { var parents = []; for (var i = 0; i < this.length; i++) { if (selector) { if ($(this[i].parentnode).is(selector)) parents.push(this[i].parentnode); } else { parents.push(this[i].parentnode); } } return $($.unique(parents)); }, parents: function (selector) { var parents = []; for (var i = 0; i < this.length; i++) { var parent = this[i].parentnode; while (parent) { if (selector) { if ($(parent).is(selector)) parents.push(parent); } else { parents.push(parent); } parent = parent.parentnode; } } return $($.unique(parents)); }, find : function (selector) { var foundelements = []; for (var i = 0; i < this.length; i++) { var found = this[i].queryselectorall(selector); for (var j = 0; j < found.length; j++) { foundelements.push(found[j]); } } return new dom7(foundelements); }, children: function (selector) { var children = []; for (var i = 0; i < this.length; i++) { var childnodes = this[i].childnodes; for (var j = 0; j < childnodes.length; j++) { if (!selector) { if (childnodes[j].nodetype === 1) children.push(childnodes[j]); } else { if (childnodes[j].nodetype === 1 && $(childnodes[j]).is(selector)) children.push(childnodes[j]); } } } return new dom7($.unique(children)); }, remove: function () { for (var i = 0; i < this.length; i++) { if (this[i].parentnode) this[i].parentnode.removechild(this[i]); } return this; }, add: function () { var dom = this; var i, j; for (i = 0; i < arguments.length; i++) { var toadd = $(arguments[i]); for (j = 0; j < toadd.length; j++) { dom[dom.length] = toadd[j]; dom.length++; } } return dom; } }; $.fn = dom7.prototype; $.unique = function (arr) { var unique = []; for (var i = 0; i < arr.length; i++) { if (unique.indexof(arr[i]) === -1) unique.push(arr[i]); } return unique; }; return $; })(); /*=========================== get dom libraries ===========================*/ var swiperdomplugins = ['jquery', 'zepto', 'dom7']; for (var i = 0; i < swiperdomplugins.length; i++) { if (window[swiperdomplugins[i]]) { addlibraryplugin(window[swiperdomplugins[i]]); } } // required dom plugins var domlib; if (typeof dom7 === 'undefined') { domlib = window.dom7 || window.zepto || window.jquery; } else { domlib = dom7; } /*=========================== add .swiper plugin from dom libraries ===========================*/ function addlibraryplugin(lib) { lib.fn.swiper = function (params) { var firstinstance; lib(this).each(function () { var s = new swiper(this, params); if (!firstinstance) firstinstance = s; }); return firstinstance; }; } if (domlib) { if (!('transitionend' in domlib.fn)) { domlib.fn.transitionend = function (callback) { var events = ['webkittransitionend', 'transitionend', 'otransitionend', 'mstransitionend', 'mstransitionend'], i, j, dom = this; function firecallback(e) { /*jshint validthis:true */ if (e.target !== this) return; callback.call(this, e); for (i = 0; i < events.length; i++) { dom.off(events[i], firecallback); } } if (callback) { for (i = 0; i < events.length; i++) { dom.on(events[i], firecallback); } } return this; }; } if (!('transform' in domlib.fn)) { domlib.fn.transform = function (transform) { for (var i = 0; i < this.length; i++) { var elstyle = this[i].style; elstyle.webkittransform = elstyle.mstransform = elstyle.mstransform = elstyle.moztransform = elstyle.otransform = elstyle.transform = transform; } return this; }; } if (!('transition' in domlib.fn)) { domlib.fn.transition = function (duration) { if (typeof duration !== 'string') { duration = duration + 'ms'; } for (var i = 0; i < this.length; i++) { var elstyle = this[i].style; elstyle.webkittransitionduration = elstyle.mstransitionduration = elstyle.mstransitionduration = elstyle.moztransitionduration = elstyle.otransitionduration = elstyle.transitionduration = duration; } return this; }; } if (!('outerwidth' in domlib.fn)) { domlib.fn.outerwidth = function (includemargins) { if (this.length > 0) { if (includemargins) return this[0].offsetwidth + parsefloat(this.css('margin-right')) + parsefloat(this.css('margin-left')); else return this[0].offsetwidth; } else return null; }; } } window.swiper = swiper; })(); /*=========================== swiper amd export ===========================*/ if (typeof(module) !== 'undefined') { module.exports = window.swiper; } else if (typeof define === 'function' && define.amd) { define([], function () { 'use strict'; return window.swiper; }); } //# sourcemappingurl=maps/swiper.js.map