var swiper = function (selector, params) { 'use strict'; /*========================= a little bit dirty but required part for ie8 and old ff support ===========================*/ if (!document.body.outerhtml && document.body.__definegetter__) { if (htmlelement) { var element = htmlelement.prototype; if (element.__definegetter__) { element.__definegetter__('outerhtml', function () { return new xmlserializer().serializetostring(this); }); } } } if (!window.getcomputedstyle) { window.getcomputedstyle = function (el, pseudo) { this.el = el; this.getpropertyvalue = function (prop) { var re = /(\-([a-z]){1})/g; if (prop === 'float') prop = 'stylefloat'; if (re.test(prop)) { prop = prop.replace(re, function () { return arguments[2].touppercase(); }); } return el.currentstyle[prop] ? el.currentstyle[prop] : null; }; return this; }; } if (!array.prototype.indexof) { array.prototype.indexof = function (obj, start) { for (var i = (start || 0), j = this.length; i < j; i++) { if (this[i] === obj) { return i; } } return -1; }; } if (!document.queryselectorall) { if (!window.jquery) return; } function $$(selector, context) { if (document.queryselectorall) return (context || document).queryselectorall(selector); else return jquery(selector, context); } /*========================= check for correct selector ===========================*/ if (typeof selector === 'undefined') return; if (!(selector.nodetype)) { if ($$(selector).length === 0) return; } /*========================= _this ===========================*/ var _this = this; /*========================= default flags and vars ===========================*/ _this.touches = { start: 0, startx: 0, starty: 0, current: 0, currentx: 0, currenty: 0, diff: 0, abs: 0 }; _this.positions = { start: 0, abs: 0, diff: 0, current: 0 }; _this.times = { start: 0, end: 0 }; _this.id = (new date()).gettime(); _this.container = (selector.nodetype) ? selector : $$(selector)[0]; _this.istouched = false; _this.ismoved = false; _this.activeindex = 0; _this.centerindex = 0; _this.activeloaderindex = 0; _this.activeloopindex = 0; _this.previousindex = null; _this.velocity = 0; _this.snapgrid = []; _this.slidesgrid = []; _this.imagestoload = []; _this.imagesloaded = 0; _this.wrapperleft = 0; _this.wrapperright = 0; _this.wrappertop = 0; _this.wrapperbottom = 0; _this.isandroid = navigator.useragent.tolowercase().indexof('android') >= 0; var wrapper, slidesize, wrappersize, direction, isscrolling, containersize; /*========================= default parameters ===========================*/ var defaults = { eventtarget: 'wrapper', // or 'container' mode : 'horizontal', // or 'vertical' touchratio : 1, speed : 300, freemode : false, freemodefluid : false, momentumratio: 1, momentumbounce: true, momentumbounceratio: 1, slidesperview : 1, slidespergroup : 1, slidesperviewfit: true, //fit to slide when spv "auto" and slides larger than container simulatetouch : true, followfinger : true, shortswipes : true, longswipesratio: 0.5, movestartthreshold: false, onlyexternal : false, createpagination : true, pagination : false, paginationelement: 'span', paginationclickable: false, paginationasrange: true, resistance : true, // or false or 100% scrollcontainer : false, preventlinks : true, preventlinkspropagation: false, noswiping : false, // or class noswipingclass : 'swiper-no-swiping', //:) initialslide: 0, keyboardcontrol: false, mousewheelcontrol : false, mousewheelcontrolforcetoaxis : false, usecss3transforms : true, // autoplay autoplay: false, autoplaydisableoninteraction: true, autoplaystoponlast: false, //loop mode loop: false, loopadditionalslides: 0, // round length values roundlengths: false, //auto height calculateheight: false, //apply css for width and/or height csswidthandheight: false, // or true or 'width' or 'height' //images preloader updateonimagesready : true, //form elements releaseformelements : true, //watch for active slide, useful when use effects on different slide states watchactiveindex: false, //slides visibility fit visibilityfullfit : false, //slides offset offsetpxbefore : 0, offsetpxafter : 0, offsetslidesbefore : 0, offsetslidesafter : 0, centeredslides: false, //queue callbacks queuestartcallbacks : false, queueendcallbacks : false, //auto resize autoresize : true, resizereinit : false, //domanimation domanimation : true, //slides loader loader: { slides: [], //array with slides slideshtmltype: 'inner', // or 'outer' surroundgroups: 1, //keep preloaded slides groups around view logic: 'reload', //or 'change' loadallslides: false }, // one way swipes swipetoprev: true, swipetonext: true, //namespace slideelement: 'div', slideclass: 'swiper-slide', slideactiveclass: 'swiper-slide-active', slidevisibleclass: 'swiper-slide-visible', slideduplicateclass: 'swiper-slide-duplicate', wrapperclass: 'swiper-wrapper', paginationelementclass: 'swiper-pagination-switch', paginationactiveclass: 'swiper-active-switch', paginationvisibleclass: 'swiper-visible-switch' }; params = params || {}; for (var prop in defaults) { if (prop in params && typeof params[prop] === 'object') { for (var subprop in defaults[prop]) { if (! (subprop in params[prop])) { params[prop][subprop] = defaults[prop][subprop]; } } } else if (! (prop in params)) { params[prop] = defaults[prop]; } } _this.params = params; if (params.scrollcontainer) { params.freemode = true; params.freemodefluid = true; } if (params.loop) { params.resistance = '100%'; } var ish = params.mode === 'horizontal'; /*========================= define touch events ===========================*/ var desktopevents = ['mousedown', 'mousemove', 'mouseup']; if (_this.browser.ie10) desktopevents = ['mspointerdown', 'mspointermove', 'mspointerup']; if (_this.browser.ie11) desktopevents = ['pointerdown', 'pointermove', 'pointerup']; _this.touchevents = { touchstart : _this.support.touch || !params.simulatetouch ? 'touchstart' : desktopevents[0], touchmove : _this.support.touch || !params.simulatetouch ? 'touchmove' : desktopevents[1], touchend : _this.support.touch || !params.simulatetouch ? 'touchend' : desktopevents[2] }; /*========================= wrapper ===========================*/ for (var i = _this.container.childnodes.length - 1; i >= 0; i--) { if (_this.container.childnodes[i].classname) { var _wrapperclasses = _this.container.childnodes[i].classname.split(/\s+/); for (var j = 0; j < _wrapperclasses.length; j++) { if (_wrapperclasses[j] === params.wrapperclass) { wrapper = _this.container.childnodes[i]; } } } } _this.wrapper = wrapper; /*========================= slide api ===========================*/ _this._extendswiperslide = function (el) { el.append = function () { if (params.loop) { el.insertafter(_this.slides.length - _this.loopedslides); } else { _this.wrapper.appendchild(el); _this.reinit(); } return el; }; el.prepend = function () { if (params.loop) { _this.wrapper.insertbefore(el, _this.slides[_this.loopedslides]); _this.removeloopedslides(); _this.calcslides(); _this.createloop(); } else { _this.wrapper.insertbefore(el, _this.wrapper.firstchild); } _this.reinit(); return el; }; el.insertafter = function (index) { if (typeof index === 'undefined') return false; var beforeslide; if (params.loop) { beforeslide = _this.slides[index + 1 + _this.loopedslides]; if (beforeslide) { _this.wrapper.insertbefore(el, beforeslide); } else { _this.wrapper.appendchild(el); } _this.removeloopedslides(); _this.calcslides(); _this.createloop(); } else { beforeslide = _this.slides[index + 1]; _this.wrapper.insertbefore(el, beforeslide); } _this.reinit(); return el; }; el.clone = function () { return _this._extendswiperslide(el.clonenode(true)); }; el.remove = function () { _this.wrapper.removechild(el); _this.reinit(); }; el.html = function (html) { if (typeof html === 'undefined') { return el.innerhtml; } else { el.innerhtml = html; return el; } }; el.index = function () { var index; for (var i = _this.slides.length - 1; i >= 0; i--) { if (el === _this.slides[i]) index = i; } return index; }; el.isactive = function () { if (el.index() === _this.activeindex) return true; else return false; }; if (!el.swiperslidedatastorage) el.swiperslidedatastorage = {}; el.getdata = function (name) { return el.swiperslidedatastorage[name]; }; el.setdata = function (name, value) { el.swiperslidedatastorage[name] = value; return el; }; el.data = function (name, value) { if (typeof value === 'undefined') { return el.getattribute('data-' + name); } else { el.setattribute('data-' + name, value); return el; } }; el.getwidth = function (outer, round) { return _this.h.getwidth(el, outer, round); }; el.getheight = function (outer, round) { return _this.h.getheight(el, outer, round); }; el.getoffset = function () { return _this.h.getoffset(el); }; return el; }; //calculate information about number of slides _this.calcslides = function (forcecalcslides) { var oldnumber = _this.slides ? _this.slides.length : false; _this.slides = []; _this.displayslides = []; for (var i = 0; i < _this.wrapper.childnodes.length; i++) { if (_this.wrapper.childnodes[i].classname) { var _classname = _this.wrapper.childnodes[i].classname; var _slideclasses = _classname.split(/\s+/); for (var j = 0; j < _slideclasses.length; j++) { if (_slideclasses[j] === params.slideclass) { _this.slides.push(_this.wrapper.childnodes[i]); } } } } for (i = _this.slides.length - 1; i >= 0; i--) { _this._extendswiperslide(_this.slides[i]); } if (oldnumber === false) return; if (oldnumber !== _this.slides.length || forcecalcslides) { // number of slides has been changed removeslideevents(); addslideevents(); _this.updateactiveslide(); if (_this.params.pagination) _this.createpagination(); _this.callplugins('numberofslideschanged'); } }; //create slide _this.createslide = function (html, slideclasslist, el) { slideclasslist = slideclasslist || _this.params.slideclass; el = el || params.slideelement; var newslide = document.createelement(el); newslide.innerhtml = html || ''; newslide.classname = slideclasslist; return _this._extendswiperslide(newslide); }; //append slide _this.appendslide = function (html, slideclasslist, el) { if (!html) return; if (html.nodetype) { return _this._extendswiperslide(html).append(); } else { return _this.createslide(html, slideclasslist, el).append(); } }; _this.prependslide = function (html, slideclasslist, el) { if (!html) return; if (html.nodetype) { return _this._extendswiperslide(html).prepend(); } else { return _this.createslide(html, slideclasslist, el).prepend(); } }; _this.insertslideafter = function (index, html, slideclasslist, el) { if (typeof index === 'undefined') return false; if (html.nodetype) { return _this._extendswiperslide(html).insertafter(index); } else { return _this.createslide(html, slideclasslist, el).insertafter(index); } }; _this.removeslide = function (index) { if (_this.slides[index]) { if (params.loop) { if (!_this.slides[index + _this.loopedslides]) return false; _this.slides[index + _this.loopedslides].remove(); _this.removeloopedslides(); _this.calcslides(); _this.createloop(); } else _this.slides[index].remove(); return true; } else return false; }; _this.removelastslide = function () { if (_this.slides.length > 0) { if (params.loop) { _this.slides[_this.slides.length - 1 - _this.loopedslides].remove(); _this.removeloopedslides(); _this.calcslides(); _this.createloop(); } else _this.slides[_this.slides.length - 1].remove(); return true; } else { return false; } }; _this.removeallslides = function () { var num = _this.slides.length; for (var i = _this.slides.length - 1; i >= 0; i--) { _this.slides[i].remove(); if (i === num - 1) { _this.setwrappertranslate(0); } } }; _this.getslide = function (index) { return _this.slides[index]; }; _this.getlastslide = function () { return _this.slides[_this.slides.length - 1]; }; _this.getfirstslide = function () { return _this.slides[0]; }; //currently active slide _this.activeslide = function () { return _this.slides[_this.activeindex]; }; /*========================= wrapper for callbacks : allows additive callbacks via function arrays ===========================*/ _this.firecallback = function () { var callback = arguments[0]; if (object.prototype.tostring.call(callback) === '[object array]') { for (var i = 0; i < callback.length; i++) { if (typeof callback[i] === 'function') { callback[i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); } } } else if (object.prototype.tostring.call(callback) === '[object string]') { if (params['on' + callback]) _this.firecallback(params['on' + callback], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); } else { callback(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]); } }; function isarray(obj) { if (object.prototype.tostring.apply(obj) === '[object array]') return true; return false; } /** * allows user to add callbacks, rather than replace them * @param callback * @param func * @return {*} */ _this.addcallback = function (callback, func) { var _this = this, tempfunc; if (_this.params['on' + callback]) { if (isarray(this.params['on' + callback])) { return this.params['on' + callback].push(func); } else if (typeof this.params['on' + callback] === 'function') { tempfunc = this.params['on' + callback]; this.params['on' + callback] = []; this.params['on' + callback].push(tempfunc); return this.params['on' + callback].push(func); } } else { this.params['on' + callback] = []; return this.params['on' + callback].push(func); } }; _this.removecallbacks = function (callback) { if (_this.params['on' + callback]) { _this.params['on' + callback] = null; } }; /*========================= plugins api ===========================*/ var _plugins = []; for (var plugin in _this.plugins) { if (params[plugin]) { var p = _this.plugins[plugin](_this, params[plugin]); if (p) _plugins.push(p); } } _this.callplugins = function (method, args) { if (!args) args = {}; for (var i = 0; i < _plugins.length; i++) { if (method in _plugins[i]) { _plugins[i][method](args); } } }; /*========================= windows phone 8 fix ===========================*/ if ((_this.browser.ie10 || _this.browser.ie11) && !params.onlyexternal) { _this.wrapper.classlist.add('swiper-wp8-' + (ish ? 'horizontal' : 'vertical')); } /*========================= free mode class ===========================*/ if (params.freemode) { _this.container.classname += ' swiper-free-mode'; } /*================================================== init/re-init/resize fix ====================================================*/ _this.initialized = false; _this.init = function (force, forcecalcslides) { var _width = _this.h.getwidth(_this.container, false, params.roundlengths); var _height = _this.h.getheight(_this.container, false, params.roundlengths); if (_width === _this.width && _height === _this.height && !force) return; _this.width = _width; _this.height = _height; var slidewidth, slideheight, slidemaxheight, wrapperwidth, wrapperheight, slideleft; var i; // loop index variable to avoid jshint w004 / w038 containersize = ish ? _width : _height; var wrapper = _this.wrapper; if (force) { _this.calcslides(forcecalcslides); } if (params.slidesperview === 'auto') { //auto mode var slideswidth = 0; var slidesheight = 0; //unset styles if (params.slidesoffset > 0) { wrapper.style.paddingleft = ''; wrapper.style.paddingright = ''; wrapper.style.paddingtop = ''; wrapper.style.paddingbottom = ''; } wrapper.style.width = ''; wrapper.style.height = ''; if (params.offsetpxbefore > 0) { if (ish) _this.wrapperleft = params.offsetpxbefore; else _this.wrappertop = params.offsetpxbefore; } if (params.offsetpxafter > 0) { if (ish) _this.wrapperright = params.offsetpxafter; else _this.wrapperbottom = params.offsetpxafter; } if (params.centeredslides) { if (ish) { _this.wrapperleft = (containersize - this.slides[0].getwidth(true, params.roundlengths)) / 2; _this.wrapperright = (containersize - _this.slides[_this.slides.length - 1].getwidth(true, params.roundlengths)) / 2; } else { _this.wrappertop = (containersize - _this.slides[0].getheight(true, params.roundlengths)) / 2; _this.wrapperbottom = (containersize - _this.slides[_this.slides.length - 1].getheight(true, params.roundlengths)) / 2; } } if (ish) { if (_this.wrapperleft >= 0) wrapper.style.paddingleft = _this.wrapperleft + 'px'; if (_this.wrapperright >= 0) wrapper.style.paddingright = _this.wrapperright + 'px'; } else { if (_this.wrappertop >= 0) wrapper.style.paddingtop = _this.wrappertop + 'px'; if (_this.wrapperbottom >= 0) wrapper.style.paddingbottom = _this.wrapperbottom + 'px'; } slideleft = 0; var centeredslideleft = 0; _this.snapgrid = []; _this.slidesgrid = []; slidemaxheight = 0; for (i = 0; i < _this.slides.length; i++) { slidewidth = _this.slides[i].getwidth(true, params.roundlengths); slideheight = _this.slides[i].getheight(true, params.roundlengths); if (params.calculateheight) { slidemaxheight = math.max(slidemaxheight, slideheight); } var _slidesize = ish ? slidewidth : slideheight; if (params.centeredslides) { var nextslidewidth = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getwidth(true, params.roundlengths); var nextslideheight = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getheight(true, params.roundlengths); var nextslidesize = ish ? nextslidewidth : nextslideheight; if (_slidesize > containersize) { if (params.slidesperviewfit) { _this.snapgrid.push(slideleft + _this.wrapperleft); _this.snapgrid.push(slideleft + _slidesize - containersize + _this.wrapperleft); } else { for (var j = 0; j <= math.floor(_slidesize / (containersize + _this.wrapperleft)); j++) { if (j === 0) _this.snapgrid.push(slideleft + _this.wrapperleft); else _this.snapgrid.push(slideleft + _this.wrapperleft + containersize * j); } } _this.slidesgrid.push(slideleft + _this.wrapperleft); } else { _this.snapgrid.push(centeredslideleft); _this.slidesgrid.push(centeredslideleft); } centeredslideleft += _slidesize / 2 + nextslidesize / 2; } else { if (_slidesize > containersize) { if (params.slidesperviewfit) { _this.snapgrid.push(slideleft); _this.snapgrid.push(slideleft + _slidesize - containersize); } else { if (containersize !== 0) { for (var k = 0; k <= math.floor(_slidesize / containersize); k++) { _this.snapgrid.push(slideleft + containersize * k); } } else { _this.snapgrid.push(slideleft); } } } else { _this.snapgrid.push(slideleft); } _this.slidesgrid.push(slideleft); } slideleft += _slidesize; slideswidth += slidewidth; slidesheight += slideheight; } if (params.calculateheight) _this.height = slidemaxheight; if (ish) { wrappersize = slideswidth + _this.wrapperright + _this.wrapperleft; if(!params.csswidthandheight || params.csswidthandheight === 'height') { wrapper.style.width = (slideswidth) + 'px'; } if(!params.csswidthandheight || params.csswidthandheight === 'width') { wrapper.style.height = (_this.height) + 'px'; } } else { if(!params.csswidthandheight || params.csswidthandheight === 'height') { wrapper.style.width = (_this.width) + 'px'; } if(!params.csswidthandheight || params.csswidthandheight === 'width') { wrapper.style.height = (slidesheight) + 'px'; } wrappersize = slidesheight + _this.wrappertop + _this.wrapperbottom; } } else if (params.scrollcontainer) { //scroll container wrapper.style.width = ''; wrapper.style.height = ''; wrapperwidth = _this.slides[0].getwidth(true, params.roundlengths); wrapperheight = _this.slides[0].getheight(true, params.roundlengths); wrappersize = ish ? wrapperwidth : wrapperheight; wrapper.style.width = wrapperwidth + 'px'; wrapper.style.height = wrapperheight + 'px'; slidesize = ish ? wrapperwidth : wrapperheight; } else { //for usual slides if (params.calculateheight) { slidemaxheight = 0; wrapperheight = 0; //resetwrappersize if (!ish) _this.container.style.height = ''; wrapper.style.height = ''; for (i = 0; i < _this.slides.length; i++) { //resetslidesize _this.slides[i].style.height = ''; slidemaxheight = math.max(_this.slides[i].getheight(true), slidemaxheight); if (!ish) wrapperheight += _this.slides[i].getheight(true); } slideheight = slidemaxheight; _this.height = slideheight; if (ish) wrapperheight = slideheight; else { containersize = slideheight; _this.container.style.height = containersize + 'px'; } } else { slideheight = ish ? _this.height : _this.height / params.slidesperview; if (params.roundlengths) slideheight = math.ceil(slideheight); wrapperheight = ish ? _this.height : _this.slides.length * slideheight; } slidewidth = ish ? _this.width / params.slidesperview : _this.width; if (params.roundlengths) slidewidth = math.ceil(slidewidth); wrapperwidth = ish ? _this.slides.length * slidewidth : _this.width; slidesize = ish ? slidewidth : slideheight; if (params.offsetslidesbefore > 0) { if (ish) _this.wrapperleft = slidesize * params.offsetslidesbefore; else _this.wrappertop = slidesize * params.offsetslidesbefore; } if (params.offsetslidesafter > 0) { if (ish) _this.wrapperright = slidesize * params.offsetslidesafter; else _this.wrapperbottom = slidesize * params.offsetslidesafter; } if (params.offsetpxbefore > 0) { if (ish) _this.wrapperleft = params.offsetpxbefore; else _this.wrappertop = params.offsetpxbefore; } if (params.offsetpxafter > 0) { if (ish) _this.wrapperright = params.offsetpxafter; else _this.wrapperbottom = params.offsetpxafter; } if (params.centeredslides) { if (ish) { _this.wrapperleft = (containersize - slidesize) / 2; _this.wrapperright = (containersize - slidesize) / 2; } else { _this.wrappertop = (containersize - slidesize) / 2; _this.wrapperbottom = (containersize - slidesize) / 2; } } if (ish) { if (_this.wrapperleft > 0) wrapper.style.paddingleft = _this.wrapperleft + 'px'; if (_this.wrapperright > 0) wrapper.style.paddingright = _this.wrapperright + 'px'; } else { if (_this.wrappertop > 0) wrapper.style.paddingtop = _this.wrappertop + 'px'; if (_this.wrapperbottom > 0) wrapper.style.paddingbottom = _this.wrapperbottom + 'px'; } wrappersize = ish ? wrapperwidth + _this.wrapperright + _this.wrapperleft : wrapperheight + _this.wrappertop + _this.wrapperbottom; if (parsefloat(wrapperwidth) > 0 && (!params.csswidthandheight || params.csswidthandheight === 'height')) { wrapper.style.width = wrapperwidth + 'px'; } if (parsefloat(wrapperheight) > 0 && (!params.csswidthandheight || params.csswidthandheight === 'width')) { wrapper.style.height = wrapperheight + 'px'; } slideleft = 0; _this.snapgrid = []; _this.slidesgrid = []; for (i = 0; i < _this.slides.length; i++) { _this.snapgrid.push(slideleft); _this.slidesgrid.push(slideleft); slideleft += slidesize; if (parsefloat(slidewidth) > 0 && (!params.csswidthandheight || params.csswidthandheight === 'height')) { _this.slides[i].style.width = slidewidth + 'px'; } if (parsefloat(slideheight) > 0 && (!params.csswidthandheight || params.csswidthandheight === 'width')) { _this.slides[i].style.height = slideheight + 'px'; } } } if (!_this.initialized) { _this.callplugins('onfirstinit'); if (params.onfirstinit) _this.firecallback(params.onfirstinit, _this); } else { _this.callplugins('oninit'); if (params.oninit) _this.firecallback(params.oninit, _this); } _this.initialized = true; }; _this.reinit = function (forcecalcslides) { _this.init(true, forcecalcslides); }; _this.resizefix = function (reinit) { _this.callplugins('beforeresizefix'); _this.init(params.resizereinit || reinit); // swipe to active slide in fixed mode if (!params.freemode) { _this.swipeto((params.loop ? _this.activeloopindex : _this.activeindex), 0, false); // fix autoplay if (params.autoplay) { if (_this.support.transitions && typeof autoplaytimeoutid !== 'undefined') { if (typeof autoplaytimeoutid !== 'undefined') { cleartimeout(autoplaytimeoutid); autoplaytimeoutid = undefined; _this.startautoplay(); } } else { if (typeof autoplayintervalid !== 'undefined') { clearinterval(autoplayintervalid); autoplayintervalid = undefined; _this.startautoplay(); } } } } // move wrapper to the beginning in free mode else if (_this.getwrappertranslate() < -maxwrapperposition()) { _this.setwrappertransition(0); _this.setwrappertranslate(-maxwrapperposition()); } _this.callplugins('afterresizefix'); }; /*========================================== max and min positions ============================================*/ function maxwrapperposition() { var a = (wrappersize - containersize); if (params.freemode) { a = wrappersize - containersize; } // if (params.loop) a -= containersize; if (params.slidesperview > _this.slides.length && !params.centeredslides) { a = 0; } if (a < 0) a = 0; return a; } /*========================================== event listeners ============================================*/ function initevents() { var bind = _this.h.addeventlistener; var eventtarget = params.eventtarget === 'wrapper' ? _this.wrapper : _this.container; //touch events if (! (_this.browser.ie10 || _this.browser.ie11)) { if (_this.support.touch) { bind(eventtarget, 'touchstart', ontouchstart); bind(eventtarget, 'touchmove', ontouchmove); bind(eventtarget, 'touchend', ontouchend); } if (params.simulatetouch) { bind(eventtarget, 'mousedown', ontouchstart); bind(document, 'mousemove', ontouchmove); bind(document, 'mouseup', ontouchend); } } else { bind(eventtarget, _this.touchevents.touchstart, ontouchstart); bind(document, _this.touchevents.touchmove, ontouchmove); bind(document, _this.touchevents.touchend, ontouchend); } //resize event if (params.autoresize) { bind(window, 'resize', _this.resizefix); } //slide events addslideevents(); //mousewheel _this._wheelevent = false; if (params.mousewheelcontrol) { if (document.onmousewheel !== undefined) { _this._wheelevent = 'mousewheel'; } if (!_this._wheelevent) { try { new wheelevent('wheel'); _this._wheelevent = 'wheel'; } catch (e) {} } if (!_this._wheelevent) { _this._wheelevent = 'dommousescroll'; } if (_this._wheelevent) { bind(_this.container, _this._wheelevent, handlemousewheel); } } //keyboard function _loadimage(img) { var image, src; var onready = function () { if (typeof _this === 'undefined' || _this === null) return; if (_this.imagesloaded !== undefined) _this.imagesloaded++; if (_this.imagesloaded === _this.imagestoload.length) { _this.reinit(); if (params.onimagesready) _this.firecallback(params.onimagesready, _this); } }; if(!img.complete){ src = (img.currentsrc || img.getattribute('src')) if( src ){ image = new image(); image.onload = onready; image.onerror = onready; image.src = src; } else { onready(); } } else {//image already loaded... onready(); } } if (params.keyboardcontrol) { bind(document, 'keydown', handlekeyboardkeys); } if (params.updateonimagesready) { _this.imagestoload = $$('img', _this.container); for (var i = 0; i < _this.imagestoload.length; i++) { _loadimage(_this.imagestoload[i]); } } } //remove event listeners _this.destroy = function (removestyles) { var unbind = _this.h.removeeventlistener; var eventtarget = params.eventtarget === 'wrapper' ? _this.wrapper : _this.container; //touch events if (! (_this.browser.ie10 || _this.browser.ie11)) { if (_this.support.touch) { unbind(eventtarget, 'touchstart', ontouchstart); unbind(eventtarget, 'touchmove', ontouchmove); unbind(eventtarget, 'touchend', ontouchend); } if (params.simulatetouch) { unbind(eventtarget, 'mousedown', ontouchstart); unbind(document, 'mousemove', ontouchmove); unbind(document, 'mouseup', ontouchend); } } else { unbind(eventtarget, _this.touchevents.touchstart, ontouchstart); unbind(document, _this.touchevents.touchmove, ontouchmove); unbind(document, _this.touchevents.touchend, ontouchend); } //resize event if (params.autoresize) { unbind(window, 'resize', _this.resizefix); } //init slide events removeslideevents(); //pagination if (params.paginationclickable) { removepaginationevents(); } //mousewheel if (params.mousewheelcontrol && _this._wheelevent) { unbind(_this.container, _this._wheelevent, handlemousewheel); } //keyboard if (params.keyboardcontrol) { unbind(document, 'keydown', handlekeyboardkeys); } //stop autoplay if (params.autoplay) { _this.stopautoplay(); } // remove styles if (removestyles) { _this.wrapper.removeattribute('style'); for (var i = 0; i < _this.slides.length; i++) { _this.slides[i].removeattribute('style'); } } // plugins _this.callplugins('ondestroy'); // check jquery/zepto data if (window.jquery && window.jquery(_this.container).data('swiper')) { window.jquery(_this.container).removedata('swiper'); } if (window.zepto && window.zepto(_this.container).data('swiper')) { window.zepto(_this.container).removedata('swiper'); } //destroy variable _this = null; }; function addslideevents() { var bind = _this.h.addeventlistener, i; //prevent links events if (params.preventlinks) { var links = $$('a', _this.container); for (i = 0; i < links.length; i++) { bind(links[i], 'click', preventclick); } } //release form elements if (params.releaseformelements) { var formelements = $$('input, textarea, select', _this.container); for (i = 0; i < formelements.length; i++) { bind(formelements[i], _this.touchevents.touchstart, releaseforms, true); if (_this.support.touch && params.simulatetouch) { bind(formelements[i], 'mousedown', releaseforms, true); } } } //slide clicks & touches if (params.onslideclick) { for (i = 0; i < _this.slides.length; i++) { bind(_this.slides[i], 'click', slideclick); } } if (params.onslidetouch) { for (i = 0; i < _this.slides.length; i++) { bind(_this.slides[i], _this.touchevents.touchstart, slidetouch); } } } function removeslideevents() { var unbind = _this.h.removeeventlistener, i; //slide clicks & touches if (params.onslideclick) { for (i = 0; i < _this.slides.length; i++) { unbind(_this.slides[i], 'click', slideclick); } } if (params.onslidetouch) { for (i = 0; i < _this.slides.length; i++) { unbind(_this.slides[i], _this.touchevents.touchstart, slidetouch); } } //release form elements if (params.releaseformelements) { var formelements = $$('input, textarea, select', _this.container); for (i = 0; i < formelements.length; i++) { unbind(formelements[i], _this.touchevents.touchstart, releaseforms, true); if (_this.support.touch && params.simulatetouch) { unbind(formelements[i], 'mousedown', releaseforms, true); } } } //prevent links events if (params.preventlinks) { var links = $$('a', _this.container); for (i = 0; i < links.length; i++) { unbind(links[i], 'click', preventclick); } } } /*========================================== keyboard control ============================================*/ function handlekeyboardkeys(e) { var kc = e.keycode || e.charcode; if (e.shiftkey || e.altkey || e.ctrlkey || e.metakey) return; if (kc === 37 || kc === 39 || kc === 38 || kc === 40) { var inview = false; //check that swiper should be inside of visible area of window var swiperoffset = _this.h.getoffset(_this.container); var scrollleft = _this.h.windowscroll().left; var scrolltop = _this.h.windowscroll().top; var windowwidth = _this.h.windowwidth(); var windowheight = _this.h.windowheight(); var swipercoord = [ [swiperoffset.left, swiperoffset.top], [swiperoffset.left + _this.width, swiperoffset.top], [swiperoffset.left, swiperoffset.top + _this.height], [swiperoffset.left + _this.width, swiperoffset.top + _this.height] ]; for (var i = 0; i < swipercoord.length; i++) { var point = swipercoord[i]; if ( point[0] >= scrollleft && point[0] <= scrollleft + windowwidth && point[1] >= scrolltop && point[1] <= scrolltop + 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) _this.swipenext(); if (kc === 37) _this.swipeprev(); } else { if (kc === 38 || kc === 40) { if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; } if (kc === 40) _this.swipenext(); if (kc === 38) _this.swipeprev(); } } _this.disablekeyboardcontrol = function () { params.keyboardcontrol = false; _this.h.removeeventlistener(document, 'keydown', handlekeyboardkeys); }; _this.enablekeyboardcontrol = function () { params.keyboardcontrol = true; _this.h.addeventlistener(document, 'keydown', handlekeyboardkeys); }; /*========================================== mousewheel control ============================================*/ var lastscrolltime = (new date()).gettime(); function handlemousewheel(e) { var we = _this._wheelevent; var delta = 0; //opera & ie if (e.detail) delta = -e.detail; //webkits else if (we === 'mousewheel') { if (params.mousewheelcontrolforcetoaxis) { 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 (params.mousewheelcontrolforcetoaxis) { 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 (!params.freemode) { if ((new date()).gettime() - lastscrolltime > 60) { if (delta < 0) _this.swipenext(); else _this.swipeprev(); } lastscrolltime = (new date()).gettime(); } else { //freemode or scrollcontainer: var position = _this.getwrappertranslate() + delta; if (position > 0) position = 0; if (position < -maxwrapperposition()) position = -maxwrapperposition(); _this.setwrappertransition(0); _this.setwrappertranslate(position); _this.updateactiveslide(position); // return page scroll on edge positions if (position === 0 || position === -maxwrapperposition()) return; } if (params.autoplay) _this.stopautoplay(true); if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; return false; } _this.disablemousewheelcontrol = function () { if (!_this._wheelevent) return false; params.mousewheelcontrol = false; _this.h.removeeventlistener(_this.container, _this._wheelevent, handlemousewheel); return true; }; _this.enablemousewheelcontrol = function () { if (!_this._wheelevent) return false; params.mousewheelcontrol = true; _this.h.addeventlistener(_this.container, _this._wheelevent, handlemousewheel); return true; }; /*========================= grab cursor ===========================*/ if (params.grabcursor) { var containerstyle = _this.container.style; containerstyle.cursor = 'move'; containerstyle.cursor = 'grab'; containerstyle.cursor = '-moz-grab'; containerstyle.cursor = '-webkit-grab'; } /*========================= slides events handlers ===========================*/ _this.allowslideclick = true; function slideclick(event) { if (_this.allowslideclick) { setclickedslide(event); _this.firecallback(params.onslideclick, _this, event); } } function slidetouch(event) { setclickedslide(event); _this.firecallback(params.onslidetouch, _this, event); } function setclickedslide(event) { // ie 6-8 support if (!event.currenttarget) { var element = event.srcelement; do { if (element.classname.indexof(params.slideclass) > -1) { break; } element = element.parentnode; } while (element); _this.clickedslide = element; } else { _this.clickedslide = event.currenttarget; } _this.clickedslideindex = _this.slides.indexof(_this.clickedslide); _this.clickedslideloopindex = _this.clickedslideindex - (_this.loopedslides || 0); } _this.allowlinks = true; function preventclick(e) { if (!_this.allowlinks) { if (e.preventdefault) e.preventdefault(); else e.returnvalue = false; if (params.preventlinkspropagation && 'stoppropagation' in e) { e.stoppropagation(); } return false; } } function releaseforms(e) { if (e.stoppropagation) e.stoppropagation(); else e.returnvalue = false; return false; } /*================================================== event handlers ====================================================*/ var istouchevent = false; var allowthresholdmove; var allowmomentumbounce = true; function ontouchstart(event) { if (params.preventlinks) _this.allowlinks = true; //exit if slider is already was touched if (_this.istouched || params.onlyexternal) { return false; } // blur active elements var eventtarget = event.target || event.srcelement; if (document.activeelement && document.activeelement !== document.body) { if (document.activeelement !== eventtarget) document.activeelement.blur(); } // form tag names var formtagnames = ('input select textarea').split(' '); // check for no swiping if (params.noswiping && (eventtarget) && noswipingslide(eventtarget)) return false; allowmomentumbounce = false; //check for nested swipers _this.istouched = true; istouchevent = event.type === 'touchstart'; // prevent user enter with right and the swiper move (needs istouchevent) if (!istouchevent && 'which' in event && event.which === 3) { _this.istouched = false; return false; } if (!istouchevent || event.targettouches.length === 1) { _this.callplugins('ontouchstartbegin'); if (!istouchevent && !_this.isandroid && formtagnames.indexof(eventtarget.tagname.tolowercase()) < 0) { if (event.preventdefault) event.preventdefault(); else event.returnvalue = false; } var pagex = istouchevent ? event.targettouches[0].pagex : (event.pagex || event.clientx); var pagey = istouchevent ? event.targettouches[0].pagey : (event.pagey || event.clienty); //start touches to check the scrolling _this.touches.startx = _this.touches.currentx = pagex; _this.touches.starty = _this.touches.currenty = pagey; _this.touches.start = _this.touches.current = ish ? pagex : pagey; //set transition time to 0 _this.setwrappertransition(0); //get start translate position _this.positions.start = _this.positions.current = _this.getwrappertranslate(); //set transform _this.setwrappertranslate(_this.positions.start); //touchstarttime _this.times.start = (new date()).gettime(); //unset scrolling isscrolling = undefined; //set treshold if (params.movestartthreshold > 0) { allowthresholdmove = false; } //callback if (params.ontouchstart) _this.firecallback(params.ontouchstart, _this, event); _this.callplugins('ontouchstartend'); } } var velocityprevposition, velocityprevtime; function ontouchmove(event) { // if slider is not touched - exit if (!_this.istouched || params.onlyexternal) return; if (istouchevent && event.type === 'mousemove') return; var pagex = istouchevent ? event.targettouches[0].pagex : (event.pagex || event.clientx); var pagey = istouchevent ? event.targettouches[0].pagey : (event.pagey || event.clienty); //check for scrolling if (typeof isscrolling === 'undefined' && ish) { isscrolling = !!(isscrolling || math.abs(pagey - _this.touches.starty) > math.abs(pagex - _this.touches.startx)); } if (typeof isscrolling === 'undefined' && !ish) { isscrolling = !!(isscrolling || math.abs(pagey - _this.touches.starty) < math.abs(pagex - _this.touches.startx)); } if (isscrolling) { _this.istouched = false; return; } // one way swipes if (ish) { if ((!params.swipetonext && pagex < _this.touches.startx) || ((!params.swipetoprev && pagex > _this.touches.startx))) { return; } } else { if ((!params.swipetonext && pagey < _this.touches.starty) || ((!params.swipetoprev && pagey > _this.touches.starty))) { return; } } //check for nested swipers if (event.assignedtoswiper) { _this.istouched = false; return; } event.assignedtoswiper = true; //block inner links if (params.preventlinks) { _this.allowlinks = false; } if (params.onslideclick) { _this.allowslideclick = false; } //stop autoplay if exist if (params.autoplay) { _this.stopautoplay(true); } if (!istouchevent || event.touches.length === 1) { //moved flag if (!_this.ismoved) { _this.callplugins('ontouchmovestart'); if (params.loop) { _this.fixloop(); _this.positions.start = _this.getwrappertranslate(); } if (params.ontouchmovestart) _this.firecallback(params.ontouchmovestart, _this); } _this.ismoved = true; // cancel event if (event.preventdefault) event.preventdefault(); else event.returnvalue = false; _this.touches.current = ish ? pagex : pagey; _this.positions.current = (_this.touches.current - _this.touches.start) * params.touchratio + _this.positions.start; //resistance callbacks if (_this.positions.current > 0 && params.onresistancebefore) { _this.firecallback(params.onresistancebefore, _this, _this.positions.current); } if (_this.positions.current < -maxwrapperposition() && params.onresistanceafter) { _this.firecallback(params.onresistanceafter, _this, math.abs(_this.positions.current + maxwrapperposition())); } //resistance if (params.resistance && params.resistance !== '100%') { var resistance; //resistance for negative-back sliding if (_this.positions.current > 0) { resistance = 1 - _this.positions.current / containersize / 2; if (resistance < 0.5) _this.positions.current = (containersize / 2); else _this.positions.current = _this.positions.current * resistance; } //resistance for after-end sliding if (_this.positions.current < -maxwrapperposition()) { var diff = (_this.touches.current - _this.touches.start) * params.touchratio + (maxwrapperposition() + _this.positions.start); resistance = (containersize + diff) / (containersize); var newpos = _this.positions.current - diff * (1 - resistance) / 2; var stoppos = -maxwrapperposition() - containersize / 2; if (newpos < stoppos || resistance <= 0) _this.positions.current = stoppos; else _this.positions.current = newpos; } } if (params.resistance && params.resistance === '100%') { //resistance for negative-back sliding if (_this.positions.current > 0 && !(params.freemode && !params.freemodefluid)) { _this.positions.current = 0; } //resistance for after-end sliding if (_this.positions.current < -maxwrapperposition() && !(params.freemode && !params.freemodefluid)) { _this.positions.current = -maxwrapperposition(); } } //move slides if (!params.followfinger) return; if (!params.movestartthreshold) { _this.setwrappertranslate(_this.positions.current); } else { if (math.abs(_this.touches.current - _this.touches.start) > params.movestartthreshold || allowthresholdmove) { if (!allowthresholdmove) { allowthresholdmove = true; _this.touches.start = _this.touches.current; return; } _this.setwrappertranslate(_this.positions.current); } else { _this.positions.current = _this.positions.start; } } if (params.freemode || params.watchactiveindex) { _this.updateactiveslide(_this.positions.current); } //grab cursor if (params.grabcursor) { _this.container.style.cursor = 'move'; _this.container.style.cursor = 'grabbing'; _this.container.style.cursor = '-moz-grabbin'; _this.container.style.cursor = '-webkit-grabbing'; } //velocity if (!velocityprevposition) velocityprevposition = _this.touches.current; if (!velocityprevtime) velocityprevtime = (new date()).gettime(); _this.velocity = (_this.touches.current - velocityprevposition) / ((new date()).gettime() - velocityprevtime) / 2; if (math.abs(_this.touches.current - velocityprevposition) < 2) _this.velocity = 0; velocityprevposition = _this.touches.current; velocityprevtime = (new date()).gettime(); //callbacks _this.callplugins('ontouchmoveend'); if (params.ontouchmove) _this.firecallback(params.ontouchmove, _this, event); return false; } } function ontouchend(event) { //check for scrolling if (isscrolling) { _this.swipereset(); } // if slider is not touched exit if (params.onlyexternal || !_this.istouched) return; _this.istouched = false; //return grab cursor if (params.grabcursor) { _this.container.style.cursor = 'move'; _this.container.style.cursor = 'grab'; _this.container.style.cursor = '-moz-grab'; _this.container.style.cursor = '-webkit-grab'; } //check for current position if (!_this.positions.current && _this.positions.current !== 0) { _this.positions.current = _this.positions.start; } //for case if slider touched but not moved if (params.followfinger) { _this.setwrappertranslate(_this.positions.current); } // touchendtime _this.times.end = (new date()).gettime(); //difference _this.touches.diff = _this.touches.current - _this.touches.start; _this.touches.abs = math.abs(_this.touches.diff); _this.positions.diff = _this.positions.current - _this.positions.start; _this.positions.abs = math.abs(_this.positions.diff); var diff = _this.positions.diff; var diffabs = _this.positions.abs; var timediff = _this.times.end - _this.times.start; if (diffabs < 5 && (timediff) < 300 && _this.allowlinks === false) { if (!params.freemode && diffabs !== 0) _this.swipereset(); //release inner links if (params.preventlinks) { _this.allowlinks = true; } if (params.onslideclick) { _this.allowslideclick = true; } } settimeout(function () { //release inner links if (typeof _this === 'undefined' || _this === null) return; if (params.preventlinks) { _this.allowlinks = true; } if (params.onslideclick) { _this.allowslideclick = true; } }, 100); var maxposition = maxwrapperposition(); //not moved or prevent negative back sliding/after-end sliding if (!_this.ismoved && params.freemode) { _this.ismoved = false; if (params.ontouchend) _this.firecallback(params.ontouchend, _this, event); _this.callplugins('ontouchend'); return; } if (!_this.ismoved || _this.positions.current > 0 || _this.positions.current < -maxposition) { _this.swipereset(); if (params.ontouchend) _this.firecallback(params.ontouchend, _this, event); _this.callplugins('ontouchend'); return; } _this.ismoved = false; //free mode if (params.freemode) { if (params.freemodefluid) { var momentumduration = 1000 * params.momentumratio; var momentumdistance = _this.velocity * momentumduration; var newposition = _this.positions.current + momentumdistance; var dobounce = false; var afterbounceposition; var bounceamount = math.abs(_this.velocity) * 20 * params.momentumbounceratio; if (newposition < -maxposition) { if (params.momentumbounce && _this.support.transitions) { if (newposition + maxposition < -bounceamount) newposition = -maxposition - bounceamount; afterbounceposition = -maxposition; dobounce = true; allowmomentumbounce = true; } else newposition = -maxposition; } if (newposition > 0) { if (params.momentumbounce && _this.support.transitions) { if (newposition > bounceamount) newposition = bounceamount; afterbounceposition = 0; dobounce = true; allowmomentumbounce = true; } else newposition = 0; } //fix duration if (_this.velocity !== 0) momentumduration = math.abs((newposition - _this.positions.current) / _this.velocity); _this.setwrappertranslate(newposition); _this.setwrappertransition(momentumduration); if (params.momentumbounce && dobounce) { _this.wrappertransitionend(function () { if (!allowmomentumbounce) return; if (params.onmomentumbounce) _this.firecallback(params.onmomentumbounce, _this); _this.callplugins('onmomentumbounce'); _this.setwrappertranslate(afterbounceposition); _this.setwrappertransition(300); }); } _this.updateactiveslide(newposition); } if (!params.freemodefluid || timediff >= 300) _this.updateactiveslide(_this.positions.current); if (params.ontouchend) _this.firecallback(params.ontouchend, _this, event); _this.callplugins('ontouchend'); return; } //direction direction = diff < 0 ? 'tonext' : 'toprev'; //short touches if (direction === 'tonext' && (timediff <= 300)) { if (diffabs < 30 || !params.shortswipes) _this.swipereset(); else _this.swipenext(true, true); } if (direction === 'toprev' && (timediff <= 300)) { if (diffabs < 30 || !params.shortswipes) _this.swipereset(); else _this.swipeprev(true, true); } //long touches var targetslidesize = 0; if (params.slidesperview === 'auto') { //define current slide's width var currentposition = math.abs(_this.getwrappertranslate()); var slidesoffset = 0; var _slidesize; for (var i = 0; i < _this.slides.length; i++) { _slidesize = ish ? _this.slides[i].getwidth(true, params.roundlengths) : _this.slides[i].getheight(true, params.roundlengths); slidesoffset += _slidesize; if (slidesoffset > currentposition) { targetslidesize = _slidesize; break; } } if (targetslidesize > containersize) targetslidesize = containersize; } else { targetslidesize = slidesize * params.slidesperview; } if (direction === 'tonext' && (timediff > 300)) { if (diffabs >= targetslidesize * params.longswipesratio) { _this.swipenext(true, true); } else { _this.swipereset(); } } if (direction === 'toprev' && (timediff > 300)) { if (diffabs >= targetslidesize * params.longswipesratio) { _this.swipeprev(true, true); } else { _this.swipereset(); } } if (params.ontouchend) _this.firecallback(params.ontouchend, _this, event); _this.callplugins('ontouchend'); } /*================================================== noswiping bubble check by isaac strack ====================================================*/ function hasclass(el, classname) { return el && el.getattribute('class') && el.getattribute('class').indexof(classname) > -1; } function noswipingslide(el) { /*this function is specifically designed to check the parent elements for the noswiping class, up to the wrapper. we need to check parents because while ontouchstart bubbles, _this.istouched is checked in ontouchstart, which stops the bubbling. so, if a text box, for example, is the initial target, and the parent slide container has the noswiping class, the _this.istouched check will never find it, and what was supposed to be noswiping is able to be swiped. this function will iterate up and check for the noswiping class in parents, up through the wrapperclass.*/ // first we create a truthy variable, which is that swiping is allowd (noswiping = false) var noswiping = false; // now we iterate up (parentelements) until we reach the node with the wrapperclass. do { // each time, we check to see if there's a 'swiper-no-swiping' class (noswipingclass). if (hasclass(el, params.noswipingclass)) { noswiping = true; // if there is, we set noswiping = true; } el = el.parentelement; // now we iterate up (parent node) } while (!noswiping && el.parentelement && !hasclass(el, params.wrapperclass)); // also include el.parentelement truthy, just in case. // because we didn't check the wrapper itself, we do so now, if noswiping is false: if (!noswiping && hasclass(el, params.wrapperclass) && hasclass(el,params.noswipingclass)) noswiping = true; // if the wrapper has the noswipingclass, we set noswiping = true; return noswiping; } function addclasstohtmlstring(klass, outerhtml) { var par = document.createelement('div'); var child; par.innerhtml = outerhtml; child = par.firstchild; child.classname += ' ' + klass; return child.outerhtml; } /*================================================== swipe functions ====================================================*/ _this.swipenext = function (runcallbacks, internal) { if (typeof runcallbacks === 'undefined') runcallbacks = true; if (!internal && params.loop) _this.fixloop(); if (!internal && params.autoplay) _this.stopautoplay(true); _this.callplugins('onswipenext'); var currentposition = _this.getwrappertranslate().tofixed(2); var newposition = currentposition; if (params.slidesperview === 'auto') { for (var i = 0; i < _this.snapgrid.length; i++) { if (-currentposition >= _this.snapgrid[i].tofixed(2) && -currentposition < _this.snapgrid[i + 1].tofixed(2)) { newposition = -_this.snapgrid[i + 1]; break; } } } else { var groupsize = slidesize * params.slidespergroup; newposition = -(math.floor(math.abs(currentposition) / math.floor(groupsize)) * groupsize + groupsize); } if (newposition < -maxwrapperposition()) { newposition = -maxwrapperposition(); } if (newposition === currentposition) return false; swipetoposition(newposition, 'next', {runcallbacks: runcallbacks}); return true; }; _this.swipeprev = function (runcallbacks, internal) { if (typeof runcallbacks === 'undefined') runcallbacks = true; if (!internal && params.loop) _this.fixloop(); if (!internal && params.autoplay) _this.stopautoplay(true); _this.callplugins('onswipeprev'); var currentposition = math.ceil(_this.getwrappertranslate()); var newposition; if (params.slidesperview === 'auto') { newposition = 0; for (var i = 1; i < _this.snapgrid.length; i++) { if (-currentposition === _this.snapgrid[i]) { newposition = -_this.snapgrid[i - 1]; break; } if (-currentposition > _this.snapgrid[i] && -currentposition < _this.snapgrid[i + 1]) { newposition = -_this.snapgrid[i]; break; } } } else { var groupsize = slidesize * params.slidespergroup; newposition = -(math.ceil(-currentposition / groupsize) - 1) * groupsize; } if (newposition > 0) newposition = 0; if (newposition === currentposition) return false; swipetoposition(newposition, 'prev', {runcallbacks: runcallbacks}); return true; }; _this.swipereset = function (runcallbacks) { if (typeof runcallbacks === 'undefined') runcallbacks = true; _this.callplugins('onswipereset'); var currentposition = _this.getwrappertranslate(); var groupsize = slidesize * params.slidespergroup; var newposition; var maxposition = -maxwrapperposition(); if (params.slidesperview === 'auto') { newposition = 0; for (var i = 0; i < _this.snapgrid.length; i++) { if (-currentposition === _this.snapgrid[i]) return; if (-currentposition >= _this.snapgrid[i] && -currentposition < _this.snapgrid[i + 1]) { if (_this.positions.diff > 0) newposition = -_this.snapgrid[i + 1]; else newposition = -_this.snapgrid[i]; break; } } if (-currentposition >= _this.snapgrid[_this.snapgrid.length - 1]) newposition = -_this.snapgrid[_this.snapgrid.length - 1]; if (currentposition <= -maxwrapperposition()) newposition = -maxwrapperposition(); } else { newposition = currentposition < 0 ? math.round(currentposition / groupsize) * groupsize : 0; if (currentposition <= -maxwrapperposition()) newposition = -maxwrapperposition(); } if (params.scrollcontainer) { newposition = currentposition < 0 ? currentposition : 0; } if (newposition < -maxwrapperposition()) { newposition = -maxwrapperposition(); } if (params.scrollcontainer && (containersize > slidesize)) { newposition = 0; } if (newposition === currentposition) return false; swipetoposition(newposition, 'reset', {runcallbacks: runcallbacks}); return true; }; _this.swipeto = function (index, speed, runcallbacks) { index = parseint(index, 10); _this.callplugins('onswipeto', {index: index, speed: speed}); if (params.loop) index = index + _this.loopedslides; var currentposition = _this.getwrappertranslate(); if (index > (_this.slides.length - 1) || index < 0) return; var newposition; if (params.slidesperview === 'auto') { newposition = -_this.slidesgrid[index]; } else { newposition = -index * slidesize; } if (newposition < - maxwrapperposition()) { newposition = - maxwrapperposition(); } if (newposition === currentposition) return false; if (typeof runcallbacks === 'undefined') runcallbacks = true; swipetoposition(newposition, 'to', {index: index, speed: speed, runcallbacks: runcallbacks}); return true; }; function swipetoposition(newposition, action, tooptions) { var speed = (action === 'to' && tooptions.speed >= 0) ? tooptions.speed : params.speed; var timeold = + new date(); function anim() { var timenew = + new date(); var time = timenew - timeold; currentposition += animationstep * time / (1000 / 60); condition = direction === 'tonext' ? currentposition > newposition : currentposition < newposition; if (condition) { _this.setwrappertranslate(math.ceil(currentposition)); _this._domanimating = true; window.settimeout(function () { anim(); }, 1000 / 60); } else { if (params.onslidechangeend) { if (action === 'to') { if (tooptions.runcallbacks === true) _this.firecallback(params.onslidechangeend, _this, direction); } else { _this.firecallback(params.onslidechangeend, _this, direction); } } _this.setwrappertranslate(newposition); _this._domanimating = false; } } if (_this.support.transitions || !params.domanimation) { _this.setwrappertranslate(newposition); _this.setwrappertransition(speed); } else { //try the dom animation var currentposition = _this.getwrappertranslate(); var animationstep = math.ceil((newposition - currentposition) / speed * (1000 / 60)); var direction = currentposition > newposition ? 'tonext' : 'toprev'; var condition = direction === 'tonext' ? currentposition > newposition : currentposition < newposition; if (_this._domanimating) return; anim(); } //update active slide index _this.updateactiveslide(newposition); //callbacks if (params.onslidenext && action === 'next' && tooptions.runcallbacks === true) { _this.firecallback(params.onslidenext, _this, newposition); } if (params.onslideprev && action === 'prev' && tooptions.runcallbacks === true) { _this.firecallback(params.onslideprev, _this, newposition); } //'reset' callback if (params.onslidereset && action === 'reset' && tooptions.runcallbacks === true) { _this.firecallback(params.onslidereset, _this, newposition); } //'next', 'prev' and 'to' callbacks if ((action === 'next' || action === 'prev' || action === 'to') && tooptions.runcallbacks === true) slidechangecallbacks(action); } /*================================================== transition callbacks ====================================================*/ //prevent multiple callbacks _this._queuestartcallbacks = false; _this._queueendcallbacks = false; function slidechangecallbacks(direction) { //transition start callback _this.callplugins('onslidechangestart'); if (params.onslidechangestart) { if (params.queuestartcallbacks && _this.support.transitions) { if (_this._queuestartcallbacks) return; _this._queuestartcallbacks = true; _this.firecallback(params.onslidechangestart, _this, direction); _this.wrappertransitionend(function () { _this._queuestartcallbacks = false; }); } else _this.firecallback(params.onslidechangestart, _this, direction); } //transition end callback if (params.onslidechangeend) { if (_this.support.transitions) { if (params.queueendcallbacks) { if (_this._queueendcallbacks) return; _this._queueendcallbacks = true; _this.wrappertransitionend(function (swiper) { _this.firecallback(params.onslidechangeend, swiper, direction); }); } else { _this.wrappertransitionend(function (swiper) { _this.firecallback(params.onslidechangeend, swiper, direction); }); } } else { if (!params.domanimation) { settimeout(function () { _this.firecallback(params.onslidechangeend, _this, direction); }, 10); } } } } /*================================================== update active slide index ====================================================*/ _this.updateactiveslide = function (position) { if (!_this.initialized) return; if (_this.slides.length === 0) return; _this.previousindex = _this.activeindex; if (typeof position === 'undefined') position = _this.getwrappertranslate(); if (position > 0) position = 0; var i; if (params.slidesperview === 'auto') { var slidesoffset = 0; _this.activeindex = _this.slidesgrid.indexof(-position); if (_this.activeindex < 0) { for (i = 0; i < _this.slidesgrid.length - 1; i++) { if (-position > _this.slidesgrid[i] && -position < _this.slidesgrid[i + 1]) { break; } } var leftdistance = math.abs(_this.slidesgrid[i] + position); var rightdistance = math.abs(_this.slidesgrid[i + 1] + position); if (leftdistance <= rightdistance) _this.activeindex = i; else _this.activeindex = i + 1; } } else { _this.activeindex = math[params.visibilityfullfit ? 'ceil' : 'round'](-position / slidesize); } if (_this.activeindex === _this.slides.length) _this.activeindex = _this.slides.length - 1; if (_this.activeindex < 0) _this.activeindex = 0; // check for slide if (!_this.slides[_this.activeindex]) return; // calc visible slides _this.calcvisibleslides(position); // mark visible and active slides with additonal classes if (_this.support.classlist) { var slide; for (i = 0; i < _this.slides.length; i++) { slide = _this.slides[i]; slide.classlist.remove(params.slideactiveclass); if (_this.visibleslides.indexof(slide) >= 0) { slide.classlist.add(params.slidevisibleclass); } else { slide.classlist.remove(params.slidevisibleclass); } } _this.slides[_this.activeindex].classlist.add(params.slideactiveclass); } else { var activeclassregexp = new regexp('\\s*' + params.slideactiveclass); var inviewclassregexp = new regexp('\\s*' + params.slidevisibleclass); for (i = 0; i < _this.slides.length; i++) { _this.slides[i].classname = _this.slides[i].classname.replace(activeclassregexp, '').replace(inviewclassregexp, ''); if (_this.visibleslides.indexof(_this.slides[i]) >= 0) { _this.slides[i].classname += ' ' + params.slidevisibleclass; } } _this.slides[_this.activeindex].classname += ' ' + params.slideactiveclass; } //update loop index if (params.loop) { var ls = _this.loopedslides; _this.activeloopindex = _this.activeindex - ls; if (_this.activeloopindex >= _this.slides.length - ls * 2) { _this.activeloopindex = _this.slides.length - ls * 2 - _this.activeloopindex; } if (_this.activeloopindex < 0) { _this.activeloopindex = _this.slides.length - ls * 2 + _this.activeloopindex; } if (_this.activeloopindex < 0) _this.activeloopindex = 0; } else { _this.activeloopindex = _this.activeindex; } //update pagination if (params.pagination) { _this.updatepagination(position); } }; /*================================================== pagination ====================================================*/ _this.createpagination = function (firstinit) { if (params.paginationclickable && _this.paginationbuttons) { removepaginationevents(); } _this.paginationcontainer = params.pagination.nodetype ? params.pagination : $$(params.pagination)[0]; if (params.createpagination) { var paginationhtml = ''; var numofslides = _this.slides.length; var numofbuttons = numofslides; if (params.loop) numofbuttons -= _this.loopedslides * 2; for (var i = 0; i < numofbuttons; i++) { paginationhtml += '<' + params.paginationelement + ' class="' + params.paginationelementclass + '">'; } _this.paginationcontainer.innerhtml = paginationhtml; } _this.paginationbuttons = $$('.' + params.paginationelementclass, _this.paginationcontainer); if (!firstinit) _this.updatepagination(); _this.callplugins('oncreatepagination'); if (params.paginationclickable) { addpaginationevents(); } }; function removepaginationevents() { var pagers = _this.paginationbuttons; if (pagers) { for (var i = 0; i < pagers.length; i++) { _this.h.removeeventlistener(pagers[i], 'click', paginationclick); } } } function addpaginationevents() { var pagers = _this.paginationbuttons; if (pagers) { for (var i = 0; i < pagers.length; i++) { _this.h.addeventlistener(pagers[i], 'click', paginationclick); } } } function paginationclick(e) { var index; var target = e.target || e.srcelement; var pagers = _this.paginationbuttons; for (var i = 0; i < pagers.length; i++) { if (target === pagers[i]) index = i; } if (params.autoplay) _this.stopautoplay(true); _this.swipeto(index); } _this.updatepagination = function (position) { if (!params.pagination) return; if (_this.slides.length < 1) return; var activepagers = $$('.' + params.paginationactiveclass, _this.paginationcontainer); if (!activepagers) return; //reset all buttons' class to not active var pagers = _this.paginationbuttons; if (pagers.length === 0) return; for (var i = 0; i < pagers.length; i++) { pagers[i].classname = params.paginationelementclass; } var indexoffset = params.loop ? _this.loopedslides : 0; if (params.paginationasrange) { if (!_this.visibleslides) _this.calcvisibleslides(position); //get visible indexes var visibleindexes = []; var j; // lopp index - avoid jshint w004 / w038 for (j = 0; j < _this.visibleslides.length; j++) { var visindex = _this.slides.indexof(_this.visibleslides[j]) - indexoffset; if (params.loop && visindex < 0) { visindex = _this.slides.length - _this.loopedslides * 2 + visindex; } if (params.loop && visindex >= _this.slides.length - _this.loopedslides * 2) { visindex = _this.slides.length - _this.loopedslides * 2 - visindex; visindex = math.abs(visindex); } visibleindexes.push(visindex); } for (j = 0; j < visibleindexes.length; j++) { if (pagers[visibleindexes[j]]) pagers[visibleindexes[j]].classname += ' ' + params.paginationvisibleclass; } if (params.loop) { if (pagers[_this.activeloopindex] !== undefined) { pagers[_this.activeloopindex].classname += ' ' + params.paginationactiveclass; } } else { if (pagers[_this.activeindex]) pagers[_this.activeindex].classname += ' ' + params.paginationactiveclass; } } else { if (params.loop) { if (pagers[_this.activeloopindex]) pagers[_this.activeloopindex].classname += ' ' + params.paginationactiveclass + ' ' + params.paginationvisibleclass; } else { if (pagers[_this.activeindex]) pagers[_this.activeindex].classname += ' ' + params.paginationactiveclass + ' ' + params.paginationvisibleclass; } } }; _this.calcvisibleslides = function (position) { var visibleslides = []; var _slideleft = 0, _slidesize = 0, _slideright = 0; if (ish && _this.wrapperleft > 0) position = position + _this.wrapperleft; if (!ish && _this.wrappertop > 0) position = position + _this.wrappertop; for (var i = 0; i < _this.slides.length; i++) { _slideleft += _slidesize; if (params.slidesperview === 'auto') _slidesize = ish ? _this.h.getwidth(_this.slides[i], true, params.roundlengths) : _this.h.getheight(_this.slides[i], true, params.roundlengths); else _slidesize = slidesize; _slideright = _slideleft + _slidesize; var isvisibile = false; if (params.visibilityfullfit) { if (_slideleft >= -position && _slideright <= -position + containersize) isvisibile = true; if (_slideleft <= -position && _slideright >= -position + containersize) isvisibile = true; } else { if (_slideright > -position && _slideright <= ((-position + containersize))) isvisibile = true; if (_slideleft >= -position && _slideleft < ((-position + containersize))) isvisibile = true; if (_slideleft < -position && _slideright > ((-position + containersize))) isvisibile = true; } if (isvisibile) visibleslides.push(_this.slides[i]); } if (visibleslides.length === 0) visibleslides = [_this.slides[_this.activeindex]]; _this.visibleslides = visibleslides; }; /*========================================== autoplay ============================================*/ var autoplaytimeoutid, autoplayintervalid; _this.startautoplay = function () { if (_this.support.transitions) { if (typeof autoplaytimeoutid !== 'undefined') return false; if (!params.autoplay) return; _this.callplugins('onautoplaystart'); if (params.onautoplaystart) _this.firecallback(params.onautoplaystart, _this); autoplay(); } else { if (typeof autoplayintervalid !== 'undefined') return false; if (!params.autoplay) return; _this.callplugins('onautoplaystart'); if (params.onautoplaystart) _this.firecallback(params.onautoplaystart, _this); autoplayintervalid = setinterval(function () { if (params.loop) { _this.fixloop(); _this.swipenext(true, true); } else if (!_this.swipenext(true, true)) { if (!params.autoplaystoponlast) _this.swipeto(0); else { clearinterval(autoplayintervalid); autoplayintervalid = undefined; } } }, params.autoplay); } }; _this.stopautoplay = function (internal) { if (_this.support.transitions) { if (!autoplaytimeoutid) return; if (autoplaytimeoutid) cleartimeout(autoplaytimeoutid); autoplaytimeoutid = undefined; if (internal && !params.autoplaydisableoninteraction) { _this.wrappertransitionend(function () { autoplay(); }); } _this.callplugins('onautoplaystop'); if (params.onautoplaystop) _this.firecallback(params.onautoplaystop, _this); } else { if (autoplayintervalid) clearinterval(autoplayintervalid); autoplayintervalid = undefined; _this.callplugins('onautoplaystop'); if (params.onautoplaystop) _this.firecallback(params.onautoplaystop, _this); } }; function autoplay() { autoplaytimeoutid = settimeout(function () { if (params.loop) { _this.fixloop(); _this.swipenext(true, true); } else if (!_this.swipenext(true, true)) { if (!params.autoplaystoponlast) _this.swipeto(0); else { cleartimeout(autoplaytimeoutid); autoplaytimeoutid = undefined; } } _this.wrappertransitionend(function () { if (typeof autoplaytimeoutid !== 'undefined') autoplay(); }); }, params.autoplay); } /*================================================== loop ====================================================*/ _this.loopcreated = false; _this.removeloopedslides = function () { if (_this.loopcreated) { for (var i = 0; i < _this.slides.length; i++) { if (_this.slides[i].getdata('looped') === true) _this.wrapper.removechild(_this.slides[i]); } } }; _this.createloop = function () { if (_this.slides.length === 0) return; if (params.slidesperview === 'auto') { _this.loopedslides = params.loopedslides || 1; } else { _this.loopedslides = params.slidesperview + params.loopadditionalslides; } if (_this.loopedslides > _this.slides.length) { _this.loopedslides = _this.slides.length; } var slidefirsthtml = '', slidelasthtml = '', i; var slidessetfullhtml = ''; /** loopedslides is too large if loopadditionalslides are set. need to divide the slides by maximum number of slides existing. @author tomaz lovrec */ var numslides = _this.slides.length; var fullslidesets = math.floor(_this.loopedslides / numslides); var remainderslides = _this.loopedslides % numslides; // assemble full sets of slides for (i = 0; i < (fullslidesets * numslides); i++) { var j = i; if (i >= numslides) { var over = math.floor(i / numslides); j = i - (numslides * over); } slidessetfullhtml += _this.slides[j].outerhtml; } // assemble remainder slides // assemble remainder appended to existing slides for (i = 0; i < remainderslides;i++) { slidelasthtml += addclasstohtmlstring(params.slideduplicateclass, _this.slides[i].outerhtml); } // assemble slides that get preppended to existing slides for (i = numslides - remainderslides; i < numslides;i++) { slidefirsthtml += addclasstohtmlstring(params.slideduplicateclass, _this.slides[i].outerhtml); } // assemble all slides var slides = slidefirsthtml + slidessetfullhtml + wrapper.innerhtml + slidessetfullhtml + slidelasthtml; // set the slides wrapper.innerhtml = slides; _this.loopcreated = true; _this.calcslides(); //update looped slides with special class for (i = 0; i < _this.slides.length; i++) { if (i < _this.loopedslides || i >= _this.slides.length - _this.loopedslides) _this.slides[i].setdata('looped', true); } _this.callplugins('oncreateloop'); }; _this.fixloop = function () { var newindex; //fix for negative oversliding if (_this.activeindex < _this.loopedslides) { newindex = _this.slides.length - _this.loopedslides * 3 + _this.activeindex; _this.swipeto(newindex, 0, false); } //fix for positive oversliding else if ((params.slidesperview === 'auto' && _this.activeindex >= _this.loopedslides * 2) || (_this.activeindex > _this.slides.length - params.slidesperview * 2)) { newindex = -_this.slides.length + _this.activeindex + _this.loopedslides; _this.swipeto(newindex, 0, false); } }; /*================================================== slides loader ====================================================*/ _this.loadslides = function () { var slideshtml = ''; _this.activeloaderindex = 0; var slides = params.loader.slides; var slidestoload = params.loader.loadallslides ? slides.length : params.slidesperview * (1 + params.loader.surroundgroups); for (var i = 0; i < slidestoload; i++) { if (params.loader.slideshtmltype === 'outer') slideshtml += slides[i]; else { slideshtml += '<' + params.slideelement + ' class="' + params.slideclass + '" data-swiperindex="' + i + '">' + slides[i] + ''; } } _this.wrapper.innerhtml = slideshtml; _this.calcslides(true); //add permanent transitionend callback if (!params.loader.loadallslides) { _this.wrappertransitionend(_this.reloadslides, true); } }; _this.reloadslides = function () { var slides = params.loader.slides; var newactiveindex = parseint(_this.activeslide().data('swiperindex'), 10); if (newactiveindex < 0 || newactiveindex > slides.length - 1) return; //<-- exit _this.activeloaderindex = newactiveindex; var firstindex = math.max(0, newactiveindex - params.slidesperview * params.loader.surroundgroups); var lastindex = math.min(newactiveindex + params.slidesperview * (1 + params.loader.surroundgroups) - 1, slides.length - 1); //update transforms if (newactiveindex > 0) { var newtransform = -slidesize * (newactiveindex - firstindex); _this.setwrappertranslate(newtransform); _this.setwrappertransition(0); } var i; // loop index //new slides if (params.loader.logic === 'reload') { _this.wrapper.innerhtml = ''; var slideshtml = ''; for (i = firstindex; i <= lastindex; i++) { slideshtml += params.loader.slideshtmltype === 'outer' ? slides[i] : '<' + params.slideelement + ' class="' + params.slideclass + '" data-swiperindex="' + i + '">' + slides[i] + ''; } _this.wrapper.innerhtml = slideshtml; } else { var minexistindex = 1000; var maxexistindex = 0; for (i = 0; i < _this.slides.length; i++) { var index = _this.slides[i].data('swiperindex'); if (index < firstindex || index > lastindex) { _this.wrapper.removechild(_this.slides[i]); } else { minexistindex = math.min(index, minexistindex); maxexistindex = math.max(index, maxexistindex); } } for (i = firstindex; i <= lastindex; i++) { var newslide; if (i < minexistindex) { newslide = document.createelement(params.slideelement); newslide.classname = params.slideclass; newslide.setattribute('data-swiperindex', i); newslide.innerhtml = slides[i]; _this.wrapper.insertbefore(newslide, _this.wrapper.firstchild); } if (i > maxexistindex) { newslide = document.createelement(params.slideelement); newslide.classname = params.slideclass; newslide.setattribute('data-swiperindex', i); newslide.innerhtml = slides[i]; _this.wrapper.appendchild(newslide); } } } //reinit _this.reinit(true); }; /*================================================== make swiper ====================================================*/ function makeswiper() { _this.calcslides(); if (params.loader.slides.length > 0 && _this.slides.length === 0) { _this.loadslides(); } if (params.loop) { _this.createloop(); } _this.init(); initevents(); if (params.pagination) { _this.createpagination(true); } if (params.loop || params.initialslide > 0) { _this.swipeto(params.initialslide, 0, false); } else { _this.updateactiveslide(0); } if (params.autoplay) { _this.startautoplay(); } /** * set center slide index. * * @author tomaz lovrec */ _this.centerindex = _this.activeindex; // callbacks if (params.onswipercreated) _this.firecallback(params.onswipercreated, _this); _this.callplugins('onswipercreated'); } makeswiper(); }; swiper.prototype = { plugins : {}, /*================================================== wrapper operations ====================================================*/ wrappertransitionend : function (callback, permanent) { 'use strict'; var a = this, el = a.wrapper, events = ['webkittransitionend', 'transitionend', 'otransitionend', 'mstransitionend', 'mstransitionend'], i; function firecallback(e) { if (e.target !== el) return; callback(a); if (a.params.queueendcallbacks) a._queueendcallbacks = false; if (!permanent) { for (i = 0; i < events.length; i++) { a.h.removeeventlistener(el, events[i], firecallback); } } } if (callback) { for (i = 0; i < events.length; i++) { a.h.addeventlistener(el, events[i], firecallback); } } }, getwrappertranslate : function (axis) { 'use strict'; var el = this.wrapper, matrix, curtransform, curstyle, transformmatrix; // automatic axis detection if (typeof axis === 'undefined') { axis = this.params.mode === 'horizontal' ? 'x' : 'y'; } if (this.support.transforms && this.params.usecss3transforms) { curstyle = window.getcomputedstyle(el, null); if (window.webkitcssmatrix) { // some old versions of webkit choke when 'none' is passed; pass // empty string instead in this case transformmatrix = new webkitcssmatrix(curstyle.webkittransform === 'none' ? '' : curstyle.webkittransform); } else { transformmatrix = curstyle.moztransform || curstyle.otransform || curstyle.mstransform || curstyle.mstransform || curstyle.transform || curstyle.getpropertyvalue('transform').replace('translate(', 'matrix(1, 0, 0, 1,'); matrix = transformmatrix.tostring().split(','); } if (axis === 'x') { //latest chrome and webkits fix if (window.webkitcssmatrix) curtransform = transformmatrix.m41; //crazy ie10 matrix else if (matrix.length === 16) curtransform = parsefloat(matrix[12]); //normal browsers else curtransform = parsefloat(matrix[4]); } if (axis === 'y') { //latest chrome and webkits fix if (window.webkitcssmatrix) curtransform = transformmatrix.m42; //crazy ie10 matrix else if (matrix.length === 16) curtransform = parsefloat(matrix[13]); //normal browsers else curtransform = parsefloat(matrix[5]); } } else { if (axis === 'x') curtransform = parsefloat(el.style.left, 10) || 0; if (axis === 'y') curtransform = parsefloat(el.style.top, 10) || 0; } return curtransform || 0; }, setwrappertranslate : function (x, y, z) { 'use strict'; var es = this.wrapper.style, coords = {x: 0, y: 0, z: 0}, translate; // passed all coordinates if (arguments.length === 3) { coords.x = x; coords.y = y; coords.z = z; } // passed one coordinate and optional axis else { if (typeof y === 'undefined') { y = this.params.mode === 'horizontal' ? 'x' : 'y'; } coords[y] = x; } if (this.support.transforms && this.params.usecss3transforms) { translate = this.support.transforms3d ? 'translate3d(' + coords.x + 'px, ' + coords.y + 'px, ' + coords.z + 'px)' : 'translate(' + coords.x + 'px, ' + coords.y + 'px)'; es.webkittransform = es.mstransform = es.mstransform = es.moztransform = es.otransform = es.transform = translate; } else { es.left = coords.x + 'px'; es.top = coords.y + 'px'; } this.callplugins('onsetwrappertransform', coords); if (this.params.onsetwrappertransform) this.firecallback(this.params.onsetwrappertransform, this, coords); }, setwrappertransition : function (duration) { 'use strict'; var es = this.wrapper.style; es.webkittransitionduration = es.mstransitionduration = es.mstransitionduration = es.moztransitionduration = es.otransitionduration = es.transitionduration = (duration / 1000) + 's'; this.callplugins('onsetwrappertransition', {duration: duration}); if (this.params.onsetwrappertransition) this.firecallback(this.params.onsetwrappertransition, this, duration); }, /*================================================== helpers ====================================================*/ h : { getwidth: function (el, outer, round) { 'use strict'; var width = window.getcomputedstyle(el, null).getpropertyvalue('width'); var returnwidth = parsefloat(width); //ie fixes if (isnan(returnwidth) || width.indexof('%') > 0 || returnwidth < 0) { returnwidth = el.offsetwidth - parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-left')) - parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-right')); } if (outer) returnwidth += parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-left')) + parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-right')); if (round) return math.ceil(returnwidth); else return returnwidth; }, getheight: function (el, outer, round) { 'use strict'; if (outer) return el.offsetheight; var height = window.getcomputedstyle(el, null).getpropertyvalue('height'); var returnheight = parsefloat(height); //ie fixes if (isnan(returnheight) || height.indexof('%') > 0 || returnheight < 0) { returnheight = el.offsetheight - parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-top')) - parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-bottom')); } if (outer) returnheight += parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-top')) + parsefloat(window.getcomputedstyle(el, null).getpropertyvalue('padding-bottom')); if (round) return math.ceil(returnheight); else return returnheight; }, getoffset: function (el) { 'use strict'; 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; if (document.documentelement && !window.pageyoffset) { //ie7-8 scrolltop = document.documentelement.scrolltop; scrollleft = document.documentelement.scrollleft; } return { top: box.top + scrolltop - clienttop, left: box.left + scrollleft - clientleft }; }, windowwidth : function () { 'use strict'; if (window.innerwidth) return window.innerwidth; else if (document.documentelement && document.documentelement.clientwidth) return document.documentelement.clientwidth; }, windowheight : function () { 'use strict'; if (window.innerheight) return window.innerheight; else if (document.documentelement && document.documentelement.clientheight) return document.documentelement.clientheight; }, windowscroll : function () { 'use strict'; if (typeof pageyoffset !== 'undefined') { return { left: window.pagexoffset, top: window.pageyoffset }; } else if (document.documentelement) { return { left: document.documentelement.scrollleft, top: document.documentelement.scrolltop }; } }, addeventlistener : function (el, event, listener, usecapture) { 'use strict'; if (typeof usecapture === 'undefined') { usecapture = false; } if (el.addeventlistener) { el.addeventlistener(event, listener, usecapture); } else if (el.attachevent) { el.attachevent('on' + event, listener); } }, removeeventlistener : function (el, event, listener, usecapture) { 'use strict'; if (typeof usecapture === 'undefined') { usecapture = false; } if (el.removeeventlistener) { el.removeeventlistener(event, listener, usecapture); } else if (el.detachevent) { el.detachevent('on' + event, listener); } } }, settransform : function (el, transform) { 'use strict'; var es = el.style; es.webkittransform = es.mstransform = es.mstransform = es.moztransform = es.otransform = es.transform = transform; }, settranslate : function (el, translate) { 'use strict'; var es = el.style; var pos = { x : translate.x || 0, y : translate.y || 0, z : translate.z || 0 }; var transformstring = this.support.transforms3d ? 'translate3d(' + (pos.x) + 'px,' + (pos.y) + 'px,' + (pos.z) + 'px)' : 'translate(' + (pos.x) + 'px,' + (pos.y) + 'px)'; es.webkittransform = es.mstransform = es.mstransform = es.moztransform = es.otransform = es.transform = transformstring; if (!this.support.transforms) { es.left = pos.x + 'px'; es.top = pos.y + 'px'; } }, settransition : function (el, duration) { 'use strict'; var es = el.style; es.webkittransitionduration = es.mstransitionduration = es.mstransitionduration = es.moztransitionduration = es.otransitionduration = es.transitionduration = duration + 'ms'; }, /*================================================== feature detection ====================================================*/ support: { touch : (window.modernizr && modernizr.touch === true) || (function () { 'use strict'; return !!(('ontouchstart' in window) || window.documenttouch && document instanceof documenttouch); })(), transforms3d : (window.modernizr && modernizr.csstransforms3d === true) || (function () { 'use strict'; var div = document.createelement('div').style; return ('webkitperspective' in div || 'mozperspective' in div || 'operspective' in div || 'msperspective' in div || 'perspective' in div); })(), transforms : (window.modernizr && modernizr.csstransforms === true) || (function () { 'use strict'; var div = document.createelement('div').style; return ('transform' in div || 'webkittransform' in div || 'moztransform' in div || 'mstransform' in div || 'mstransform' in div || 'otransform' in div); })(), transitions : (window.modernizr && modernizr.csstransitions === true) || (function () { 'use strict'; var div = document.createelement('div').style; return ('transition' in div || 'webkittransition' in div || 'moztransition' in div || 'mstransition' in div || 'mstransition' in div || 'otransition' in div); })(), classlist : (function () { 'use strict'; var div = document.createelement('div'); return 'classlist' in div; })() }, browser : { ie8 : (function () { 'use strict'; var rv = -1; // return value assumes failure. if (navigator.appname === 'microsoft internet explorer') { var ua = navigator.useragent; var re = new regexp(/msie ([0-9]{1,}[\.0-9]{0,})/); if (re.exec(ua) !== null) rv = parsefloat(regexp.$1); } return rv !== -1 && rv < 9; })(), ie10 : window.navigator.mspointerenabled, ie11 : window.navigator.pointerenabled } }; /*========================= jquery & zepto plugins ===========================*/ if (window.jquery || window.zepto) { (function ($) { 'use strict'; $.fn.swiper = function (params) { var firstinstance; this.each(function (i) { var that = $(this); var s = new swiper(that[0], params); if (!i) firstinstance = s; that.data('swiper', s); }); return firstinstance; }; })(window.jquery || window.zepto); } // component if (typeof(module) !== 'undefined') { module.exports = swiper; } // requirejs support if (typeof define === 'function' && define.amd) { define([], function () { 'use strict'; return swiper; }); }