/** * swiper 3.1.0 * most modern mobile touch slider and framework with hardware accelerated transitions * * http://www.idangero.us/swiper/ * * copyright 2015, vladimir kharlampidi * the idangero.us * http://www.idangero.us/ * * licensed under mit * * released on: july 14, 2015 */ (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, // free mode freemode: false, freemodemomentum: true, freemodemomentumratio: 1, freemodemomentumbounce: true, freemodemomentumbounceratio: 1, freemodesticky: false, // set wrapper width setwrappersize: false, // virtual translate virtualtranslate: false, // effects effect: 'slide', // 'slide' or 'fade' or 'cube' or 'coverflow' coverflow: { rotate: 50, stretch: 0, depth: 100, modifier: 1, slideshadows : true }, cube: { slideshadows: true, shadow: true, shadowoffset: 20, shadowscale: 0.94 }, fade: { crossfade: false }, // parallax parallax: false, // scrollbar scrollbar: null, scrollbarhide: true, // keyboard mousewheel keyboardcontrol: false, mousewheelcontrol: false, mousewheelreleaseonedges: false, mousewheelinvert: false, mousewheelforcetoaxis: false, // hash navigation hashnav: false, // 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, // pagination pagination: null, paginationelement: 'span', paginationclickable: false, paginationhide: false, paginationbulletrender: null, // resistance resistance: true, resistanceratio: 0.85, // next/prev buttons nextbutton: null, prevbutton: null, // progress watchslidesprogress: false, watchslidesvisibility: false, // cursor grabcursor: false, // clicks preventclicks: true, preventclickspropagation: true, slidetoclickedslide: false, // lazy loading lazyloading: false, lazyloadinginprevnext: false, lazyloadingontransitionstart: false, // images preloadimages: true, updateonimagesready: true, // loop loop: false, loopadditionalslides: 0, loopedslides: null, // control control: undefined, controlinverse: false, controlby: 'slide', //or 'container' // swiping/no swiping allowswipetoprev: true, allowswipetonext: true, swipehandler: null, //'.swipe-handler', noswiping: true, noswipingclass: 'swiper-no-swiping', // ns slideclass: 'swiper-slide', slideactiveclass: 'swiper-slide-active', slidevisibleclass: 'swiper-slide-visible', slideduplicateclass: 'swiper-slide-duplicate', slidenextclass: 'swiper-slide-next', slideprevclass: 'swiper-slide-prev', wrapperclass: 'swiper-wrapper', bulletclass: 'swiper-pagination-bullet', bulletactiveclass: 'cur', buttondisabledclass: 'swiper-button-disabled', paginationhiddenclass: 'swiper-pagination-hidden', // observer observer: false, observeparents: false, // accessibility a11y: false, prevslidemessage: 'previous slide', nextslidemessage: 'next slide', firstslidemessage: 'this is the first slide', lastslidemessage: 'this is the last slide', paginationbulletmessage: 'go to slide {{index}}', // callbacks runcallbacksoninit: true /* callbacks: oninit: function (swiper) ondestroy: function (swiper) onclick: function (swiper, e) ontap: function (swiper, e) ondoubletap: function (swiper, e) onslidermove: function (swiper, e) onslidechangestart: function (swiper) onslidechangeend: function (swiper) ontransitionstart: function (swiper) ontransitionend: function (swiper) onimagesready: function (swiper) onprogress: function (swiper, progress) ontouchstart: function (swiper, e) ontouchmove: function (swiper, e) ontouchmoveopposite: function (swiper, e) ontouchend: function (swiper, e) onreachbeginning: function (swiper) onreachend: function (swiper) onsettransition: function (swiper, duration) onsettranslate: function (swiper, translate) onautoplaystart: function (swiper) onautoplaystop: function (swiper), onlazyimageload: function (swiper, slide, image) onlazyimageready: function (swiper, slide, image) */ }; var initialvirtualtranslate = params && params.virtualtranslate; params = params || {}; for (var def in defaults) { if (typeof params[def] === 'undefined') { params[def] = defaults[def]; } else if (typeof params[def] === 'object') { for (var deepdef in defaults[def]) { if (typeof params[def][deepdef] === 'undefined') { params[def][deepdef] = defaults[def][deepdef]; } } } } // swiper var s = this; // version s.version = '3.1.0'; // params s.params = params; // 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.$ = $; /*========================= preparation - define container, wrapper and pagination ===========================*/ s.container = $(container); if (s.container.length === 0) return; if (s.container.length > 1) { s.container.each(function () { new swiper(this, params); }); return; } // save instance in container html element and in data s.container[0].swiper = s; s.container.data('swiper', s); s.classnames.push('swiper-container-' + s.params.direction); if (s.params.freemode) { s.classnames.push('swiper-container-free-mode'); } if (!s.support.flexbox) { s.classnames.push('swiper-container-no-flexbox'); s.params.slidespercolumn = 1; } // enable slides progress when required if (s.params.parallax || s.params.watchslidesvisibility) { s.params.watchslidesprogress = true; } // coverflow / 3d if (['cube', 'coverflow'].indexof(s.params.effect) >= 0) { if (s.support.transforms3d) { s.params.watchslidesprogress = true; s.classnames.push('swiper-container-3d'); } else { s.params.effect = 'slide'; } } if (s.params.effect !== 'slide') { s.classnames.push('swiper-container-' + s.params.effect); } if (s.params.effect === 'cube') { s.params.resistanceratio = 0; s.params.slidesperview = 1; s.params.slidespercolumn = 1; s.params.slidespergroup = 1; s.params.centeredslides = false; s.params.spacebetween = 0; s.params.virtualtranslate = true; s.params.setwrappersize = false; } if (s.params.effect === 'fade') { s.params.slidesperview = 1; s.params.slidespercolumn = 1; s.params.slidespergroup = 1; s.params.watchslidesprogress = true; s.params.spacebetween = 0; if (typeof 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.paginationclickable) { s.paginationcontainer.addclass('swiper-pagination-clickable'); } } // is horizontal function ish() { return s.params.direction === 'horizontal'; } // rtl s.rtl = ish() && (s.container[0].dir.tolowercase() === 'rtl' || s.container.css('direction') === 'rtl'); if (s.rtl) { s.classnames.push('swiper-container-rtl'); } // wrong rtl support if (s.rtl) { s.wrongrtl = s.wrapper.css('display') === '-webkit-box'; } // columns if (s.params.slidespercolumn > 1) { s.classnames.push('swiper-container-multirow'); } // check for android if (s.device.android) { s.classnames.push('swiper-container-android'); } // add classes s.container.addclass(s.classnames.join(' ')); // translate s.translate = 0; // progress s.progress = 0; // velocity s.velocity = 0; /*========================= locks, unlocks ===========================*/ s.lockswipetonext = function () { s.params.allowswipetonext = false; }; s.lockswipetoprev = function () { s.params.allowswipetoprev = false; }; s.lockswipes = function () { s.params.allowswipetonext = s.params.allowswipetoprev = false; }; s.unlockswipetonext = function () { s.params.allowswipetonext = true; }; s.unlockswipetoprev = function () { s.params.allowswipetoprev = true; }; s.unlockswipes = function () { s.params.allowswipetonext = s.params.allowswipetoprev = true; }; /*========================= round helper ===========================*/ function round(a) { return math.floor(a); } /*========================= set grab cursor ===========================*/ if (s.params.grabcursor) { s.container[0].style.cursor = 'move'; s.container[0].style.cursor = '-webkit-grab'; s.container[0].style.cursor = '-moz-grab'; s.container[0].style.cursor = 'grab'; } /*========================= update on images ready ===========================*/ s.imagestoload = []; s.imagesloaded = 0; s.loadimage = function (imgelement, src, checkforcomplete, callback) { var image; function onready () { if (callback) callback(); } if (!imgelement.complete || !checkforcomplete) { if (src) { image = new window.image(); image.onload = onready; image.onerror = onready; image.src = src; } else { onready(); } } else {//image already loaded... onready(); } }; s.preloadimages = function () { s.imagestoload = s.container.find('img'); function _onready() { if (typeof s === 'undefined' || s === null) return; if (s.imagesloaded !== undefined) s.imagesloaded++; if (s.imagesloaded === s.imagestoload.length) { if (s.params.updateonimagesready) s.update(); s.emit('onimagesready', s); } } for (var i = 0; i < s.imagestoload.length; i++) { s.loadimage(s.imagestoload[i], (s.imagestoload[i].currentsrc || s.imagestoload[i].getattribute('src')), true, _onready); } }; /*========================= autoplay ===========================*/ s.autoplaytimeoutid = undefined; s.autoplaying = false; s.autoplaypaused = false; function autoplay() { s.autoplaytimeoutid = settimeout(function () { if (s.params.loop) { s.fixloop(); s._slidenext(); } else { if (!s.isend) { s._slidenext(); } else { if (!params.autoplaystoponlast) { s._slideto(0); } else { s.stopautoplay(); } } } }, s.params.autoplay); } s.startautoplay = function () { if (typeof s.autoplaytimeoutid !== 'undefined') return false; if (!s.params.autoplay) return false; if (s.autoplaying) return false; s.autoplaying = true; s.emit('onautoplaystart', s); autoplay(); }; s.stopautoplay = function (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.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 && ish() || height === 0 && !ish()) { 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 = ish() ? s.width : s.height; }; s.updateslidessize = function () { s.slides = s.wrapper.children('.' + s.params.slideclass); s.snapgrid = []; s.slidesgrid = []; s.slidessizesgrid = []; var spacebetween = s.params.spacebetween, slideposition = -s.params.slidesoffsetbefore, i, prevslidesize = 0, index = 0; if (typeof spacebetween === 'string' && spacebetween.indexof('%') >= 0) { spacebetween = parsefloat(spacebetween.replace('%', '')) / 100 * s.size; } s.virtualsize = -spacebetween; // reset margins if (s.rtl) s.slides.css({marginleft: '', margintop: ''}); else s.slides.css({marginright: '', marginbottom: ''}); var slidesnumbereventorows; if (s.params.slidespercolumn > 1) { if (math.floor(s.slides.length / s.params.slidespercolumn) === s.slides.length / s.params.slidespercolumn) { slidesnumbereventorows = s.slides.length; } else { slidesnumbereventorows = math.ceil(s.slides.length / s.params.slidespercolumn) * s.params.slidespercolumn; } } // calc slides var slidesize; 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-top': (row !== 0 && s.params.spacebetween) && (s.params.spacebetween + 'px') }) .attr('data-swiper-column', column) .attr('data-swiper-row', row); } if (slide.css('display') === 'none') continue; if (s.params.slidesperview === 'auto') { slidesize = ish() ? slide.outerwidth(true) : slide.outerheight(true); 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 (ish()) { s.slides[i].style.width = slidesize + 'px'; } else { s.slides[i].style.height = slidesize + 'px'; } } s.slides[i].swiperslidesize = slidesize; s.slidessizesgrid.push(slidesize); if (s.params.centeredslides) { slideposition = slideposition + slidesize / 2 + prevslidesize / 2 + spacebetween; if (i === 0) slideposition = slideposition - s.size / 2 - spacebetween; if (math.abs(slideposition) < 1 / 1000) slideposition = 0; if ((index) % s.params.slidespergroup === 0) s.snapgrid.push(slideposition); s.slidesgrid.push(slideposition); } else { if ((index) % s.params.slidespergroup === 0) s.snapgrid.push(slideposition); s.slidesgrid.push(slideposition); slideposition = slideposition + slidesize + spacebetween; } s.virtualsize += slidesize + spacebetween; prevslidesize = slidesize; index ++; } s.virtualsize = math.max(s.virtualsize, s.size) + 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 (ish()) s.wrapper.css({width: s.virtualsize + s.params.spacebetween + 'px'}); else s.wrapper.css({height: s.virtualsize + s.params.spacebetween + 'px'}); } if (s.params.slidespercolumn > 1) { s.virtualsize = (slidesize + s.params.spacebetween) * slidesnumbereventorows; s.virtualsize = math.ceil(s.virtualsize / s.params.slidespercolumn) - s.params.spacebetween; s.wrapper.css({width: s.virtualsize + s.params.spacebetween + 'px'}); if (s.params.centeredslides) { newslidesgrid = []; for (i = 0; i < s.snapgrid.length; i++) { if (s.snapgrid[i] < s.virtualsize + s.snapgrid[0]) newslidesgrid.push(s.snapgrid[i]); } s.snapgrid = newslidesgrid; } } // remove last grid elements depending on width if (!s.params.centeredslides) { newslidesgrid = []; for (i = 0; i < s.snapgrid.length; i++) { if (s.snapgrid[i] <= s.virtualsize - s.size) { newslidesgrid.push(s.snapgrid[i]); } } s.snapgrid = newslidesgrid; if (math.floor(s.virtualsize - s.size) > math.floor(s.snapgrid[s.snapgrid.length - 1])) { s.snapgrid.push(s.virtualsize - s.size); } } if (s.snapgrid.length === 0) s.snapgrid = [0]; if (s.params.spacebetween !== 0) { if (ish()) { if (s.rtl) s.slides.css({marginleft: spacebetween + 'px'}); else s.slides.css({marginright: spacebetween + 'px'}); } else s.slides.css({marginbottom: spacebetween + 'px'}); } if (s.params.watchslidesprogress) { s.updateslidesoffset(); } }; s.updateslidesoffset = function () { for (var i = 0; i < s.slides.length; i++) { s.slides[i].swiperslideoffset = ish() ? s.slides[i].offsetleft : s.slides[i].offsettop; } }; /*========================= slider/slides progress ===========================*/ s.updateslidesprogress = function (translate) { if (typeof translate === 'undefined') { translate = s.translate || 0; } if (s.slides.length === 0) return; if (typeof s.slides[0].swiperslideoffset === 'undefined') s.updateslidesoffset(); var offsetcenter = s.params.centeredslides ? -translate + s.size / 2 : -translate; if (s.rtl) offsetcenter = s.params.centeredslides ? translate - s.size / 2 : translate; // visible slides var containerbox = s.container[0].getboundingclientrect(); var sidebefore = ish() ? 'left' : 'top'; var sideafter = ish() ? 'right' : 'bottom'; s.slides.removeclass(s.params.slidevisibleclass); for (var i = 0; i < s.slides.length; i++) { var slide = s.slides[i]; var slidecenteroffset = (s.params.centeredslides === true) ? slide.swiperslidesize / 2 : 0; var slideprogress = (offsetcenter - slide.swiperslideoffset - slidecenteroffset) / (slide.swiperslidesize + s.params.spacebetween); if (s.params.watchslidesvisibility) { var slidebefore = -(offsetcenter - slide.swiperslideoffset - slidecenteroffset); var slideafter = slidebefore + s.slidessizesgrid[i]; var isvisible = (slidebefore >= 0 && slidebefore < s.size) || (slideafter > 0 && slideafter <= s.size) || (slidebefore <= 0 && slideafter >= s.size); if (isvisible) { s.slides.eq(i).addclass(s.params.slidevisibleclass); } } slide.progress = s.rtl ? -slideprogress : slideprogress; } }; s.updateprogress = function (translate) { if (typeof translate === 'undefined') { translate = s.translate || 0; } var translatesdiff = s.maxtranslate() - s.mintranslate(); if (translatesdiff === 0) { s.progress = 0; s.isbeginning = s.isend = true; } else { s.progress = (translate - s.mintranslate()) / (translatesdiff); s.isbeginning = s.progress <= 0; s.isend = s.progress >= 1; } if (s.isbeginning) s.emit('onreachbeginning', s); if (s.isend) s.emit('onreachend', s); if (s.params.watchslidesprogress) s.updateslidesprogress(translate); s.emit('onprogress', s, s.progress); }; s.updateactiveindex = function () { var translate = s.rtl ? s.translate : -s.translate; var newactiveindex, i, snapindex; for (i = 0; i < s.slidesgrid.length; i ++) { if (typeof s.slidesgrid[i + 1] !== 'undefined') { if (translate >= s.slidesgrid[i] && translate < s.slidesgrid[i + 1] - (s.slidesgrid[i + 1] - s.slidesgrid[i]) / 2) { newactiveindex = i; } else if (translate >= s.slidesgrid[i] && translate < s.slidesgrid[i + 1]) { newactiveindex = i + 1; } } else { if (translate >= s.slidesgrid[i]) { newactiveindex = i; } } } // normalize slideindex if (newactiveindex < 0 || typeof newactiveindex === 'undefined') newactiveindex = 0; // for (i = 0; i < s.slidesgrid.length; i++) { // if (- translate >= s.slidesgrid[i]) { // newactiveindex = i; // } // } snapindex = math.floor(newactiveindex / s.params.slidespergroup); if (snapindex >= s.snapgrid.length) snapindex = s.snapgrid.length - 1; if (newactiveindex === s.activeindex) { return; } s.snapindex = snapindex; s.previousindex = s.activeindex; s.activeindex = newactiveindex; s.updateclasses(); }; /*========================= classes ===========================*/ s.updateclasses = function () { s.slides.removeclass(s.params.slideactiveclass + ' ' + s.params.slidenextclass + ' ' + s.params.slideprevclass); var activeslide = s.slides.eq(s.activeindex); // active classes activeslide.addclass(s.params.slideactiveclass); activeslide.next('.' + s.params.slideclass).addclass(s.params.slidenextclass); activeslide.prev('.' + s.params.slideclass).addclass(s.params.slideprevclass); // pagination if (s.bullets && s.bullets.length > 0) { s.bullets.removeclass(s.params.bulletactiveclass); var bulletindex; if (s.params.loop) { bulletindex = math.ceil(s.activeindex - s.loopedslides)/s.params.slidespergroup; if (bulletindex > s.slides.length - 1 - s.loopedslides * 2) { bulletindex = bulletindex - (s.slides.length - s.loopedslides * 2); } if (bulletindex > s.bullets.length - 1) bulletindex = bulletindex - s.bullets.length; } else { if (typeof s.snapindex !== 'undefined') { bulletindex = s.snapindex; } else { bulletindex = s.activeindex || 0; } } if (s.paginationcontainer.length > 1) { s.bullets.each(function () { if ($(this).index() === bulletindex) $(this).addclass(s.params.bulletactiveclass); }); } else { s.bullets.eq(bulletindex).addclass(s.params.bulletactiveclass); } } // next/active buttons if (!s.params.loop) { if (s.params.prevbutton) { if (s.isbeginning) { $(s.params.prevbutton).addclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.prevbutton)); } else { $(s.params.prevbutton).removeclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.prevbutton)); } } if (s.params.nextbutton) { if (s.isend) { $(s.params.nextbutton).addclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.disable($(s.params.nextbutton)); } else { $(s.params.nextbutton).removeclass(s.params.buttondisabledclass); if (s.params.a11y && s.a11y) s.a11y.enable($(s.params.nextbutton)); } } } }; /*========================= pagination ===========================*/ s.updatepagination = function () { if (!s.params.pagination) return; if (s.paginationcontainer && s.paginationcontainer.length > 0) { var bulletshtml = ''; var numberofbullets = s.params.loop ? math.ceil((s.slides.length - s.loopedslides * 2) / s.params.slidespergroup) : s.snapgrid.length; for (var i = 0; i < numberofbullets; i++) { if (s.params.paginationbulletrender) { bulletshtml += s.params.paginationbulletrender(i, s.params.bulletclass); } else { bulletshtml += '<' + s.params.paginationelement+' class="' + s.params.bulletclass + '">' + s.params.paginationelement + '>'; } } s.paginationcontainer.html(bulletshtml); s.bullets = s.paginationcontainer.find('.' + s.params.bulletclass); if (s.params.paginationclickable && s.params.a11y && s.a11y) { s.a11y.initpagination(); } } }; /*========================= common update method ===========================*/ s.update = function (updatetranslate) { s.updatecontainersize(); s.updateslidessize(); s.updateprogress(); s.updatepagination(); s.updateclasses(); if (s.params.scrollbar && s.scrollbar) { s.scrollbar.set(); } function forcesettranslate() { newtranslate = math.min(math.max(s.translate, s.maxtranslate()), s.mintranslate()); s.setwrappertranslate(newtranslate); s.updateactiveindex(); s.updateclasses(); } if (updatetranslate) { var translated, newtranslate; if (s.controller && s.controller.spline) { s.controller.spline = undefined; } if (s.params.freemode) { forcesettranslate(); } 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(); } } } }; /*========================= resize handler ===========================*/ s.onresize = function (forceupdatepagination) { // 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; } if (s.params.freemode) { var newtranslate = math.min(math.max(s.translate, s.maxtranslate()), s.mintranslate()); s.setwrappertranslate(newtranslate); s.updateactiveindex(); s.updateclasses(); } else { s.updateclasses(); if ((s.params.slidesperview === 'auto' || s.params.slidesperview > 1) && s.isend && !s.params.centeredslides) { s.slideto(s.slides.length - 1, 0, false, true); } else { s.slideto(s.activeindex, 0, false, true); } } // return locks after resize s.params.allowswipetoprev = allowswipetoprev; s.params.allowswipetonext = allowswipetonext; }; /*========================= events ===========================*/ //define touch events var desktopevents = ['mousedown', 'mousemove', 'mouseup']; if (window.navigator.pointerenabled) desktopevents = ['pointerdown', 'pointermove', 'pointerup']; else if (window.navigator.mspointerenabled) desktopevents = ['mspointerdown', 'mspointermove', 'mspointerup']; s.touchevents = { start : s.support.touch || !s.params.simulatetouch ? 'touchstart' : desktopevents[0], move : s.support.touch || !s.params.simulatetouch ? 'touchmove' : desktopevents[1], end : s.support.touch || !s.params.simulatetouch ? 'touchend' : desktopevents[2] }; // wp8 touch events fix if (window.navigator.pointerenabled || window.navigator.mspointerenabled) { (s.params.toucheventstarget === 'container' ? s.container : s.wrapper).addclass('swiper-wp8-' + s.params.direction); } // attach/detach events s.initevents = function (detach) { var actiondom = detach ? 'off' : 'on'; var action = detach ? 'removeeventlistener' : 'addeventlistener'; var toucheventstarget = s.params.toucheventstarget === 'container' ? s.container[0] : s.wrapper[0]; var target = s.support.touch ? toucheventstarget : document; var movecapture = s.params.nested ? true : false; //touch events if (s.browser.ie) { toucheventstarget[action](s.touchevents.start, s.ontouchstart, false); target[action](s.touchevents.move, s.ontouchmove, movecapture); target[action](s.touchevents.end, s.ontouchend, false); } else { if (s.support.touch) { toucheventstarget[action](s.touchevents.start, s.ontouchstart, false); toucheventstarget[action](s.touchevents.move, s.ontouchmove, movecapture); toucheventstarget[action](s.touchevents.end, s.ontouchend, false); } if (params.simulatetouch && !s.device.ios && !s.device.android) { toucheventstarget[action]('mousedown', s.ontouchstart, false); 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.params.nextbutton)[actiondom]('click', s.onclicknext); if (s.params.a11y && s.a11y) $(s.params.nextbutton)[actiondom]('keydown', s.a11y.onenterkey); } if (s.params.prevbutton) { $(s.params.prevbutton)[actiondom]('click', s.onclickprev); if (s.params.a11y && s.a11y) $(s.params.prevbutton)[actiondom]('keydown', s.a11y.onenterkey); } if (s.params.pagination && s.params.paginationclickable) { $(s.paginationcontainer)[actiondom]('click', '.' + s.params.bulletclass, s.onclickindex); 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 (detach) { 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; if (s.params.loop) { realindex = $(s.clickedslide).attr('data-swiper-slide-index'); if (slidetoindex > s.slides.length - s.params.slidesperview) { s.fixloop(); slidetoindex = s.wrapper.children('.' + s.params.slideclass + '[data-swiper-slide-index="' + realindex + '"]').eq(0).index(); settimeout(function () { s.slideto(slidetoindex); }, 0); } else if (slidetoindex < s.params.slidesperview - 1) { s.fixloop(); var duplicatedslides = s.wrapper.children('.' + s.params.slideclass + '[data-swiper-slide-index="' + realindex + '"]'); slidetoindex = duplicatedslides.eq(duplicatedslides.length - 1).index(); settimeout(function () { s.slideto(slidetoindex); }, 0); } else { s.slideto(slidetoindex); } } else { s.slideto(slidetoindex); } } }; var istouched, ismoved, touchstarttime, isscrolling, currenttranslate, starttranslate, allowthresholdmove, // form elements to match formelements = 'input, select, textarea, button', // last click time lastclicktime = date.now(), clicktimeout, //velocities velocities = [], allowmomentumbounce; // animating flag s.animating = false; // touches information s.touches = { startx: 0, starty: 0, currentx: 0, currenty: 0, diff: 0 }; // touch handlers var istouchevent, startmoving; s.ontouchstart = function (e) { if (e.originalevent) e = e.originalevent; istouchevent = e.type === 'touchstart'; if (!istouchevent && 'which' in e && e.which === 3) return; if (s.params.noswiping && findelementinevent(e, '.' + s.params.noswipingclass)) { s.allowclick = true; return; } if (s.params.swipehandler) { if (!findelementinevent(e, s.params.swipehandler)) return; } istouched = true; ismoved = false; isscrolling = undefined; startmoving = undefined; s.touches.startx = s.touches.currentx = e.type === 'touchstart' ? e.targettouches[0].pagex : e.pagex; s.touches.starty = s.touches.currenty = e.type === 'touchstart' ? e.targettouches[0].pagey : e.pagey; touchstarttime = date.now(); s.allowclick = true; s.updatecontainersize(); s.swipedirection = undefined; if (s.params.threshold > 0) allowthresholdmove = false; if (e.type !== 'touchstart') { var preventdefault = true; if ($(e.target).is(formelements)) preventdefault = false; if (document.activeelement && $(document.activeelement).is(formelements)) { document.activeelement.blur(); } if (preventdefault) { e.preventdefault(); } } s.emit('ontouchstart', s, e); }; s.ontouchmove = function (e) { if (e.originalevent) e = e.originalevent; if (istouchevent && e.type === 'mousemove') return; if (e.preventedbynestedswiper) return; if (s.params.onlyexternal) { // ismoved = true; s.allowclick = false; 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 && document.activeelement) { if (e.target === document.activeelement && $(e.target).is(formelements)) { ismoved = true; s.allowclick = false; return; } } s.emit('ontouchmove', s, e); if (e.targettouches && e.targettouches.length > 1) return; s.touches.currentx = e.type === 'touchmove' ? e.targettouches[0].pagex : e.pagex; s.touches.currenty = e.type === 'touchmove' ? e.targettouches[0].pagey : e.pagey; if (typeof isscrolling === 'undefined') { var touchangle = math.atan2(math.abs(s.touches.currenty - s.touches.starty), math.abs(s.touches.currentx - s.touches.startx)) * 180 / math.pi; isscrolling = ish() ? touchangle > s.params.touchangle : (90 - touchangle > s.params.touchangle); } if (isscrolling) { s.emit('ontouchmoveopposite', s, e); } if (typeof startmoving === 'undefined' && s.browser.ietouch) { if (s.touches.currentx !== s.touches.startx || s.touches.currenty !== s.touches.starty) { startmoving = true; } } if (!istouched) return; if (isscrolling) { istouched = false; return; } if (!startmoving && s.browser.ietouch) { return; } s.allowclick = false; s.emit('onslidermove', s, e); e.preventdefault(); if (s.params.touchmovestoppropagation && !s.params.nested) { e.stoppropagation(); } if (!ismoved) { if (params.loop) { s.fixloop(); } starttranslate = s.getwrappertranslate(); s.setwrappertransition(0); if (s.animating) { s.wrapper.trigger('webkittransitionend transitionend otransitionend mstransitionend mstransitionend'); } if (s.params.autoplay && s.autoplaying) { if (s.params.autoplaydisableoninteraction) { s.stopautoplay(); } else { s.pauseautoplay(); } } allowmomentumbounce = false; //grab cursor if (s.params.grabcursor) { s.container[0].style.cursor = 'move'; s.container[0].style.cursor = '-webkit-grabbing'; s.container[0].style.cursor = '-moz-grabbin'; s.container[0].style.cursor = 'grabbing'; } } ismoved = true; var diff = s.touches.diff = ish() ? s.touches.currentx - s.touches.startx : s.touches.currenty - s.touches.starty; diff = diff * s.params.touchratio; if (s.rtl) diff = -diff; s.swipedirection = diff > 0 ? 'prev' : 'next'; currenttranslate = diff + starttranslate; var disableparentswiper = true; if ((diff > 0 && currenttranslate > s.mintranslate())) { disableparentswiper = false; if (s.params.resistance) currenttranslate = s.mintranslate() - 1 + math.pow(-s.mintranslate() + starttranslate + diff, s.params.resistanceratio); } else if (diff < 0 && currenttranslate < s.maxtranslate()) { disableparentswiper = false; if (s.params.resistance) currenttranslate = s.maxtranslate() + 1 - math.pow(s.maxtranslate() - starttranslate - diff, s.params.resistanceratio); } if (disableparentswiper) { e.preventedbynestedswiper = true; } // directions locks if (!s.params.allowswipetonext && s.swipedirection === 'next' && currenttranslate < starttranslate) { currenttranslate = starttranslate; } if (!s.params.allowswipetoprev && s.swipedirection === 'prev' && currenttranslate > starttranslate) { currenttranslate = starttranslate; } if (!s.params.followfinger) return; // threshold if (s.params.threshold > 0) { if (math.abs(diff) > s.params.threshold || allowthresholdmove) { if (!allowthresholdmove) { allowthresholdmove = true; s.touches.startx = s.touches.currentx; s.touches.starty = s.touches.currenty; currenttranslate = starttranslate; s.touches.diff = ish() ? s.touches.currentx - s.touches.startx : s.touches.currenty - s.touches.starty; return; } } else { currenttranslate = starttranslate; return; } } // update active index in free mode if (s.params.freemode || s.params.watchslidesprogress) { s.updateactiveindex(); } if (s.params.freemode) { //velocity if (velocities.length === 0) { velocities.push({ position: s.touches[ish() ? 'startx' : 'starty'], time: touchstarttime }); } velocities.push({ position: s.touches[ish() ? 'currentx' : 'currenty'], time: (new window.date()).gettime() }); } // update progress s.updateprogress(currenttranslate); // update translate s.setwrappertranslate(currenttranslate); }; s.ontouchend = function (e) { if (e.originalevent) e = e.originalevent; s.emit('ontouchend', s, e); if (!istouched) return; //return grab cursor if (s.params.grabcursor && ismoved && istouched) { s.container[0].style.cursor = 'move'; s.container[0].style.cursor = '-webkit-grab'; s.container[0].style.cursor = '-moz-grab'; s.container[0].style.cursor = 'grab'; } // time diff var touchendtime = date.now(); var timediff = touchendtime - touchstarttime; // tap, doubletap, click if (s.allowclick) { s.updateclickedslide(e); s.emit('ontap', s, e); if (timediff < 300 && (touchendtime - lastclicktime) > 300) { if (clicktimeout) cleartimeout(clicktimeout); clicktimeout = settimeout(function () { if (!s) return; if (s.params.paginationhide && s.paginationcontainer.length > 0 && !$(e.target).hasclass(s.params.bulletclass)) { s.paginationcontainer.toggleclass(s.params.paginationhiddenclass); } s.emit('onclick', s, e); }, 300); } if (timediff < 300 && (touchendtime - lastclicktime) < 300) { if (clicktimeout) cleartimeout(clicktimeout); s.emit('ondoubletap', s, e); } } lastclicktime = date.now(); settimeout(function () { if (s) s.allowclick = 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) < 0.02) { s.velocity = 0; } // this implies that the user stopped moving a finger then released. // there would be no events with distance zero, so the last event is stale. if (time > 150 || (new window.date().gettime() - lastmoveevent.time) > 300) { s.velocity = 0; } } else { s.velocity = 0; } velocities.length = 0; var momentumduration = 1000 * s.params.freemodemomentumratio; var momentumdistance = s.velocity * momentumduration; var newposition = s.translate + momentumdistance; if (s.rtl) newposition = - newposition; var dobounce = false; var afterbounceposition; var bounceamount = math.abs(s.velocity) * 20 * s.params.freemodemomentumbounceratio; if (newposition < s.maxtranslate()) { if (s.params.freemodemomentumbounce) { if (newposition + s.maxtranslate() < -bounceamount) { newposition = s.maxtranslate() - bounceamount; } afterbounceposition = s.maxtranslate(); dobounce = true; allowmomentumbounce = true; } else { newposition = s.maxtranslate(); } } 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]; // directions locks if (!s.params.allowswipetonext && translate < s.translate && translate < s.mintranslate()) { return false; } if (!s.params.allowswipetoprev && translate > s.translate && translate > s.maxtranslate()) { return false; } // stop autoplay if (s.params.autoplay && s.autoplaying) { if (internal || !s.params.autoplaydisableoninteraction) { s.pauseautoplay(speed); } else { s.stopautoplay(); } } // update progress s.updateprogress(translate); // normalize slideindex for (var i = 0; i < s.slidesgrid.length; i++) { if (- math.floor(translate * 100) >= math.floor(s.slidesgrid[i] * 100)) { slideindex = i; } } if (typeof speed === 'undefined') speed = s.params.speed; s.previousindex = s.activeindex || 0; s.activeindex = slideindex; if (translate === s.translate) { s.updateclasses(); return false; } s.updateclasses(); s.ontransitionstart(runcallbacks); var translatex = ish() ? translate : 0, translatey = ish() ? 0 : translate; if (speed === 0) { s.setwrappertransition(0); s.setwrappertranslate(translate); s.ontransitionend(runcallbacks); } else { s.setwrappertransition(speed); s.setwrappertranslate(translate); if (!s.animating) { s.animating = true; s.wrapper.transitionend(function () { if (!s) return; s.ontransitionend(runcallbacks); }); } } return true; }; s.ontransitionstart = function (runcallbacks) { if (typeof runcallbacks === 'undefined') runcallbacks = true; if (s.lazy) s.lazy.ontransitionstart(); if (runcallbacks) { s.emit('ontransitionstart', s); if (s.activeindex !== s.previousindex) { s.emit('onslidechangestart', s); } } }; s.ontransitionend = function (runcallbacks) { s.animating = false; s.setwrappertransition(0); if (typeof runcallbacks === 'undefined') runcallbacks = true; if (s.lazy) s.lazy.ontransitionend(); if (runcallbacks) { s.emit('ontransitionend', s); if (s.activeindex !== s.previousindex) { s.emit('onslidechangeend', s); } } if (s.params.hashnav && s.hashnav) { s.hashnav.sethash(); } }; s.slidenext = function (runcallbacks, speed, internal) { if (s.params.loop) { if (s.animating) return false; s.fixloop(); 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); }; /*========================= translate/transition helpers ===========================*/ s.setwrappertransition = function (duration, bycontroller) { s.wrapper.transition(duration); if (s.params.effect !== 'slide' && s.effects[s.params.effect]) { s.effects[s.params.effect].settransition(duration); } if (s.params.parallax && s.parallax) { s.parallax.settransition(duration); } if (s.params.scrollbar && s.scrollbar) { s.scrollbar.settransition(duration); } if (s.params.control && s.controller) { s.controller.settransition(duration, bycontroller); } s.emit('onsettransition', s, duration); }; s.setwrappertranslate = function (translate, updateactiveindex, bycontroller) { var x = 0, y = 0, z = 0; if (ish()) { x = s.rtl ? -translate : translate; } else { y = translate; } if (!s.params.virtualtranslate) { if (s.support.transforms3d) s.wrapper.transform('translate3d(' + x + 'px, ' + y + 'px, ' + z + 'px)'); else s.wrapper.transform('translate(' + x + 'px, ' + y + 'px)'); } s.translate = ish() ? x : y; if (updateactiveindex) s.updateactiveindex(); if (s.params.effect !== 'slide' && s.effects[s.params.effect]) { s.effects[s.params.effect].settranslate(s.translate); } if (s.params.parallax && s.parallax) { s.parallax.settranslate(s.translate); } if (s.params.scrollbar && s.scrollbar) { s.scrollbar.settranslate(s.translate); } if (s.params.control && s.controller) { s.controller.settranslate(s.translate, bycontroller); } s.emit('onsettranslate', s, s.translate); }; s.gettranslate = function (el, axis) { var matrix, curtransform, curstyle, transformmatrix; // automatic axis detection if (typeof axis === 'undefined') { axis = 'x'; } if (s.params.virtualtranslate) { return s.rtl ? -s.translate : s.translate; } curstyle = window.getcomputedstyle(el, null); if (window.webkitcssmatrix) { // some old versions of webkit choke when 'none' is passed; pass // empty string instead in this case transformmatrix = new window.webkitcssmatrix(curstyle.webkittransform === 'none' ? '' : curstyle.webkittransform); } else { transformmatrix = curstyle.moztransform || curstyle.otransform || curstyle.mstransform || curstyle.mstransform || curstyle.transform || curstyle.getpropertyvalue('transform').replace('translate(', 'matrix(1, 0, 0, 1,'); matrix = transformmatrix.tostring().split(','); } if (axis === 'x') { //latest chrome and webkits fix if (window.webkitcssmatrix) curtransform = transformmatrix.m41; //crazy ie10 matrix else if (matrix.length === 16) curtransform = parsefloat(matrix[12]); //normal browsers else curtransform = parsefloat(matrix[4]); } if (axis === 'y') { //latest chrome and webkits fix if (window.webkitcssmatrix) curtransform = transformmatrix.m42; //crazy ie10 matrix else if (matrix.length === 16) curtransform = parsefloat(matrix[13]); //normal browsers else curtransform = parsefloat(matrix[5]); } if (s.rtl && curtransform) curtransform = -curtransform; return curtransform || 0; }; s.getwrappertranslate = function (axis) { if (typeof axis === 'undefined') { axis = ish() ? 'x' : 'y'; } return s.gettranslate(s.wrapper[0], axis); }; /*========================= observer ===========================*/ s.observers = []; function initobserver(target, options) { options = options || {}; // create an observer instance var observerfunc = window.mutationobserver || window.webkitmutationobserver; var observer = new observerfunc(function (mutations) { mutations.foreach(function (mutation) { s.onresize(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); s.loopedslides = parseint(s.params.loopedslides || s.params.slidesperview, 10); s.loopedslides = s.loopedslides + s.params.loopadditionalslides; if (s.loopedslides > slides.length) { s.loopedslides = slides.length; } var prependslides = [], appendslides = [], i; slides.each(function (index, el) { var slide = $(this); if (index < s.loopedslides) appendslides.push(el); if (index < slides.length && index >= slides.length - s.loopedslides) prependslides.push(el); slide.attr('data-swiper-slide-index', index); }); for (i = 0; i < appendslides.length; i++) { s.wrapper.append($(appendslides[i].clonenode(true)).addclass(s.params.slideduplicateclass)); } for (i = prependslides.length - 1; i >= 0; i--) { s.wrapper.prepend($(prependslides[i].clonenode(true)).addclass(s.params.slideduplicateclass)); } }; s.destroyloop = function () { s.wrapper.children('.' + s.params.slideclass + '.' + s.params.slideduplicateclass).remove(); s.slides.removeattr('data-swiper-slide-index'); }; s.fixloop = function () { var newindex; //fix for negative oversliding if (s.activeindex < s.loopedslides) { newindex = s.slides.length - s.loopedslides * 3 + s.activeindex; newindex = newindex + s.loopedslides; s.slideto(newindex, 0, false, true); } //fix for positive oversliding else if ((s.params.slidesperview === 'auto' && s.activeindex >= s.loopedslides * 2) || (s.activeindex > s.slides.length - s.params.slidesperview * 2)) { newindex = -s.slides.length + s.activeindex + s.loopedslides; newindex = newindex + s.loopedslides; s.slideto(newindex, 0, false, true); } }; /*========================= append/prepend/remove slides ===========================*/ s.appendslide = function (slides) { if (s.params.loop) { s.destroyloop(); } if (typeof slides === 'object' && slides.length) { for (var i = 0; i < slides.length; i++) { if (slides[i]) s.wrapper.append(slides[i]); } } else { s.wrapper.append(slides); } if (s.params.loop) { s.createloop(); } if (!(s.params.observer && s.support.observer)) { s.update(true); } }; s.prependslide = function (slides) { if (s.params.loop) { s.destroyloop(); } var newactiveindex = s.activeindex + 1; if (typeof slides === 'object' && slides.length) { for (var i = 0; i < slides.length; i++) { if (slides[i]) s.wrapper.prepend(slides[i]); } newactiveindex = s.activeindex + slides.length; } else { s.wrapper.prepend(slides); } if (s.params.loop) { s.createloop(); } if (!(s.params.observer && s.support.observer)) { s.update(true); } s.slideto(newactiveindex, 0, false); }; s.removeslide = function (slidesindexes) { if (s.params.loop) { s.destroyloop(); 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 (!ish()) { ty = tx; tx = 0; } var slideopacity = s.params.fade.crossfade ? math.max(1 - math.abs(slide[0].progress), 0) : 1 + math.min(math.max(slide[0].progress, -1), 0); 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]); } }); } } }, cube: { settranslate: function () { var wrapperrotate = 0, cubeshadow; if (s.params.cube.shadow) { if (ish()) { cubeshadow = s.wrapper.find('.swiper-cube-shadow'); if (cubeshadow.length === 0) { cubeshadow = $('
'); 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 (!ish()) { ty = tx; tx = 0; } var transform = 'rotatex(' + (ish() ? 0 : -slideangle) + 'deg) rotatey(' + (ish() ? slideangle : 0) + 'deg) translate3d(' + tx + 'px, ' + ty + 'px, ' + tz + 'px)'; if (progress <= 1 && progress > -1) { wrapperrotate = i * 90 + progress * 90; if (s.rtl) wrapperrotate = -i * 90 - progress * 90; } slide.transform(transform); if (s.params.cube.slideshadows) { //set shadows var shadowbefore = ish() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); var shadowafter = ish() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); if (shadowbefore.length === 0) { shadowbefore = $(''); slide.append(shadowbefore); } if (shadowafter.length === 0) { shadowafter = $(''); slide.append(shadowafter); } var shadowopacity = slide[0].progress; if (shadowbefore.length) shadowbefore[0].style.opacity = -slide[0].progress; if (shadowafter.length) shadowafter[0].style.opacity = slide[0].progress; } } s.wrapper.css({ '-webkit-transform-origin': '50% 50% -' + (s.size / 2) + 'px', '-moz-transform-origin': '50% 50% -' + (s.size / 2) + 'px', '-ms-transform-origin': '50% 50% -' + (s.size / 2) + 'px', 'transform-origin': '50% 50% -' + (s.size / 2) + 'px' }); if (s.params.cube.shadow) { if (ish()) { cubeshadow.transform('translate3d(0px, ' + (s.width / 2 + s.params.cube.shadowoffset) + 'px, ' + (-s.width / 2) + 'px) rotatex(90deg) rotatez(0deg) scale(' + (s.params.cube.shadowscale) + ')'); } else { var shadowangle = math.abs(wrapperrotate) - math.floor(math.abs(wrapperrotate) / 90) * 90; var multiplier = 1.5 - (math.sin(shadowangle * 2 * math.pi / 360) / 2 + math.cos(shadowangle * 2 * math.pi / 360) / 2); var scale1 = s.params.cube.shadowscale, scale2 = s.params.cube.shadowscale / multiplier, offset = s.params.cube.shadowoffset; cubeshadow.transform('scale3d(' + scale1 + ', 1, ' + scale2 + ') translate3d(0px, ' + (s.height / 2 + offset) + 'px, ' + (-s.height / 2 / scale2) + 'px) rotatex(-90deg)'); } } var zfactor = (s.issafari || s.isuiwebview) ? (-s.size / 2) : 0; s.wrapper.transform('translate3d(0px,0,' + zfactor + 'px) rotatex(' + (ish() ? 0 : wrapperrotate) + 'deg) rotatey(' + (ish() ? -wrapperrotate : 0) + 'deg)'); }, settransition: function (duration) { s.slides.transition(duration).find('.swiper-slide-shadow-top, .swiper-slide-shadow-right, .swiper-slide-shadow-bottom, .swiper-slide-shadow-left').transition(duration); if (s.params.cube.shadow && !ish()) { s.container.find('.swiper-cube-shadow').transition(duration); } } }, coverflow: { settranslate: function () { var transform = s.translate; var center = ish() ? -transform + s.width / 2 : -transform + s.height / 2; var rotate = ish() ? s.params.coverflow.rotate: -s.params.coverflow.rotate; var translate = s.params.coverflow.depth; //each slide offset from center for (var i = 0, length = s.slides.length; i < length; i++) { var slide = s.slides.eq(i); var slidesize = s.slidessizesgrid[i]; var slideoffset = slide[0].swiperslideoffset; var offsetmultiplier = (center - slideoffset - slidesize / 2) / slidesize * s.params.coverflow.modifier; var rotatey = ish() ? rotate * offsetmultiplier : 0; var rotatex = ish() ? 0 : rotate * offsetmultiplier; // var rotatez = 0 var translatez = -translate * math.abs(offsetmultiplier); var translatey = ish() ? 0 : s.params.coverflow.stretch * (offsetmultiplier); var translatex = ish() ? s.params.coverflow.stretch * (offsetmultiplier) : 0; //fix for ultra small values if (math.abs(translatex) < 0.001) translatex = 0; if (math.abs(translatey) < 0.001) translatey = 0; if (math.abs(translatez) < 0.001) translatez = 0; if (math.abs(rotatey) < 0.001) rotatey = 0; if (math.abs(rotatex) < 0.001) rotatex = 0; var slidetransform = 'translate3d(' + translatex + 'px,' + translatey + 'px,' + translatez + 'px) rotatex(' + rotatex + 'deg) rotatey(' + rotatey + 'deg)'; slide.transform(slidetransform); slide[0].style.zindex = -math.abs(math.round(offsetmultiplier)) + 1; if (s.params.coverflow.slideshadows) { //set shadows var shadowbefore = ish() ? slide.find('.swiper-slide-shadow-left') : slide.find('.swiper-slide-shadow-top'); var shadowafter = ish() ? slide.find('.swiper-slide-shadow-right') : slide.find('.swiper-slide-shadow-bottom'); if (shadowbefore.length === 0) { shadowbefore = $(''); 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('.swiper-lazy:not(.swiper-lazy-loaded):not(.swiper-lazy-loading)'); if (slide.hasclass('swiper-lazy') && !slide.hasclass('swiper-lazy-loaded') && !slide.hasclass('swiper-lazy-loading')) { img.add(slide[0]); } if (img.length === 0) return; img.each(function () { var _img = $(this); _img.addclass('swiper-lazy-loading'); var background = _img.attr('data-background'); var src = _img.attr('data-src'); s.loadimage(_img[0], (src || background), false, function () { if (background) { _img.css('background-image', 'url(' + background + ')'); _img.removeattr('data-background'); } else { _img.attr('src', src); _img.removeattr('data-src'); } _img.addclass('swiper-lazy-loaded').removeclass('swiper-lazy-loading'); slide.find('.swiper-lazy-preloader, .preloader').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; if (s.params.watchslidesvisibility) { s.wrapper.children('.' + s.params.slidevisibleclass).each(function () { s.lazy.loadimageinslide($(this).index()); }); } else { if (s.params.slidesperview > 1) { for (i = s.activeindex; i < s.activeindex + s.params.slidesperview ; i++) { if (s.slides[i]) s.lazy.loadimageinslide(i); } } else { s.lazy.loadimageinslide(s.activeindex); } } if (s.params.lazyloadinginprevnext) { if (s.params.slidesperview > 1) { // next slides for (i = s.activeindex + s.params.slidesperview; i < s.activeindex + s.params.slidesperview + s.params.slidesperview; i++) { if (s.slides[i]) s.lazy.loadimageinslide(i); } // prev slides for (i = s.activeindex - s.params.slidesperview; 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 = { set: function () { if (!s.params.scrollbar) return; var sb = s.scrollbar; sb.track = $(s.params.scrollbar); sb.drag = sb.track.find('.swiper-scrollbar-drag'); if (sb.drag.length === 0) { sb.drag = $(''); sb.track.append(sb.drag); } sb.drag[0].style.width = ''; sb.drag[0].style.height = ''; sb.tracksize = ish() ? sb.track[0].offsetwidth : sb.track[0].offsetheight; sb.divider = s.size / s.virtualsize; sb.movedivider = sb.divider * (sb.tracksize / s.size); sb.dragsize = sb.tracksize * sb.divider; if (ish()) { sb.drag[0].style.width = sb.dragsize + 'px'; } else { sb.drag[0].style.height = sb.dragsize + 'px'; } if (sb.divider >= 1) { sb.track[0].style.display = 'none'; } else { sb.track[0].style.display = ''; } if (s.params.scrollbarhide) { sb.track[0].style.opacity = 0; } }, settranslate: function () { if (!s.params.scrollbar) return; var 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 && ish()) { newpos = -newpos; if (newpos > 0) { newsize = sb.dragsize - newpos; newpos = 0; } else if (-newpos + sb.dragsize > sb.tracksize) { newsize = sb.tracksize + newpos; } } else { if (newpos < 0) { newsize = sb.dragsize + newpos; newpos = 0; } else if (newpos + sb.dragsize > sb.tracksize) { newsize = sb.tracksize - newpos; } } if (ish()) { if (s.support.transforms3d) { sb.drag.transform('translate3d(' + (newpos) + 'px, 0, 0)'); } else { sb.drag.transform('translatex(' + (newpos) + 'px)'); } sb.drag[0].style.width = newsize + 'px'; } else { if (s.support.transforms3d) { sb.drag.transform('translate3d(0px, ' + (newpos) + 'px, 0)'); } else { sb.drag.transform('translatey(' + (newpos) + 'px)'); } sb.drag[0].style.height = newsize + 'px'; } if (s.params.scrollbarhide) { cleartimeout(sb.timeout); sb.track[0].style.opacity = 1; sb.timeout = settimeout(function () { sb.track[0].style.opacity = 0; sb.track.transition(400); }, 1000); } }, settransition: function (duration) { if (!s.params.scrollbar) return; s.scrollbar.drag.transition(duration); } }; /*========================= controller ===========================*/ s.controller = { linearspline: function (x, y) { 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]; }; 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; }; })(); }, //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 (s.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 (s.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 = { init: function () { if (!s.params.hashnav) return; s.hashnav.initialized = true; var hash = document.location.hash.replace('#', ''); if (!hash) return; 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'); if (slidehash === hash && !slide.hasclass(s.params.slideduplicateclass)) { var index = slide.index(); s.slideto(index, speed, s.params.runcallbacksoninit, true); } } }, sethash: function () { if (!s.hashnav.initialized || !s.params.hashnav) return; document.location.hash = s.slides.eq(s.activeindex).attr('data-hash') || ''; } }; /*========================= 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 && (ish() && kc === 39 || !ish() && kc === 40)) { return false; } if (!s.params.allowswipetoprev && (ish() && kc === 37 || !ish() && 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('.swiper-slide').length > 0 && s.container.parents('.swiper-slide-active').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 (ish()) { 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.disablekeyboardcontrol = function () { $(document).off('keydown', handlekeyboard); }; s.enablekeyboardcontrol = function () { $(document).on('keydown', handlekeyboard); }; /*========================= mousewheel control ===========================*/ s.mousewheel = { event: false, lastscrolltime: (new window.date()).gettime() }; if (s.params.mousewheelcontrol) { if (document.onmousewheel !== undefined) { s.mousewheel.event = 'mousewheel'; } if (!s.mousewheel.event) { try { new window.wheelevent('wheel'); s.mousewheel.event = 'wheel'; } catch (e) {} } if (!s.mousewheel.event) { s.mousewheel.event = 'dommousescroll'; } } function handlemousewheel(e) { if (e.originalevent) e = e.originalevent; //jquery fix var we = s.mousewheel.event; var delta = 0; //opera & ie if (e.detail) delta = -e.detail; //webkits else if (we === 'mousewheel') { if (s.params.mousewheelforcetoaxis) { if (ish()) { if (math.abs(e.wheeldeltax) > math.abs(e.wheeldeltay)) delta = e.wheeldeltax; else return; } else { if (math.abs(e.wheeldeltay) > math.abs(e.wheeldeltax)) delta = e.wheeldeltay; else return; } } else { delta = e.wheeldelta; } } //old firefox else if (we === 'dommousescroll') delta = -e.detail; //new firefox else if (we === 'wheel') { if (s.params.mousewheelforcetoaxis) { if (ish()) { if (math.abs(e.deltax) > math.abs(e.deltay)) delta = -e.deltax; else return; } else { if (math.abs(e.deltay) > math.abs(e.deltax)) delta = -e.deltay; else return; } } else { delta = math.abs(e.deltax) > math.abs(e.deltay) ? - e.deltax : - e.deltay; } } 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.slidenext(); else if (s.params.mousewheelreleaseonedges) return true; } else { if (!s.isbeginning) s.slideprev(); else if (s.params.mousewheelreleaseonedges) return true; } } s.mousewheel.lastscrolltime = (new window.date()).gettime(); } else { //freemode or scrollcontainer: var position = s.getwrappertranslate() + delta; if (position > 0) position = 0; if (position < s.maxtranslate()) position = s.maxtranslate(); s.setwrappertransition(0); s.setwrappertranslate(position); s.updateprogress(); s.updateactiveindex(); if (s.params.freemodesticky) { cleartimeout(s.mousewheel.timeout); s.mousewheel.timeout = settimeout(function () { s.slidereset(); }, 300); } // return page scroll on edge positions if (position === 0 || position === s.maxtranslate()) return; } if (s.params.autoplay) s.stopautoplay(); if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; return false; } s.disablemousewheelcontrol = function () { if (!s.mousewheel.event) return false; s.container.off(s.mousewheel.event, handlemousewheel); return true; }; s.enablemousewheelcontrol = function () { if (!s.mousewheel.event) return false; s.container.on(s.mousewheel.event, handlemousewheel); return true; }; /*========================= parallax ===========================*/ function setparallaxtransform(el, progress) { el = $(el); var p, px, py; p = el.attr('data-swiper-parallax') || '0'; px = el.attr('data-swiper-parallax-x'); py = el.attr('data-swiper-parallax-y'); if (px || py) { px = px || '0'; py = py || '0'; } else { if (ish()) { px = p; py = '0'; } else { py = p; px = '0'; } } if ((px).indexof('%') >= 0) { px = parseint(px, 10) * progress + '%'; } else { px = px * progress + 'px' ; } if ((py).indexof('%') >= 0) { py = parseint(py, 10) * progress + '%'; } else { py = py * progress + 'px' ; } el.transform('translate3d(' + px + ', ' + py + ',0px)'); } s.parallax = { settranslate: function () { s.container.children('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){ setparallaxtransform(this, s.progress); }); s.slides.each(function () { var slide = $(this); slide.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function () { var progress = math.min(math.max(slide[0].progress, -1), 1); setparallaxtransform(this, progress); }); }); }, settransition: function (duration) { if (typeof duration === 'undefined') duration = s.params.speed; s.container.find('[data-swiper-parallax], [data-swiper-parallax-x], [data-swiper-parallax-y]').each(function(){ var el = $(this); var parallaxduration = parseint(el.attr('data-swiper-parallax-duration'), 10) || duration; if (duration === 0) parallaxduration = 0; el.transition(parallaxduration); }); } }; /*========================= plugins api. collect all and init all plugins ===========================*/ s._plugins = []; for (var plugin in s.plugins) { 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) { var nextbutton = $(s.params.nextbutton); s.a11y.makefocusable(nextbutton); s.a11y.addrole(nextbutton, 'button'); s.a11y.addlabel(nextbutton, s.params.nextslidemessage); } if (s.params.prevbutton) { var prevbutton = $(s.params.prevbutton); s.a11y.makefocusable(prevbutton); s.a11y.addrole(prevbutton, 'button'); s.a11y.addlabel(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.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.autoplay) { s.startautoplay(); } if (s.params.keyboardcontrol) { if (s.enablekeyboardcontrol) s.enablekeyboardcontrol(); } if (s.params.mousewheelcontrol) { if (s.enablemousewheelcontrol) s.enablemousewheelcontrol(); } if (s.params.hashnav) { if (s.hashnav) s.hashnav.init(); } if (s.params.a11y && s.a11y) s.a11y.init(); s.emit('oninit', s); }; // cleanup dynamic styles s.cleanupstyles = function () { // container s.container.removeclass(s.classnames.join(' ')).removeattr('style'); // wrapper s.wrapper.removeattr('style'); // slides if (s.slides && s.slides.length) { s.slides .removeclass([ s.params.slidevisibleclass, s.params.slideactiveclass, s.params.slidenextclass, s.params.slideprevclass ].join(' ')) .removeattr('style') .removeattr('data-swiper-column') .removeattr('data-swiper-row'); } // pagination/bullets if (s.paginationcontainer && s.paginationcontainer.length) { s.paginationcontainer.removeclass(s.params.paginationhiddenclass); } if (s.bullets && s.bullets.length) { s.bullets.removeclass(s.params.bulletactiveclass); } // buttons if (s.params.prevbutton) $(s.params.prevbutton).removeclass(s.params.buttondisabledclass); if (s.params.nextbutton) $(s.params.nextbutton).removeclass(s.params.buttondisabledclass); // scrollbar if (s.params.scrollbar && s.scrollbar) { if (s.scrollbar.track && s.scrollbar.track.length) s.scrollbar.track.removeattr('style'); if (s.scrollbar.drag && s.scrollbar.drag.length) s.scrollbar.drag.removeattr('style'); } }; // destroy s.destroy = function (deleteinstance, cleanupstyles) { // detach evebts s.detachevents(); // stop autoplay s.stopautoplay(); // destroy loop if (s.params.loop) { s.destroyloop(); } // cleanup styles if (cleanupstyles) { s.cleanupstyles(); } // disconnect observer s.disconnectobservers(); // disable keyboard/mousewheel if (s.params.keyboardcontrol) { if (s.disablekeyboardcontrol) s.disablekeyboardcontrol(); } if (s.params.mousewheelcontrol) { if (s.disablemousewheelcontrol) s.disablemousewheelcontrol(); } // disable a11y if (s.params.a11y && s.a11y) s.a11y.destroy(); // destroy callback s.emit('ondestroy'); // delete instance if (deleteinstance !== false) s = null; }; s.init(); // return swiper instance return s; }; /*================================================== prototype ====================================================*/ swiper.prototype = { issafari: (function () { var ua = navigator.useragent.tolowercase(); return (ua.indexof('safari') >= 0 && ua.indexof('chrome') < 0 && ua.indexof('android') < 0); })(), isuiwebview: /(iphone|ipod|ipad).*applewebkit(?!.*safari)/i.test(navigator.useragent), isarray: function (arr) { return object.prototype.tostring.apply(arr) === '[object array]'; }, /*================================================== browser ====================================================*/ browser: { ie: window.navigator.pointerenabled || window.navigator.mspointerenabled, ietouch: (window.navigator.mspointerenabled && window.navigator.msmaxtouchpoints > 1) || (window.navigator.pointerenabled && window.navigator.maxtouchpoints > 1), }, /*================================================== devices ====================================================*/ device: (function () { var ua = navigator.useragent; var android = ua.match(/(android);?[\s\/]+([\d.]+)?/); var ipad = ua.match(/(ipad).*os\s([\d_]+)/); var ipod = ua.match(/(ipod)(.*os\s([\d_]+))?/); var iphone = !ipad && ua.match(/(iphone\sos)\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); })() }, /*================================================== plugins ====================================================*/ plugins: {} }; /*=========================== 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; }; } } 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; }); }