swiper-rails 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NmQxOGUzZDQyNTk2MzM4YTlkNjc1MTVlYjgyNWU2NTYyMzM1NzM2YQ==
5
- data.tar.gz: !binary |-
6
- OTRlNDBkZWU3MTJmZGI5NWRkNzIwZjQwZmY1NWVlNjA1YTVkYWFkZg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZTM3MjBmZDU1NmMxMWU0YmJmN2MxYTY5NmVlNjk0NWFhNTg1NzNiNjE0Yjg4
10
- Y2NkYTYxZDhmY2NmMjAxMGNkZTdlNWY4NDNjNTYwMGVkNDg5OWZjYTAwNzdi
11
- ZTQ0M2Y0YWU0NWZmMWYyN2E5MjY1ODFhY2UyOTU4NzFlYzQwOTY=
12
- data.tar.gz: !binary |-
13
- ODE4NTI1NDFhNTlmMDFhYjc5NzZjMzBkYzM5ZDIyNDM2ZmQ3ZTQwNzkzMzgw
14
- NDlmODZjOTk5OWU5MzgwMDlkYmMxOGUwNWZhMGE0Y2RhMWY4ZDhkMjEzOGQ2
15
- ODAxMWUyZjI1MmMzZWQ3Y2UzNWNjNTJkZmU5ZWUwMTdmOWU5Mjg=
2
+ SHA1:
3
+ metadata.gz: 118b7afde4a47cdf56fe73bf7bd2f2108f75fc21
4
+ data.tar.gz: f2176db71cecf8cc3af76b271c5a0b74b8e50a34
5
+ SHA512:
6
+ metadata.gz: 15f36c4e178419f0bb92aebe0d1b9f786b2684d542f6fb593742012ee8923ca70b5a517bd2a1988399dfa3be4571fb20ca10f14037fe91ec2bd69b274a91f443
7
+ data.tar.gz: 4bcc75a38564af8f5e1cadd6cec194a090a926e78fc2c03c00b66408e8a9d92191ef98b67539246727d0756134be487b6081239ab0c0ff97e678e2fb1300856d
@@ -1,16 +1,6 @@
1
- /*
2
- * Swiper 2.1 - Mobile Touch Slider
3
- * http://www.idangero.us/sliders/swiper/
4
- *
5
- * Copyright 2012-2013, Vladimir Kharlampidi
6
- * The iDangero.us
7
- * http://www.idangero.us/
8
- *
9
- * Licensed under GPL & MIT
10
- *
11
- * Updated on: August 22, 2013
12
- */
13
1
  var Swiper = function (selector, params) {
2
+ 'use strict';
3
+
14
4
  /*=========================
15
5
  A little bit dirty but required part for IE8 and old FF support
16
6
  ===========================*/
@@ -18,7 +8,7 @@ var Swiper = function (selector, params) {
18
8
  if (HTMLElement) {
19
9
  var element = HTMLElement.prototype;
20
10
  if (element.__defineGetter__) {
21
- element.__defineGetter__("outerHTML", function () { return new XMLSerializer().serializeToString(this); } );
11
+ element.__defineGetter__('outerHTML', function () { return new XMLSerializer().serializeToString(this); });
22
12
  }
23
13
  }
24
14
  }
@@ -35,34 +25,34 @@ var Swiper = function (selector, params) {
35
25
  });
36
26
  }
37
27
  return el.currentStyle[prop] ? el.currentStyle[prop] : null;
38
- }
28
+ };
39
29
  return this;
40
- }
30
+ };
41
31
  }
42
32
  if (!Array.prototype.indexOf) {
43
- Array.prototype.indexOf = function(obj, start) {
33
+ Array.prototype.indexOf = function (obj, start) {
44
34
  for (var i = (start || 0), j = this.length; i < j; i++) {
45
35
  if (this[i] === obj) { return i; }
46
36
  }
47
37
  return -1;
48
- }
38
+ };
49
39
  }
50
40
  if (!document.querySelectorAll) {
51
41
  if (!window.jQuery) return;
52
42
  }
53
- function $$(s) {
43
+ function $$(selector, context) {
54
44
  if (document.querySelectorAll)
55
- return document.querySelectorAll(s);
45
+ return (context || document).querySelectorAll(selector);
56
46
  else
57
- return jQuery(s);
47
+ return jQuery(selector, context);
58
48
  }
59
49
 
60
50
  /*=========================
61
51
  Check for correct selector
62
52
  ===========================*/
63
- if(typeof selector === 'undefined') return;
53
+ if (typeof selector === 'undefined') return;
64
54
 
65
- if(!(selector.nodeType)){
55
+ if (!(selector.nodeType)) {
66
56
  if ($$(selector).length === 0) return;
67
57
  }
68
58
 
@@ -75,24 +65,24 @@ var Swiper = function (selector, params) {
75
65
  Default Flags and vars
76
66
  ===========================*/
77
67
  _this.touches = {
78
- start:0,
79
- startX:0,
80
- startY:0,
81
- current:0,
82
- currentX:0,
83
- currentY:0,
84
- diff:0,
85
- abs:0
68
+ start: 0,
69
+ startX: 0,
70
+ startY: 0,
71
+ current: 0,
72
+ currentX: 0,
73
+ currentY: 0,
74
+ diff: 0,
75
+ abs: 0
86
76
  };
87
77
  _this.positions = {
88
- start:0,
89
- abs:0,
90
- diff:0,
91
- current:0
78
+ start: 0,
79
+ abs: 0,
80
+ diff: 0,
81
+ current: 0
92
82
  };
93
83
  _this.times = {
94
- start:0,
95
- end:0
84
+ start: 0,
85
+ end: 0
96
86
  };
97
87
 
98
88
  _this.id = (new Date()).getTime();
@@ -100,6 +90,7 @@ var Swiper = function (selector, params) {
100
90
  _this.isTouched = false;
101
91
  _this.isMoved = false;
102
92
  _this.activeIndex = 0;
93
+ _this.centerIndex = 0;
103
94
  _this.activeLoaderIndex = 0;
104
95
  _this.activeLoopIndex = 0;
105
96
  _this.previousIndex = null;
@@ -108,16 +99,18 @@ var Swiper = function (selector, params) {
108
99
  _this.slidesGrid = [];
109
100
  _this.imagesToLoad = [];
110
101
  _this.imagesLoaded = 0;
111
- _this.wrapperLeft=0;
112
- _this.wrapperRight=0;
113
- _this.wrapperTop=0;
114
- _this.wrapperBottom=0;
102
+ _this.wrapperLeft = 0;
103
+ _this.wrapperRight = 0;
104
+ _this.wrapperTop = 0;
105
+ _this.wrapperBottom = 0;
106
+ _this.isAndroid = navigator.userAgent.toLowerCase().indexOf('android') >= 0;
115
107
  var wrapper, slideSize, wrapperSize, direction, isScrolling, containerSize;
116
108
 
117
109
  /*=========================
118
110
  Default Parameters
119
111
  ===========================*/
120
112
  var defaults = {
113
+ eventTarget: 'wrapper', // or 'container'
121
114
  mode : 'horizontal', // or 'vertical'
122
115
  touchRatio : 1,
123
116
  speed : 300,
@@ -128,11 +121,12 @@ var Swiper = function (selector, params) {
128
121
  momentumBounceRatio: 1,
129
122
  slidesPerView : 1,
130
123
  slidesPerGroup : 1,
124
+ slidesPerViewFit: true, //Fit to slide when spv "auto" and slides larger than container
131
125
  simulateTouch : true,
132
126
  followFinger : true,
133
127
  shortSwipes : true,
134
- moveStartThreshold:false,
135
- autoplay: false,
128
+ longSwipesRatio: 0.5,
129
+ moveStartThreshold: false,
136
130
  onlyExternal : false,
137
131
  createPagination : true,
138
132
  pagination : false,
@@ -142,18 +136,24 @@ var Swiper = function (selector, params) {
142
136
  resistance : true, // or false or 100%
143
137
  scrollContainer : false,
144
138
  preventLinks : true,
139
+ preventLinksPropagation: false,
145
140
  noSwiping : false, // or class
146
141
  noSwipingClass : 'swiper-no-swiping', //:)
147
142
  initialSlide: 0,
148
143
  keyboardControl: false,
149
144
  mousewheelControl : false,
150
- mousewheelDebounce: 600,
145
+ mousewheelControlForceToAxis : false,
151
146
  useCSS3Transforms : true,
147
+ // Autoplay
148
+ autoplay: false,
149
+ autoplayDisableOnInteraction: true,
150
+ autoplayStopOnLast: false,
152
151
  //Loop mode
153
- loop:false,
154
- loopAdditionalSlides:0,
152
+ loop: false,
153
+ loopAdditionalSlides: 0,
155
154
  //Auto Height
156
155
  calculateHeight: false,
156
+ cssWidthAndHeight: false,
157
157
  //Images Preloader
158
158
  updateOnImagesReady : true,
159
159
  //Form elements
@@ -178,25 +178,26 @@ var Swiper = function (selector, params) {
178
178
  DOMAnimation : true,
179
179
  //Slides Loader
180
180
  loader: {
181
- slides:[], //array with slides
182
- slidesHTMLType:'inner', // or 'outer'
181
+ slides: [], //array with slides
182
+ slidesHTMLType: 'inner', // or 'outer'
183
183
  surroundGroups: 1, //keep preloaded slides groups around view
184
184
  logic: 'reload', //or 'change'
185
185
  loadAllSlides: false
186
186
  },
187
187
  //Namespace
188
- slideElement : 'div',
189
- slideClass : 'swiper-slide',
190
- slideActiveClass : 'swiper-slide-active',
191
- slideVisibleClass : 'swiper-slide-visible',
192
- wrapperClass : 'swiper-wrapper',
188
+ slideElement: 'div',
189
+ slideClass: 'swiper-slide',
190
+ slideActiveClass: 'swiper-slide-active',
191
+ slideVisibleClass: 'swiper-slide-visible',
192
+ slideDuplicateClass: 'swiper-slide-duplicate',
193
+ wrapperClass: 'swiper-wrapper',
193
194
  paginationElementClass: 'swiper-pagination-switch',
194
- paginationActiveClass : 'swiper-active-switch',
195
- paginationVisibleClass : 'swiper-visible-switch'
196
- }
195
+ paginationActiveClass: 'swiper-active-switch',
196
+ paginationVisibleClass: 'swiper-visible-switch'
197
+ };
197
198
  params = params || {};
198
199
  for (var prop in defaults) {
199
- if (prop in params && typeof params[prop]==='object') {
200
+ if (prop in params && typeof params[prop] === 'object') {
200
201
  for (var subProp in defaults[prop]) {
201
202
  if (! (subProp in params[prop])) {
202
203
  params[prop][subProp] = defaults[prop][subProp];
@@ -204,7 +205,7 @@ var Swiper = function (selector, params) {
204
205
  }
205
206
  }
206
207
  else if (! (prop in params)) {
207
- params[prop] = defaults[prop]
208
+ params[prop] = defaults[prop];
208
209
  }
209
210
  }
210
211
  _this.params = params;
@@ -215,16 +216,19 @@ var Swiper = function (selector, params) {
215
216
  if (params.loop) {
216
217
  params.resistance = '100%';
217
218
  }
218
- var isH = params.mode==='horizontal';
219
+ var isH = params.mode === 'horizontal';
219
220
 
220
221
  /*=========================
221
222
  Define Touch Events
222
223
  ===========================*/
224
+ var desktopEvents = ['mousedown', 'mousemove', 'mouseup'];
225
+ if (_this.browser.ie10) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp'];
226
+ if (_this.browser.ie11) desktopEvents = ['pointerdown', 'pointermove', 'pointerup'];
223
227
 
224
228
  _this.touchEvents = {
225
- touchStart : _this.support.touch || !params.simulateTouch ? 'touchstart' : (_this.browser.ie10 ? 'MSPointerDown' : 'mousedown'),
226
- touchMove : _this.support.touch || !params.simulateTouch ? 'touchmove' : (_this.browser.ie10 ? 'MSPointerMove' : 'mousemove'),
227
- touchEnd : _this.support.touch || !params.simulateTouch ? 'touchend' : (_this.browser.ie10 ? 'MSPointerUp' : 'mouseup')
229
+ touchStart : _this.support.touch || !params.simulateTouch ? 'touchstart' : desktopEvents[0],
230
+ touchMove : _this.support.touch || !params.simulateTouch ? 'touchmove' : desktopEvents[1],
231
+ touchEnd : _this.support.touch || !params.simulateTouch ? 'touchend' : desktopEvents[2]
228
232
  };
229
233
 
230
234
  /*=========================
@@ -232,14 +236,14 @@ var Swiper = function (selector, params) {
232
236
  ===========================*/
233
237
  for (var i = _this.container.childNodes.length - 1; i >= 0; i--) {
234
238
  if (_this.container.childNodes[i].className) {
235
- var _wrapperClasses = _this.container.childNodes[i].className.split(' ')
239
+ var _wrapperClasses = _this.container.childNodes[i].className.split(/\s+/);
236
240
  for (var j = 0; j < _wrapperClasses.length; j++) {
237
- if (_wrapperClasses[j]===params.wrapperClass) {
241
+ if (_wrapperClasses[j] === params.wrapperClass) {
238
242
  wrapper = _this.container.childNodes[i];
239
243
  }
240
- };
244
+ }
241
245
  }
242
- };
246
+ }
243
247
 
244
248
  _this.wrapper = wrapper;
245
249
  /*=========================
@@ -248,18 +252,15 @@ var Swiper = function (selector, params) {
248
252
  _this._extendSwiperSlide = function (el) {
249
253
  el.append = function () {
250
254
  if (params.loop) {
251
- el.insertAfter(_this.slides.length-_this.loopedSlides);
252
- _this.removeLoopedSlides();
253
- _this.calcSlides();
254
- _this.createLoop();
255
+ el.insertAfter(_this.slides.length - _this.loopedSlides);
255
256
  }
256
257
  else {
257
258
  _this.wrapper.appendChild(el);
259
+ _this.reInit();
258
260
  }
259
261
 
260
- _this.reInit();
261
262
  return el;
262
- }
263
+ };
263
264
  el.prepend = function () {
264
265
  if (params.loop) {
265
266
  _this.wrapper.insertBefore(el, _this.slides[_this.loopedSlides]);
@@ -272,32 +273,37 @@ var Swiper = function (selector, params) {
272
273
  }
273
274
  _this.reInit();
274
275
  return el;
275
- }
276
+ };
276
277
  el.insertAfter = function (index) {
277
- if(typeof index === 'undefined') return false;
278
+ if (typeof index === 'undefined') return false;
278
279
  var beforeSlide;
279
280
 
280
281
  if (params.loop) {
281
282
  beforeSlide = _this.slides[index + 1 + _this.loopedSlides];
282
- _this.wrapper.insertBefore(el, beforeSlide);
283
+ if (beforeSlide) {
284
+ _this.wrapper.insertBefore(el, beforeSlide);
285
+ }
286
+ else {
287
+ _this.wrapper.appendChild(el);
288
+ }
283
289
  _this.removeLoopedSlides();
284
290
  _this.calcSlides();
285
291
  _this.createLoop();
286
292
  }
287
293
  else {
288
294
  beforeSlide = _this.slides[index + 1];
289
- _this.wrapper.insertBefore(el, beforeSlide)
295
+ _this.wrapper.insertBefore(el, beforeSlide);
290
296
  }
291
297
  _this.reInit();
292
298
  return el;
293
- }
299
+ };
294
300
  el.clone = function () {
295
- return _this._extendSwiperSlide(el.cloneNode(true))
296
- }
301
+ return _this._extendSwiperSlide(el.cloneNode(true));
302
+ };
297
303
  el.remove = function () {
298
304
  _this.wrapper.removeChild(el);
299
305
  _this.reInit();
300
- }
306
+ };
301
307
  el.html = function (html) {
302
308
  if (typeof html === 'undefined') {
303
309
  return el.innerHTML;
@@ -306,46 +312,46 @@ var Swiper = function (selector, params) {
306
312
  el.innerHTML = html;
307
313
  return el;
308
314
  }
309
- }
315
+ };
310
316
  el.index = function () {
311
317
  var index;
312
318
  for (var i = _this.slides.length - 1; i >= 0; i--) {
313
- if(el === _this.slides[i]) index = i;
319
+ if (el === _this.slides[i]) index = i;
314
320
  }
315
321
  return index;
316
- }
322
+ };
317
323
  el.isActive = function () {
318
324
  if (el.index() === _this.activeIndex) return true;
319
325
  else return false;
320
- }
321
- if (!el.swiperSlideDataStorage) el.swiperSlideDataStorage={};
326
+ };
327
+ if (!el.swiperSlideDataStorage) el.swiperSlideDataStorage = {};
322
328
  el.getData = function (name) {
323
329
  return el.swiperSlideDataStorage[name];
324
- }
330
+ };
325
331
  el.setData = function (name, value) {
326
332
  el.swiperSlideDataStorage[name] = value;
327
333
  return el;
328
- }
334
+ };
329
335
  el.data = function (name, value) {
330
- if (!value) {
331
- return el.getAttribute('data-'+name);
336
+ if (typeof value === 'undefined') {
337
+ return el.getAttribute('data-' + name);
332
338
  }
333
339
  else {
334
- el.setAttribute('data-'+name,value);
340
+ el.setAttribute('data-' + name, value);
335
341
  return el;
336
342
  }
337
- }
343
+ };
338
344
  el.getWidth = function (outer) {
339
345
  return _this.h.getWidth(el, outer);
340
- }
346
+ };
341
347
  el.getHeight = function (outer) {
342
348
  return _this.h.getHeight(el, outer);
343
- }
344
- el.getOffset = function() {
349
+ };
350
+ el.getOffset = function () {
345
351
  return _this.h.getOffset(el);
346
- }
352
+ };
347
353
  return el;
348
- }
354
+ };
349
355
 
350
356
  //Calculate information about number of slides
351
357
  _this.calcSlides = function (forceCalcSlides) {
@@ -355,9 +361,9 @@ var Swiper = function (selector, params) {
355
361
  for (var i = 0; i < _this.wrapper.childNodes.length; i++) {
356
362
  if (_this.wrapper.childNodes[i].className) {
357
363
  var _className = _this.wrapper.childNodes[i].className;
358
- var _slideClasses = _className.split(' ');
364
+ var _slideClasses = _className.split(/\s+/);
359
365
  for (var j = 0; j < _slideClasses.length; j++) {
360
- if(_slideClasses[j]===params.slideClass) {
366
+ if (_slideClasses[j] === params.slideClass) {
361
367
  _this.slides.push(_this.wrapper.childNodes[i]);
362
368
  }
363
369
  }
@@ -366,46 +372,47 @@ var Swiper = function (selector, params) {
366
372
  for (i = _this.slides.length - 1; i >= 0; i--) {
367
373
  _this._extendSwiperSlide(_this.slides[i]);
368
374
  }
369
- if (!oldNumber) return;
370
- if(oldNumber!==_this.slides.length || forceCalcSlides) {
375
+ if (oldNumber === false) return;
376
+ if (oldNumber !== _this.slides.length || forceCalcSlides) {
377
+
371
378
  // Number of slides has been changed
372
379
  removeSlideEvents();
373
380
  addSlideEvents();
374
381
  _this.updateActiveSlide();
375
- if (params.createPagination && _this.params.pagination) _this.createPagination();
382
+ if (_this.params.pagination) _this.createPagination();
376
383
  _this.callPlugins('numberOfSlidesChanged');
377
384
  }
378
- }
385
+ };
379
386
 
380
387
  //Create Slide
381
388
  _this.createSlide = function (html, slideClassList, el) {
382
- var slideClassList = slideClassList || _this.params.slideClass;
383
- var el = el||params.slideElement;
389
+ slideClassList = slideClassList || _this.params.slideClass;
390
+ el = el || params.slideElement;
384
391
  var newSlide = document.createElement(el);
385
- newSlide.innerHTML = html||'';
392
+ newSlide.innerHTML = html || '';
386
393
  newSlide.className = slideClassList;
387
394
  return _this._extendSwiperSlide(newSlide);
388
- }
395
+ };
389
396
 
390
397
  //Append Slide
391
398
  _this.appendSlide = function (html, slideClassList, el) {
392
399
  if (!html) return;
393
400
  if (html.nodeType) {
394
- return _this._extendSwiperSlide(html).append()
401
+ return _this._extendSwiperSlide(html).append();
395
402
  }
396
403
  else {
397
- return _this.createSlide(html, slideClassList, el).append()
404
+ return _this.createSlide(html, slideClassList, el).append();
398
405
  }
399
- }
406
+ };
400
407
  _this.prependSlide = function (html, slideClassList, el) {
401
408
  if (!html) return;
402
409
  if (html.nodeType) {
403
- return _this._extendSwiperSlide(html).prepend()
410
+ return _this._extendSwiperSlide(html).prepend();
404
411
  }
405
412
  else {
406
- return _this.createSlide(html, slideClassList, el).prepend()
413
+ return _this.createSlide(html, slideClassList, el).prepend();
407
414
  }
408
- }
415
+ };
409
416
  _this.insertSlideAfter = function (index, html, slideClassList, el) {
410
417
  if (typeof index === 'undefined') return false;
411
418
  if (html.nodeType) {
@@ -414,12 +421,12 @@ var Swiper = function (selector, params) {
414
421
  else {
415
422
  return _this.createSlide(html, slideClassList, el).insertAfter(index);
416
423
  }
417
- }
424
+ };
418
425
  _this.removeSlide = function (index) {
419
426
  if (_this.slides[index]) {
420
427
  if (params.loop) {
421
- if (!_this.slides[index+_this.loopedSlides]) return false;
422
- _this.slides[index+_this.loopedSlides].remove();
428
+ if (!_this.slides[index + _this.loopedSlides]) return false;
429
+ _this.slides[index + _this.loopedSlides].remove();
423
430
  _this.removeLoopedSlides();
424
431
  _this.calcSlides();
425
432
  _this.createLoop();
@@ -428,42 +435,92 @@ var Swiper = function (selector, params) {
428
435
  return true;
429
436
  }
430
437
  else return false;
431
- }
438
+ };
432
439
  _this.removeLastSlide = function () {
433
- if (_this.slides.length>0) {
440
+ if (_this.slides.length > 0) {
434
441
  if (params.loop) {
435
442
  _this.slides[_this.slides.length - 1 - _this.loopedSlides].remove();
436
443
  _this.removeLoopedSlides();
437
444
  _this.calcSlides();
438
445
  _this.createLoop();
439
446
  }
440
- else _this.slides[ (_this.slides.length-1) ].remove();
447
+ else _this.slides[_this.slides.length - 1].remove();
441
448
  return true;
442
449
  }
443
450
  else {
444
451
  return false;
445
452
  }
446
- }
453
+ };
447
454
  _this.removeAllSlides = function () {
448
455
  for (var i = _this.slides.length - 1; i >= 0; i--) {
449
- _this.slides[i].remove()
456
+ _this.slides[i].remove();
450
457
  }
451
- }
458
+ };
452
459
  _this.getSlide = function (index) {
453
- return _this.slides[index]
454
- }
460
+ return _this.slides[index];
461
+ };
455
462
  _this.getLastSlide = function () {
456
- return _this.slides[ _this.slides.length-1 ]
457
- }
463
+ return _this.slides[_this.slides.length - 1];
464
+ };
458
465
  _this.getFirstSlide = function () {
459
- return _this.slides[0]
460
- }
466
+ return _this.slides[0];
467
+ };
461
468
 
462
469
  //Currently Active Slide
463
470
  _this.activeSlide = function () {
464
- return _this.slides[_this.activeIndex]
471
+ return _this.slides[_this.activeIndex];
472
+ };
473
+
474
+ /*=========================
475
+ Wrapper for Callbacks : Allows additive callbacks via function arrays
476
+ ===========================*/
477
+ _this.fireCallback = function () {
478
+ var callback = arguments[0];
479
+ if (Object.prototype.toString.call(callback) === '[object Array]') {
480
+ for (var i = 0; i < callback.length; i++) {
481
+ if (typeof callback[i] === 'function') {
482
+ callback[i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
483
+ }
484
+ }
485
+ } else if (Object.prototype.toString.call(callback) === '[object String]') {
486
+ if (params['on' + callback]) _this.fireCallback(params['on' + callback]);
487
+ } else {
488
+ callback(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
489
+ }
490
+ };
491
+ function isArray(obj) {
492
+ if (Object.prototype.toString.apply(obj) === '[object Array]') return true;
493
+ return false;
465
494
  }
466
495
 
496
+ /**
497
+ * Allows user to add callbacks, rather than replace them
498
+ * @param callback
499
+ * @param func
500
+ * @return {*}
501
+ */
502
+ _this.addCallback = function (callback, func) {
503
+ var _this = this, tempFunc;
504
+ if (_this.params['on' + callback]) {
505
+ if (isArray(this.params['on' + callback])) {
506
+ return this.params['on' + callback].push(func);
507
+ } else if (typeof this.params['on' + callback] === 'function') {
508
+ tempFunc = this.params['on' + callback];
509
+ this.params['on' + callback] = [];
510
+ this.params['on' + callback].push(tempFunc);
511
+ return this.params['on' + callback].push(func);
512
+ }
513
+ } else {
514
+ this.params['on' + callback] = [];
515
+ return this.params['on' + callback].push(func);
516
+ }
517
+ };
518
+ _this.removeCallbacks = function (callback) {
519
+ if (_this.params['on' + callback]) {
520
+ _this.params['on' + callback] = null;
521
+ }
522
+ };
523
+
467
524
  /*=========================
468
525
  Plugins API
469
526
  ===========================*/
@@ -471,44 +528,46 @@ var Swiper = function (selector, params) {
471
528
  for (var plugin in _this.plugins) {
472
529
  if (params[plugin]) {
473
530
  var p = _this.plugins[plugin](_this, params[plugin]);
474
- if (p) _plugins.push( p );
531
+ if (p) _plugins.push(p);
475
532
  }
476
533
  }
477
- _this.callPlugins = function(method, args) {
478
- if (!args) args = {}
479
- for (var i=0; i<_plugins.length; i++) {
534
+ _this.callPlugins = function (method, args) {
535
+ if (!args) args = {};
536
+ for (var i = 0; i < _plugins.length; i++) {
480
537
  if (method in _plugins[i]) {
481
538
  _plugins[i][method](args);
482
539
  }
483
540
  }
484
- }
541
+ };
485
542
 
486
543
  /*=========================
487
- WP8 Fix
544
+ Windows Phone 8 Fix
488
545
  ===========================*/
489
- if (_this.browser.ie10 && !params.onlyExternal) {
490
- if (isH) _this.wrapper.classList.add('swiper-wp8-horizontal');
491
- else _this.wrapper.classList.add('swiper-wp8-vertical');
546
+ if ((_this.browser.ie10 || _this.browser.ie11) && !params.onlyExternal) {
547
+ _this.wrapper.classList.add('swiper-wp8-' + (isH ? 'horizontal' : 'vertical'));
492
548
  }
493
549
 
494
550
  /*=========================
495
551
  Free Mode Class
496
552
  ===========================*/
497
553
  if (params.freeMode) {
498
- _this.container.className+=' swiper-free-mode';
554
+ _this.container.className += ' swiper-free-mode';
499
555
  }
500
556
 
501
557
  /*==================================================
502
558
  Init/Re-init/Resize Fix
503
559
  ====================================================*/
504
560
  _this.initialized = false;
505
- _this.init = function(force, forceCalcSlides) {
561
+ _this.init = function (force, forceCalcSlides) {
506
562
  var _width = _this.h.getWidth(_this.container);
507
563
  var _height = _this.h.getHeight(_this.container);
508
- if (_width===_this.width && _height===_this.height && !force) return;
564
+ if (_width === _this.width && _height === _this.height && !force) return;
565
+
509
566
  _this.width = _width;
510
567
  _this.height = _height;
511
568
 
569
+ var slideWidth, slideHeight, slideMaxHeight, wrapperWidth, wrapperHeight, slideLeft;
570
+ var i; // loop index variable to avoid JSHint W004 / W038
512
571
  containerSize = isH ? _width : _height;
513
572
  var wrapper = _this.wrapper;
514
573
 
@@ -516,13 +575,13 @@ var Swiper = function (selector, params) {
516
575
  _this.calcSlides(forceCalcSlides);
517
576
  }
518
577
 
519
- if (params.slidesPerView==='auto') {
578
+ if (params.slidesPerView === 'auto') {
520
579
  //Auto mode
521
580
  var slidesWidth = 0;
522
581
  var slidesHeight = 0;
523
582
 
524
583
  //Unset Styles
525
- if (params.slidesOffset>0) {
584
+ if (params.slidesOffset > 0) {
526
585
  wrapper.style.paddingLeft = '';
527
586
  wrapper.style.paddingRight = '';
528
587
  wrapper.style.paddingTop = '';
@@ -530,71 +589,87 @@ var Swiper = function (selector, params) {
530
589
  }
531
590
  wrapper.style.width = '';
532
591
  wrapper.style.height = '';
533
- if (params.offsetPxBefore>0) {
592
+ if (params.offsetPxBefore > 0) {
534
593
  if (isH) _this.wrapperLeft = params.offsetPxBefore;
535
594
  else _this.wrapperTop = params.offsetPxBefore;
536
595
  }
537
- if (params.offsetPxAfter>0) {
596
+ if (params.offsetPxAfter > 0) {
538
597
  if (isH) _this.wrapperRight = params.offsetPxAfter;
539
598
  else _this.wrapperBottom = params.offsetPxAfter;
540
599
  }
541
600
 
542
601
  if (params.centeredSlides) {
543
602
  if (isH) {
544
- _this.wrapperLeft = (containerSize - this.slides[0].getWidth(true) )/2;
545
- _this.wrapperRight = (containerSize - _this.slides[ _this.slides.length-1 ].getWidth(true))/2;
603
+ _this.wrapperLeft = (containerSize - this.slides[0].getWidth(true)) / 2;
604
+ _this.wrapperRight = (containerSize - _this.slides[_this.slides.length - 1].getWidth(true)) / 2;
546
605
  }
547
606
  else {
548
- _this.wrapperTop = (containerSize - _this.slides[0].getHeight(true))/2;
549
- _this.wrapperBottom = (containerSize - _this.slides[ _this.slides.length-1 ].getHeight(true))/2;
607
+ _this.wrapperTop = (containerSize - _this.slides[0].getHeight(true)) / 2;
608
+ _this.wrapperBottom = (containerSize - _this.slides[_this.slides.length - 1].getHeight(true)) / 2;
550
609
  }
551
610
  }
552
611
 
553
612
  if (isH) {
554
- if (_this.wrapperLeft>=0) wrapper.style.paddingLeft = _this.wrapperLeft+'px';
555
- if (_this.wrapperRight>=0) wrapper.style.paddingRight = _this.wrapperRight+'px';
613
+ if (_this.wrapperLeft >= 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px';
614
+ if (_this.wrapperRight >= 0) wrapper.style.paddingRight = _this.wrapperRight + 'px';
556
615
  }
557
616
  else {
558
- if (_this.wrapperTop>=0) wrapper.style.paddingTop = _this.wrapperTop+'px';
559
- if (_this.wrapperBottom>=0) wrapper.style.paddingBottom = _this.wrapperBottom+'px';
617
+ if (_this.wrapperTop >= 0) wrapper.style.paddingTop = _this.wrapperTop + 'px';
618
+ if (_this.wrapperBottom >= 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px';
560
619
  }
561
- var slideLeft = 0;
562
- var centeredSlideLeft=0;
620
+ slideLeft = 0;
621
+ var centeredSlideLeft = 0;
563
622
  _this.snapGrid = [];
564
623
  _this.slidesGrid = [];
565
624
 
566
- var slideMaxHeight = 0;
567
- for(var i = 0; i<_this.slides.length; i++) {
568
- var slideWidth = _this.slides[i].getWidth(true);
569
- var slideHeight = _this.slides[i].getHeight(true);
625
+ slideMaxHeight = 0;
626
+ for (i = 0; i < _this.slides.length; i++) {
627
+ slideWidth = _this.slides[i].getWidth(true);
628
+ slideHeight = _this.slides[i].getHeight(true);
570
629
  if (params.calculateHeight) {
571
- slideMaxHeight = Math.max(slideMaxHeight, slideHeight)
630
+ slideMaxHeight = Math.max(slideMaxHeight, slideHeight);
572
631
  }
573
632
  var _slideSize = isH ? slideWidth : slideHeight;
574
633
  if (params.centeredSlides) {
575
- var nextSlideWidth = i === _this.slides.length-1 ? 0 : _this.slides[i+1].getWidth(true);
576
- var nextSlideHeight = i === _this.slides.length-1 ? 0 : _this.slides[i+1].getHeight(true);
634
+ var nextSlideWidth = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getWidth(true);
635
+ var nextSlideHeight = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getHeight(true);
577
636
  var nextSlideSize = isH ? nextSlideWidth : nextSlideHeight;
578
- if (_slideSize>containerSize) {
579
- for (var j=0; j<=Math.floor(_slideSize/(containerSize+_this.wrapperLeft)); j++) {
580
- if (j === 0) _this.snapGrid.push(slideLeft+_this.wrapperLeft);
581
- else _this.snapGrid.push(slideLeft+_this.wrapperLeft+containerSize*j);
637
+ if (_slideSize > containerSize) {
638
+ if (params.slidesPerViewFit) {
639
+ _this.snapGrid.push(slideLeft + _this.wrapperLeft);
640
+ _this.snapGrid.push(slideLeft + _slideSize - containerSize + _this.wrapperLeft);
641
+ }
642
+ else {
643
+ for (var j = 0; j <= Math.floor(_slideSize / (containerSize + _this.wrapperLeft)); j++) {
644
+ if (j === 0) _this.snapGrid.push(slideLeft + _this.wrapperLeft);
645
+ else _this.snapGrid.push(slideLeft + _this.wrapperLeft + containerSize * j);
646
+ }
582
647
  }
583
- _this.slidesGrid.push(slideLeft+_this.wrapperLeft);
648
+ _this.slidesGrid.push(slideLeft + _this.wrapperLeft);
584
649
  }
585
650
  else {
586
651
  _this.snapGrid.push(centeredSlideLeft);
587
652
  _this.slidesGrid.push(centeredSlideLeft);
588
653
  }
589
-
590
- centeredSlideLeft += _slideSize/2 + nextSlideSize/2;
591
-
654
+ centeredSlideLeft += _slideSize / 2 + nextSlideSize / 2;
592
655
  }
593
656
  else {
594
- if (_slideSize>containerSize) {
595
- for (var j=0; j<=Math.floor(_slideSize/containerSize); j++) {
596
- _this.snapGrid.push(slideLeft+containerSize*j);
657
+ if (_slideSize > containerSize) {
658
+ if (params.slidesPerViewFit) {
659
+ _this.snapGrid.push(slideLeft);
660
+ _this.snapGrid.push(slideLeft + _slideSize - containerSize);
661
+ }
662
+ else {
663
+ if (containerSize !== 0) {
664
+ for (var k = 0; k <= Math.floor(_slideSize / containerSize); k++) {
665
+ _this.snapGrid.push(slideLeft + containerSize * k);
666
+ }
667
+ }
668
+ else {
669
+ _this.snapGrid.push(slideLeft);
670
+ }
597
671
  }
672
+
598
673
  }
599
674
  else {
600
675
  _this.snapGrid.push(slideLeft);
@@ -608,15 +683,15 @@ var Swiper = function (selector, params) {
608
683
  slidesHeight += slideHeight;
609
684
  }
610
685
  if (params.calculateHeight) _this.height = slideMaxHeight;
611
- if(isH) {
686
+ if (isH) {
612
687
  wrapperSize = slidesWidth + _this.wrapperRight + _this.wrapperLeft;
613
- wrapper.style.width = (slidesWidth)+'px';
614
- wrapper.style.height = (_this.height)+'px';
688
+ wrapper.style.width = (slidesWidth) + 'px';
689
+ wrapper.style.height = (_this.height) + 'px';
615
690
  }
616
691
  else {
617
692
  wrapperSize = slidesHeight + _this.wrapperTop + _this.wrapperBottom;
618
- wrapper.style.width = (_this.width)+'px';
619
- wrapper.style.height = (slidesHeight)+'px';
693
+ wrapper.style.width = (_this.width) + 'px';
694
+ wrapper.style.height = (slidesHeight) + 'px';
620
695
  }
621
696
 
622
697
  }
@@ -624,125 +699,158 @@ var Swiper = function (selector, params) {
624
699
  //Scroll Container
625
700
  wrapper.style.width = '';
626
701
  wrapper.style.height = '';
627
- var wrapperWidth = _this.slides[0].getWidth(true);
628
- var wrapperHeight = _this.slides[0].getHeight(true);
702
+ wrapperWidth = _this.slides[0].getWidth(true);
703
+ wrapperHeight = _this.slides[0].getHeight(true);
629
704
  wrapperSize = isH ? wrapperWidth : wrapperHeight;
630
- wrapper.style.width = wrapperWidth+'px';
631
- wrapper.style.height = wrapperHeight+'px';
705
+ wrapper.style.width = wrapperWidth + 'px';
706
+ wrapper.style.height = wrapperHeight + 'px';
632
707
  slideSize = isH ? wrapperWidth : wrapperHeight;
633
708
 
634
709
  }
635
710
  else {
636
711
  //For usual slides
637
712
  if (params.calculateHeight) {
638
- var slideMaxHeight = 0;
639
- var wrapperHeight = 0;
713
+ slideMaxHeight = 0;
714
+ wrapperHeight = 0;
640
715
  //ResetWrapperSize
641
- if (!isH) _this.container.style.height= '';
642
- wrapper.style.height='';
716
+ if (!isH) _this.container.style.height = '';
717
+ wrapper.style.height = '';
643
718
 
644
- for (var i=0; i<_this.slides.length; i++) {
719
+ for (i = 0; i < _this.slides.length; i++) {
645
720
  //ResetSlideSize
646
- _this.slides[i].style.height='';
647
- slideMaxHeight = Math.max( _this.slides[i].getHeight(true), slideMaxHeight );
648
- if (!isH) wrapperHeight+=_this.slides[i].getHeight(true);
721
+ _this.slides[i].style.height = '';
722
+ slideMaxHeight = Math.max(_this.slides[i].getHeight(true), slideMaxHeight);
723
+ if (!isH) wrapperHeight += _this.slides[i].getHeight(true);
649
724
  }
650
- var slideHeight = slideMaxHeight;
725
+ slideHeight = slideMaxHeight;
651
726
  _this.height = slideHeight;
652
727
 
653
728
  if (isH) wrapperHeight = slideHeight;
654
- else containerSize = slideHeight, _this.container.style.height= containerSize+'px';
729
+ else {
730
+ containerSize = slideHeight;
731
+ _this.container.style.height = containerSize + 'px';
732
+ }
655
733
  }
656
734
  else {
657
- var slideHeight = isH ? _this.height : _this.height/params.slidesPerView ;
658
- var wrapperHeight = isH ? _this.height : _this.slides.length*slideHeight;
735
+ slideHeight = isH ? _this.height : _this.height / params.slidesPerView;
736
+ wrapperHeight = isH ? _this.height : _this.slides.length * slideHeight;
659
737
  }
660
- var slideWidth = isH ? _this.width/params.slidesPerView : _this.width;
661
- var wrapperWidth = isH ? _this.slides.length*slideWidth : _this.width;
738
+ slideWidth = isH ? _this.width / params.slidesPerView : _this.width;
739
+ wrapperWidth = isH ? _this.slides.length * slideWidth : _this.width;
662
740
  slideSize = isH ? slideWidth : slideHeight;
663
741
 
664
- if (params.offsetSlidesBefore>0) {
665
- if (isH) _this.wrapperLeft = slideSize*params.offsetSlidesBefore;
666
- else _this.wrapperTop = slideSize*params.offsetSlidesBefore;
742
+ if (params.offsetSlidesBefore > 0) {
743
+ if (isH) _this.wrapperLeft = slideSize * params.offsetSlidesBefore;
744
+ else _this.wrapperTop = slideSize * params.offsetSlidesBefore;
667
745
  }
668
- if (params.offsetSlidesAfter>0) {
669
- if (isH) _this.wrapperRight = slideSize*params.offsetSlidesAfter;
670
- else _this.wrapperBottom = slideSize*params.offsetSlidesAfter;
746
+ if (params.offsetSlidesAfter > 0) {
747
+ if (isH) _this.wrapperRight = slideSize * params.offsetSlidesAfter;
748
+ else _this.wrapperBottom = slideSize * params.offsetSlidesAfter;
671
749
  }
672
- if (params.offsetPxBefore>0) {
750
+ if (params.offsetPxBefore > 0) {
673
751
  if (isH) _this.wrapperLeft = params.offsetPxBefore;
674
752
  else _this.wrapperTop = params.offsetPxBefore;
675
753
  }
676
- if (params.offsetPxAfter>0) {
754
+ if (params.offsetPxAfter > 0) {
677
755
  if (isH) _this.wrapperRight = params.offsetPxAfter;
678
756
  else _this.wrapperBottom = params.offsetPxAfter;
679
757
  }
680
758
  if (params.centeredSlides) {
681
759
  if (isH) {
682
- _this.wrapperLeft = (containerSize - slideSize)/2;
683
- _this.wrapperRight = (containerSize - slideSize)/2;
760
+ _this.wrapperLeft = (containerSize - slideSize) / 2;
761
+ _this.wrapperRight = (containerSize - slideSize) / 2;
684
762
  }
685
763
  else {
686
- _this.wrapperTop = (containerSize - slideSize)/2;
687
- _this.wrapperBottom = (containerSize - slideSize)/2;
764
+ _this.wrapperTop = (containerSize - slideSize) / 2;
765
+ _this.wrapperBottom = (containerSize - slideSize) / 2;
688
766
  }
689
767
  }
690
768
  if (isH) {
691
- if (_this.wrapperLeft>0) wrapper.style.paddingLeft = _this.wrapperLeft+'px';
692
- if (_this.wrapperRight>0) wrapper.style.paddingRight = _this.wrapperRight+'px';
769
+ if (_this.wrapperLeft > 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px';
770
+ if (_this.wrapperRight > 0) wrapper.style.paddingRight = _this.wrapperRight + 'px';
693
771
  }
694
772
  else {
695
- if (_this.wrapperTop>0) wrapper.style.paddingTop = _this.wrapperTop+'px';
696
- if (_this.wrapperBottom>0) wrapper.style.paddingBottom = _this.wrapperBottom+'px';
773
+ if (_this.wrapperTop > 0) wrapper.style.paddingTop = _this.wrapperTop + 'px';
774
+ if (_this.wrapperBottom > 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px';
697
775
  }
698
776
 
699
777
  wrapperSize = isH ? wrapperWidth + _this.wrapperRight + _this.wrapperLeft : wrapperHeight + _this.wrapperTop + _this.wrapperBottom;
700
- wrapper.style.width = wrapperWidth+'px';
701
- wrapper.style.height = wrapperHeight+'px';
702
- var slideLeft = 0;
778
+ if (!params.cssWidthAndHeight) {
779
+ if (parseFloat(wrapperWidth) > 0) {
780
+ wrapper.style.width = wrapperWidth + 'px';
781
+ }
782
+ if (parseFloat(wrapperHeight) > 0) {
783
+ wrapper.style.height = wrapperHeight + 'px';
784
+ }
785
+ }
786
+ slideLeft = 0;
703
787
  _this.snapGrid = [];
704
788
  _this.slidesGrid = [];
705
- for (var i=0; i<_this.slides.length; i++) {
789
+ for (i = 0; i < _this.slides.length; i++) {
706
790
  _this.snapGrid.push(slideLeft);
707
791
  _this.slidesGrid.push(slideLeft);
708
- slideLeft+=slideSize;
709
- _this.slides[i].style.width = slideWidth+'px';
710
- _this.slides[i].style.height = slideHeight+'px';
792
+ slideLeft += slideSize;
793
+ if (!params.cssWidthAndHeight) {
794
+ if (parseFloat(slideWidth) > 0) {
795
+ _this.slides[i].style.width = slideWidth + 'px';
796
+ }
797
+ if (parseFloat(slideHeight) > 0) {
798
+ _this.slides[i].style.height = slideHeight + 'px';
799
+ }
800
+ }
711
801
  }
712
802
 
713
803
  }
714
804
 
715
805
  if (!_this.initialized) {
716
806
  _this.callPlugins('onFirstInit');
717
- if (params.onFirstInit) params.onFirstInit(_this);
807
+ if (params.onFirstInit) _this.fireCallback(params.onFirstInit, _this);
718
808
  }
719
809
  else {
720
810
  _this.callPlugins('onInit');
721
- if (params.onInit) params.onInit(_this);
811
+ if (params.onInit) _this.fireCallback(params.onInit, _this);
722
812
  }
723
813
  _this.initialized = true;
724
- }
814
+ };
815
+
725
816
  _this.reInit = function (forceCalcSlides) {
726
817
  _this.init(true, forceCalcSlides);
727
- }
728
- _this.resizeFix = function(reInit){
818
+ };
819
+
820
+ _this.resizeFix = function (reInit) {
729
821
  _this.callPlugins('beforeResizeFix');
730
- _this.init(params.resizeReInit||reInit);
822
+
823
+ _this.init(params.resizeReInit || reInit);
824
+
825
+ // swipe to active slide in fixed mode
731
826
  if (!params.freeMode) {
732
- if (params.loop) _this.swipeTo(_this.activeLoopIndex, 0, false);
733
- else _this.swipeTo(_this.activeIndex, 0, false);
734
- }
735
- else {
736
- var pos = isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
737
- if (pos < -maxWrapperPosition()) {
738
- var x = isH ? -maxWrapperPosition() : 0;
739
- var y = isH ? 0 : -maxWrapperPosition();
740
- _this.setWrapperTransition(0);
741
- _this.setWrapperTranslate(x,y,0);
827
+ _this.swipeTo((params.loop ? _this.activeLoopIndex : _this.activeIndex), 0, false);
828
+ // Fix autoplay
829
+ if (params.autoplay) {
830
+ if (_this.support.transitions && typeof autoplayTimeoutId !== 'undefined') {
831
+ if (typeof autoplayTimeoutId !== 'undefined') {
832
+ clearTimeout(autoplayTimeoutId);
833
+ autoplayTimeoutId = undefined;
834
+ _this.startAutoplay();
835
+ }
836
+ }
837
+ else {
838
+ if (typeof autoplayIntervalId !== 'undefined') {
839
+ clearInterval(autoplayIntervalId);
840
+ autoplayIntervalId = undefined;
841
+ _this.startAutoplay();
842
+ }
843
+ }
742
844
  }
743
845
  }
846
+ // move wrapper to the beginning in free mode
847
+ else if (_this.getWrapperTranslate() < -maxWrapperPosition()) {
848
+ _this.setWrapperTransition(0);
849
+ _this.setWrapperTranslate(-maxWrapperPosition());
850
+ }
851
+
744
852
  _this.callPlugins('afterResizeFix');
745
- }
853
+ };
746
854
 
747
855
  /*==========================================
748
856
  Max and Min Positions
@@ -753,13 +861,10 @@ var Swiper = function (selector, params) {
753
861
  a = wrapperSize - containerSize;
754
862
  }
755
863
  // if (params.loop) a -= containerSize;
756
- if (params.slidesPerView > _this.slides.length) a = 0;
757
- if (a<0) a = 0;
758
- return a;
759
- }
760
- function minWrapperPosition() {
761
- var a = 0;
762
- // if (params.loop) a = containerSize;
864
+ if (params.slidesPerView > _this.slides.length && !params.centeredSlides) {
865
+ a = 0;
866
+ }
867
+ if (a < 0) a = 0;
763
868
  return a;
764
869
  }
765
870
 
@@ -767,100 +872,105 @@ var Swiper = function (selector, params) {
767
872
  Event Listeners
768
873
  ============================================*/
769
874
  function initEvents() {
875
+ var bind = _this.h.addEventListener;
876
+ var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container;
770
877
  //Touch Events
771
- if (!_this.browser.ie10) {
878
+ if (! (_this.browser.ie10 || _this.browser.ie11)) {
772
879
  if (_this.support.touch) {
773
- _this.h.addEventListener(_this.wrapper, 'touchstart', onTouchStart, false);
774
- _this.h.addEventListener(_this.wrapper, 'touchmove', onTouchMove, false);
775
- _this.h.addEventListener(_this.wrapper, 'touchend', onTouchEnd, false);
880
+ bind(eventTarget, 'touchstart', onTouchStart);
881
+ bind(eventTarget, 'touchmove', onTouchMove);
882
+ bind(eventTarget, 'touchend', onTouchEnd);
776
883
  }
777
884
  if (params.simulateTouch) {
778
- _this.h.addEventListener(_this.wrapper, 'mousedown', onTouchStart, false);
779
- _this.h.addEventListener(document, 'mousemove', onTouchMove, false);
780
- _this.h.addEventListener(document, 'mouseup', onTouchEnd, false);
885
+ bind(eventTarget, 'mousedown', onTouchStart);
886
+ bind(document, 'mousemove', onTouchMove);
887
+ bind(document, 'mouseup', onTouchEnd);
781
888
  }
782
889
  }
783
890
  else {
784
- _this.h.addEventListener(_this.wrapper, _this.touchEvents.touchStart, onTouchStart, false);
785
- _this.h.addEventListener(document, _this.touchEvents.touchMove, onTouchMove, false);
786
- _this.h.addEventListener(document, _this.touchEvents.touchEnd, onTouchEnd, false);
891
+ bind(eventTarget, _this.touchEvents.touchStart, onTouchStart);
892
+ bind(document, _this.touchEvents.touchMove, onTouchMove);
893
+ bind(document, _this.touchEvents.touchEnd, onTouchEnd);
787
894
  }
895
+
788
896
  //Resize Event
789
897
  if (params.autoResize) {
790
- _this.h.addEventListener(window, 'resize', _this.resizeFix, false);
898
+ bind(window, 'resize', _this.resizeFix);
791
899
  }
792
900
  //Slide Events
793
901
  addSlideEvents();
794
902
  //Mousewheel
795
903
  _this._wheelEvent = false;
796
904
  if (params.mousewheelControl) {
797
- if ( document.onmousewheel !== undefined ) {
798
- _this._wheelEvent = "mousewheel";
905
+ if (document.onmousewheel !== undefined) {
906
+ _this._wheelEvent = 'mousewheel';
799
907
  }
800
908
  try {
801
- WheelEvent("wheel");
802
- _this._wheelEvent = "wheel";
909
+ new WheelEvent('wheel');
910
+ _this._wheelEvent = 'wheel';
803
911
  } catch (e) {}
804
- if ( !_this._wheelEvent ) {
805
- _this._wheelEvent = "DOMMouseScroll";
912
+ if (!_this._wheelEvent) {
913
+ _this._wheelEvent = 'DOMMouseScroll';
806
914
  }
807
915
 
808
916
  if (_this._wheelEvent) {
809
- _this.h.addEventListener(_this.container, _this._wheelEvent, handleMousewheel, false);
917
+ bind(_this.container, _this._wheelEvent, handleMousewheel);
810
918
  }
811
919
  }
812
920
 
813
921
  //Keyboard
814
- if (params.keyboardControl) {
815
- _this.h.addEventListener(document, 'keydown', handleKeyboardKeys, false);
816
- }
817
- if (params.updateOnImagesReady) {
818
- if (document.querySelectorAll) _this.imagesToLoad = _this.container.querySelectorAll('img');
819
- else if (window.jQuery) _this.imagesToLoad = $$(_this.container).find('img');
820
-
821
- for (var i=0; i<_this.imagesToLoad.length; i++) {
822
- _loadImage(_this.imagesToLoad[i].getAttribute('src'))
823
- }
824
- }
825
922
  function _loadImage(src) {
826
923
  var image = new Image();
827
- image.onload = function(){
828
- _this.imagesLoaded++;
829
- if (_this.imagesLoaded==_this.imagesToLoad.length) {
924
+ image.onload = function () {
925
+ if (_this && _this.imagesLoaded) _this.imagesLoaded++;
926
+ if (_this.imagesLoaded === _this.imagesToLoad.length) {
830
927
  _this.reInit();
831
- if (params.onImagesReady) params.onImagesReady(_this);
928
+ if (params.onImagesReady) _this.fireCallback(params.onImagesReady, _this);
832
929
  }
833
- }
930
+ };
834
931
  image.src = src;
835
932
  }
836
- }
837
933
 
934
+ if (params.keyboardControl) {
935
+ bind(document, 'keydown', handleKeyboardKeys);
936
+ }
937
+ if (params.updateOnImagesReady) {
938
+ _this.imagesToLoad = $$('img', _this.container);
838
939
 
940
+ for (var i = 0; i < _this.imagesToLoad.length; i++) {
941
+ _loadImage(_this.imagesToLoad[i].getAttribute('src'));
942
+ }
943
+ }
944
+ }
839
945
 
840
946
  //Remove Event Listeners
841
- _this.destroy = function(removeResizeFix){
947
+ _this.destroy = function () {
948
+ var unbind = _this.h.removeEventListener;
949
+ var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container;
842
950
  //Touch Events
843
- if (!_this.browser.ie10) {
951
+ if (! (_this.browser.ie10 || _this.browser.ie11)) {
844
952
  if (_this.support.touch) {
845
- _this.h.removeEventListener(_this.wrapper, 'touchstart', onTouchStart, false);
846
- _this.h.removeEventListener(_this.wrapper, 'touchmove', onTouchMove, false);
847
- _this.h.removeEventListener(_this.wrapper, 'touchend', onTouchEnd, false);
953
+ unbind(eventTarget, 'touchstart', onTouchStart);
954
+ unbind(eventTarget, 'touchmove', onTouchMove);
955
+ unbind(eventTarget, 'touchend', onTouchEnd);
848
956
  }
849
957
  if (params.simulateTouch) {
850
- _this.h.removeEventListener(_this.wrapper, 'mousedown', onTouchStart, false);
851
- _this.h.removeEventListener(document, 'mousemove', onTouchMove, false);
852
- _this.h.removeEventListener(document, 'mouseup', onTouchEnd, false);
958
+ unbind(eventTarget, 'mousedown', onTouchStart);
959
+ unbind(document, 'mousemove', onTouchMove);
960
+ unbind(document, 'mouseup', onTouchEnd);
853
961
  }
854
962
  }
855
963
  else {
856
- _this.h.removeEventListener(_this.wrapper, _this.touchEvents.touchStart, onTouchStart, false);
857
- _this.h.removeEventListener(document, _this.touchEvents.touchMove, onTouchMove, false);
858
- _this.h.removeEventListener(document, _this.touchEvents.touchEnd, onTouchEnd, false);
964
+ unbind(eventTarget, _this.touchEvents.touchStart, onTouchStart);
965
+ unbind(document, _this.touchEvents.touchMove, onTouchMove);
966
+ unbind(document, _this.touchEvents.touchEnd, onTouchEnd);
859
967
  }
968
+
860
969
  //Resize Event
861
970
  if (params.autoResize) {
862
- _this.h.removeEventListener(window, 'resize', _this.resizeFix, false);
971
+ unbind(window, 'resize', _this.resizeFix);
863
972
  }
973
+
864
974
  //Init Slide Events
865
975
  removeSlideEvents();
866
976
 
@@ -871,12 +981,12 @@ var Swiper = function (selector, params) {
871
981
 
872
982
  //Mousewheel
873
983
  if (params.mousewheelControl && _this._wheelEvent) {
874
- _this.h.removeEventListener(_this.container, _this._wheelEvent, handleMousewheel, false);
984
+ unbind(_this.container, _this._wheelEvent, handleMousewheel);
875
985
  }
876
986
 
877
987
  //Keyboard
878
988
  if (params.keyboardControl) {
879
- _this.h.removeEventListener(document, 'keydown', handleKeyboardKeys, false);
989
+ unbind(document, 'keydown', handleKeyboardKeys);
880
990
  }
881
991
 
882
992
  //Stop autoplay
@@ -887,83 +997,79 @@ var Swiper = function (selector, params) {
887
997
 
888
998
  //Destroy variable
889
999
  _this = null;
890
- }
1000
+ };
1001
+
891
1002
  function addSlideEvents() {
1003
+ var bind = _this.h.addEventListener,
1004
+ i;
1005
+
892
1006
  //Prevent Links Events
893
1007
  if (params.preventLinks) {
894
- var links = [];
895
- if (document.querySelectorAll) {
896
- links = _this.container.querySelectorAll('a');
897
- }
898
- else if (window.jQuery) {
899
- links = $$(_this.container).find('a');
900
- }
901
- for (var i=0; i<links.length; i++) {
902
- _this.h.addEventListener(links[i], 'click', preventClick, false);
1008
+ var links = $$('a', _this.container);
1009
+ for (i = 0; i < links.length; i++) {
1010
+ bind(links[i], 'click', preventClick);
903
1011
  }
904
1012
  }
905
1013
  //Release Form Elements
906
1014
  if (params.releaseFormElements) {
907
- var formElements = document.querySelectorAll ? _this.container.querySelectorAll('input, textarea, select') : $$(_this.container).find('input, textarea, select');
908
- for (var i=0; i<formElements.length; i++) {
909
- _this.h.addEventListener(formElements[i], _this.touchEvents.touchStart, releaseForms, true);
1015
+ var formElements = $$('input, textarea, select', _this.container);
1016
+ for (i = 0; i < formElements.length; i++) {
1017
+ bind(formElements[i], _this.touchEvents.touchStart, releaseForms, true);
910
1018
  }
911
1019
  }
912
1020
 
913
1021
  //Slide Clicks & Touches
914
1022
  if (params.onSlideClick) {
915
- for (var i=0; i<_this.slides.length; i++) {
916
- _this.h.addEventListener(_this.slides[i], 'click', slideClick, false);
1023
+ for (i = 0; i < _this.slides.length; i++) {
1024
+ bind(_this.slides[i], 'click', slideClick);
917
1025
  }
918
1026
  }
919
1027
  if (params.onSlideTouch) {
920
- for (var i=0; i<_this.slides.length; i++) {
921
- _this.h.addEventListener(_this.slides[i], _this.touchEvents.touchStart, slideTouch, false);
1028
+ for (i = 0; i < _this.slides.length; i++) {
1029
+ bind(_this.slides[i], _this.touchEvents.touchStart, slideTouch);
922
1030
  }
923
1031
  }
924
1032
  }
925
1033
  function removeSlideEvents() {
1034
+ var unbind = _this.h.removeEventListener,
1035
+ i;
1036
+
926
1037
  //Slide Clicks & Touches
927
1038
  if (params.onSlideClick) {
928
- for (var i=0; i<_this.slides.length; i++) {
929
- _this.h.removeEventListener(_this.slides[i], 'click', slideClick, false);
1039
+ for (i = 0; i < _this.slides.length; i++) {
1040
+ unbind(_this.slides[i], 'click', slideClick);
930
1041
  }
931
1042
  }
932
1043
  if (params.onSlideTouch) {
933
- for (var i=0; i<_this.slides.length; i++) {
934
- _this.h.removeEventListener(_this.slides[i], _this.touchEvents.touchStart, slideTouch, false);
1044
+ for (i = 0; i < _this.slides.length; i++) {
1045
+ unbind(_this.slides[i], _this.touchEvents.touchStart, slideTouch);
935
1046
  }
936
1047
  }
937
1048
  //Release Form Elements
938
1049
  if (params.releaseFormElements) {
939
- var formElements = document.querySelectorAll ? _this.container.querySelectorAll('input, textarea, select') : $$(_this.container).find('input, textarea, select');
940
- for (var i=0; i<formElements.length; i++) {
941
- _this.h.removeEventListener(formElements[i], _this.touchEvents.touchStart, releaseForms, true);
1050
+ var formElements = $$('input, textarea, select', _this.container);
1051
+ for (i = 0; i < formElements.length; i++) {
1052
+ unbind(formElements[i], _this.touchEvents.touchStart, releaseForms, true);
942
1053
  }
943
1054
  }
944
1055
  //Prevent Links Events
945
1056
  if (params.preventLinks) {
946
- var links = [];
947
- if (document.querySelectorAll) {
948
- links = _this.container.querySelectorAll('a');
949
- }
950
- else if (window.jQuery) {
951
- links = $$(_this.container).find('a');
952
- }
953
- for (var i=0; i<links.length; i++) {
954
- _this.h.removeEventListener(links[i], 'click', preventClick, false);
1057
+ var links = $$('a', _this.container);
1058
+ for (i = 0; i < links.length; i++) {
1059
+ unbind(links[i], 'click', preventClick);
955
1060
  }
956
1061
  }
957
1062
  }
958
1063
  /*==========================================
959
1064
  Keyboard Control
960
1065
  ============================================*/
961
- function handleKeyboardKeys (e) {
1066
+ function handleKeyboardKeys(e) {
962
1067
  var kc = e.keyCode || e.charCode;
963
- if (kc==37 || kc==39 || kc==38 || kc==40) {
1068
+ if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) return;
1069
+ if (kc === 37 || kc === 39 || kc === 38 || kc === 40) {
964
1070
  var inView = false;
965
1071
  //Check that swiper should be inside of visible area of window
966
- var swiperOffset = _this.h.getOffset( _this.container );
1072
+ var swiperOffset = _this.h.getOffset(_this.container);
967
1073
  var scrollLeft = _this.h.windowScroll().left;
968
1074
  var scrollTop = _this.h.windowScroll().top;
969
1075
  var windowWidth = _this.h.windowWidth();
@@ -973,12 +1079,12 @@ var Swiper = function (selector, params) {
973
1079
  [swiperOffset.left + _this.width, swiperOffset.top],
974
1080
  [swiperOffset.left, swiperOffset.top + _this.height],
975
1081
  [swiperOffset.left + _this.width, swiperOffset.top + _this.height]
976
- ]
977
- for (var i=0; i<swiperCoord.length; i++) {
1082
+ ];
1083
+ for (var i = 0; i < swiperCoord.length; i++) {
978
1084
  var point = swiperCoord[i];
979
1085
  if (
980
- point[0]>=scrollLeft && point[0]<=scrollLeft+windowWidth &&
981
- point[1]>=scrollTop && point[1]<=scrollTop+windowHeight
1086
+ point[0] >= scrollLeft && point[0] <= scrollLeft + windowWidth &&
1087
+ point[1] >= scrollTop && point[1] <= scrollTop + windowHeight
982
1088
  ) {
983
1089
  inView = true;
984
1090
  }
@@ -987,68 +1093,103 @@ var Swiper = function (selector, params) {
987
1093
  if (!inView) return;
988
1094
  }
989
1095
  if (isH) {
990
- if (kc==37 || kc==39) {
1096
+ if (kc === 37 || kc === 39) {
991
1097
  if (e.preventDefault) e.preventDefault();
992
1098
  else e.returnValue = false;
993
1099
  }
994
- if (kc == 39) _this.swipeNext();
995
- if (kc == 37) _this.swipePrev();
1100
+ if (kc === 39) _this.swipeNext();
1101
+ if (kc === 37) _this.swipePrev();
996
1102
  }
997
1103
  else {
998
- if (kc==38 || kc==40) {
1104
+ if (kc === 38 || kc === 40) {
999
1105
  if (e.preventDefault) e.preventDefault();
1000
1106
  else e.returnValue = false;
1001
1107
  }
1002
- if (kc == 40) _this.swipeNext();
1003
- if (kc == 38) _this.swipePrev();
1108
+ if (kc === 40) _this.swipeNext();
1109
+ if (kc === 38) _this.swipePrev();
1004
1110
  }
1005
1111
  }
1006
1112
 
1113
+ _this.disableKeyboardControl = function () {
1114
+ params.keyboardControl = false;
1115
+ _this.h.removeEventListener(document, 'keydown', handleKeyboardKeys);
1116
+ };
1117
+
1118
+ _this.enableKeyboardControl = function () {
1119
+ params.keyboardControl = true;
1120
+ _this.h.addEventListener(document, 'keydown', handleKeyboardKeys);
1121
+ };
1122
+
1007
1123
  /*==========================================
1008
1124
  Mousewheel Control
1009
1125
  ============================================*/
1010
- var allowScrollChange = true;
1011
- function handleMousewheel (e) {
1126
+ var lastScrollTime = (new Date()).getTime();
1127
+ function handleMousewheel(e) {
1012
1128
  var we = _this._wheelEvent;
1013
- var delta;
1129
+ var delta = 0;
1130
+
1014
1131
  //Opera & IE
1015
1132
  if (e.detail) delta = -e.detail;
1016
1133
  //WebKits
1017
- else if (we == 'mousewheel') delta = e.wheelDelta;
1134
+ else if (we === 'mousewheel') {
1135
+ if (params.mousewheelControlForceToAxis) {
1136
+ if (isH) {
1137
+ if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) delta = e.wheelDeltaX;
1138
+ else return;
1139
+ }
1140
+ else {
1141
+ if (Math.abs(e.wheelDeltaY) > Math.abs(e.wheelDeltaX)) delta = e.wheelDeltaY;
1142
+ else return;
1143
+ }
1144
+ }
1145
+ else {
1146
+ delta = e.wheelDelta;
1147
+ }
1148
+ }
1018
1149
  //Old FireFox
1019
- else if (we == 'DOMMouseScroll') delta = -e.detail;
1150
+ else if (we === 'DOMMouseScroll') delta = -e.detail;
1020
1151
  //New FireFox
1021
- else if (we == 'wheel') {
1022
- delta = Math.abs(e.deltaX)>Math.abs(e.deltaY) ? - e.deltaX : - e.deltaY;
1152
+ else if (we === 'wheel') {
1153
+ if (params.mousewheelControlForceToAxis) {
1154
+ if (isH) {
1155
+ if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = -e.deltaX;
1156
+ else return;
1157
+ }
1158
+ else {
1159
+ if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) delta = -e.deltaY;
1160
+ else return;
1161
+ }
1162
+ }
1163
+ else {
1164
+ delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? - e.deltaX : - e.deltaY;
1165
+ }
1023
1166
  }
1167
+
1024
1168
  if (!params.freeMode) {
1025
- if(delta<0) _this.swipeNext();
1026
- else _this.swipePrev();
1169
+ if ((new Date()).getTime() - lastScrollTime > 60) {
1170
+ if (delta < 0) _this.swipeNext();
1171
+ else _this.swipePrev();
1172
+ }
1173
+ lastScrollTime = (new Date()).getTime();
1174
+
1027
1175
  }
1028
1176
  else {
1029
1177
  //Freemode or scrollContainer:
1030
- var currentTransform =isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
1031
- var x,y;
1032
- if (isH) {
1033
- x = _this.getWrapperTranslate('x') + delta;
1034
- y = _this.getWrapperTranslate('y');
1035
- if (x>0) x = 0;
1036
- if (x<-maxWrapperPosition()) x = -maxWrapperPosition();
1037
- }
1038
- else {
1039
- x = _this.getWrapperTranslate('x');
1040
- y = _this.getWrapperTranslate('y')+delta;
1041
- if (y>0) y = 0;
1042
- if (y<-maxWrapperPosition()) y = -maxWrapperPosition();
1043
- }
1178
+ var position = _this.getWrapperTranslate() + delta;
1179
+
1180
+ if (position > 0) position = 0;
1181
+ if (position < -maxWrapperPosition()) position = -maxWrapperPosition();
1182
+
1044
1183
  _this.setWrapperTransition(0);
1045
- _this.setWrapperTranslate(x,y,0);
1046
- if (isH) _this.updateActiveSlide(x);
1047
- else _this.updateActiveSlide(y);
1184
+ _this.setWrapperTranslate(position);
1185
+ _this.updateActiveSlide(position);
1186
+
1187
+ // Return page scroll on edge positions
1188
+ if (position === 0 || position === -maxWrapperPosition()) return;
1048
1189
  }
1049
- if (params.autoplay) _this.stopAutoplay();
1190
+ if (params.autoplay) _this.stopAutoplay(true);
1050
1191
 
1051
- if(e.preventDefault) e.preventDefault();
1192
+ if (e.preventDefault) e.preventDefault();
1052
1193
  else e.returnValue = false;
1053
1194
  return false;
1054
1195
  }
@@ -1057,51 +1198,59 @@ var Swiper = function (selector, params) {
1057
1198
  Grab Cursor
1058
1199
  ===========================*/
1059
1200
  if (params.grabCursor) {
1060
- _this.container.style.cursor = 'move';
1061
- _this.container.style.cursor = 'grab';
1062
- _this.container.style.cursor = '-moz-grab';
1063
- _this.container.style.cursor = '-webkit-grab';
1201
+ var containerStyle = _this.container.style;
1202
+ containerStyle.cursor = 'move';
1203
+ containerStyle.cursor = 'grab';
1204
+ containerStyle.cursor = '-moz-grab';
1205
+ containerStyle.cursor = '-webkit-grab';
1064
1206
  }
1065
1207
 
1066
1208
  /*=========================
1067
1209
  Slides Events Handlers
1068
1210
  ===========================*/
1069
- function findSlide(el) {
1070
- var found = false;
1071
- while(!found) {
1072
- if (el.className.indexOf(params.slideClass)>-1)
1073
- {
1074
- found = el;
1075
- }
1076
- el = el.parentElement;
1077
- }
1078
- return found;
1079
- }
1211
+
1080
1212
  _this.allowSlideClick = true;
1081
- function slideClick(e) {
1082
- if(_this.allowSlideClick) {
1083
- if (!e.target) {
1084
- _this.clickedSlide = findSlide(e.srcElement);
1085
- _this.clickedSlideIndex = _this.slides.indexOf(_this.clickedSlide);
1086
- }
1087
- else {
1088
- _this.clickedSlide = this;
1089
- _this.clickedSlideIndex = _this.slides.indexOf(this);
1090
- }
1091
- params.onSlideClick(_this);
1213
+ function slideClick(event) {
1214
+ if (_this.allowSlideClick) {
1215
+ setClickedSlide(event);
1216
+ _this.fireCallback(params.onSlideClick, _this, event);
1092
1217
  }
1093
1218
  }
1094
- function slideTouch(e) {
1095
- if (!e.target) _this.clickedSlide = findSlide(e.srcElement);
1096
- else _this.clickedSlide = this;
1097
- _this.clickedSlideIndex = _this.slides.indexOf(_this.clickedSlide);
1098
- params.onSlideTouch(_this);
1219
+
1220
+ function slideTouch(event) {
1221
+ setClickedSlide(event);
1222
+ _this.fireCallback(params.onSlideTouch, _this, event);
1223
+ }
1224
+
1225
+ function setClickedSlide(event) {
1226
+
1227
+ // IE 6-8 support
1228
+ if (!event.currentTarget) {
1229
+ var element = event.srcElement;
1230
+ do {
1231
+ if (element.className.indexOf(params.slideClass) > -1) {
1232
+ break;
1233
+ }
1234
+ element = element.parentNode;
1235
+ } while (element);
1236
+ _this.clickedSlide = element;
1237
+ }
1238
+ else {
1239
+ _this.clickedSlide = event.currentTarget;
1240
+ }
1241
+
1242
+ _this.clickedSlideIndex = _this.slides.indexOf(_this.clickedSlide);
1243
+ _this.clickedSlideLoopIndex = _this.clickedSlideIndex - (_this.loopedSlides || 0);
1099
1244
  }
1245
+
1100
1246
  _this.allowLinks = true;
1101
1247
  function preventClick(e) {
1102
1248
  if (!_this.allowLinks) {
1103
- if(e.preventDefault) e.preventDefault();
1249
+ if (e.preventDefault) e.preventDefault();
1104
1250
  else e.returnValue = false;
1251
+ if (params.preventLinksPropagation && 'stopPropagation' in e) {
1252
+ e.stopPropagation();
1253
+ }
1105
1254
  return false;
1106
1255
  }
1107
1256
  }
@@ -1109,6 +1258,7 @@ var Swiper = function (selector, params) {
1109
1258
  if (e.stopPropagation) e.stopPropagation();
1110
1259
  else e.returnValue = false;
1111
1260
  return false;
1261
+
1112
1262
  }
1113
1263
 
1114
1264
  /*==================================================
@@ -1126,17 +1276,15 @@ var Swiper = function (selector, params) {
1126
1276
 
1127
1277
  if (params.noSwiping && (event.target || event.srcElement) && noSwipingSlide(event.target || event.srcElement)) return false;
1128
1278
  allowMomentumBounce = false;
1129
-
1130
1279
  //Check For Nested Swipers
1131
1280
  _this.isTouched = true;
1132
- isTouchEvent = event.type=='touchstart';
1281
+ isTouchEvent = event.type === 'touchstart';
1133
1282
 
1134
- if (!isTouchEvent || event.targetTouches.length == 1 ) {
1135
- if (params.loop) _this.fixLoop();
1283
+ if (!isTouchEvent || event.targetTouches.length === 1) {
1136
1284
  _this.callPlugins('onTouchStartBegin');
1137
1285
 
1138
- if(!isTouchEvent) {
1139
- if(event.preventDefault) event.preventDefault();
1286
+ if (!isTouchEvent && !_this.isAndroid) {
1287
+ if (event.preventDefault) event.preventDefault();
1140
1288
  else event.returnValue = false;
1141
1289
  }
1142
1290
 
@@ -1147,21 +1295,16 @@ var Swiper = function (selector, params) {
1147
1295
  _this.touches.startX = _this.touches.currentX = pageX;
1148
1296
  _this.touches.startY = _this.touches.currentY = pageY;
1149
1297
 
1150
- _this.touches.start = _this.touches.current = isH ? pageX : pageY ;
1298
+ _this.touches.start = _this.touches.current = isH ? pageX : pageY;
1151
1299
 
1152
1300
  //Set Transition Time to 0
1153
1301
  _this.setWrapperTransition(0);
1154
1302
 
1155
1303
  //Get Start Translate Position
1156
- _this.positions.start = _this.positions.current = isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
1304
+ _this.positions.start = _this.positions.current = _this.getWrapperTranslate();
1157
1305
 
1158
1306
  //Set Transform
1159
- if (isH) {
1160
- _this.setWrapperTranslate( _this.positions.start, 0, 0);
1161
- }
1162
- else {
1163
- _this.setWrapperTranslate( 0, _this.positions.start, 0);
1164
- }
1307
+ _this.setWrapperTranslate(_this.positions.start);
1165
1308
 
1166
1309
  //TouchStartTime
1167
1310
  _this.times.start = (new Date()).getTime();
@@ -1170,10 +1313,12 @@ var Swiper = function (selector, params) {
1170
1313
  isScrolling = undefined;
1171
1314
 
1172
1315
  //Set Treshold
1173
- if (params.moveStartThreshold>0) allowThresholdMove = false;
1316
+ if (params.moveStartThreshold > 0) {
1317
+ allowThresholdMove = false;
1318
+ }
1174
1319
 
1175
1320
  //CallBack
1176
- if (params.onTouchStart) params.onTouchStart(_this);
1321
+ if (params.onTouchStart) _this.fireCallback(params.onTouchStart, _this);
1177
1322
  _this.callPlugins('onTouchStartEnd');
1178
1323
 
1179
1324
  }
@@ -1182,33 +1327,30 @@ var Swiper = function (selector, params) {
1182
1327
  function onTouchMove(event) {
1183
1328
  // If slider is not touched - exit
1184
1329
  if (!_this.isTouched || params.onlyExternal) return;
1185
- if (isTouchEvent && event.type=='mousemove') return;
1330
+ if (isTouchEvent && event.type === 'mousemove') return;
1186
1331
 
1187
1332
  var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX);
1188
1333
  var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY);
1189
1334
 
1190
1335
  //check for scrolling
1191
- if ( typeof isScrolling === 'undefined' && isH) {
1192
- isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs( pageX - _this.touches.startX ) );
1336
+ if (typeof isScrolling === 'undefined' && isH) {
1337
+ isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs(pageX - _this.touches.startX));
1193
1338
  }
1194
- if ( typeof isScrolling === 'undefined' && !isH) {
1195
- isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs( pageX - _this.touches.startX ) );
1339
+ if (typeof isScrolling === 'undefined' && !isH) {
1340
+ isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs(pageX - _this.touches.startX));
1196
1341
  }
1197
- if (isScrolling ) {
1342
+ if (isScrolling) {
1198
1343
  _this.isTouched = false;
1199
- return
1344
+ return;
1200
1345
  }
1201
1346
 
1202
1347
  //Check For Nested Swipers
1203
1348
  if (event.assignedToSwiper) {
1204
1349
  _this.isTouched = false;
1205
- return
1350
+ return;
1206
1351
  }
1207
1352
  event.assignedToSwiper = true;
1208
1353
 
1209
- //Moved Flag
1210
- _this.isMoved = true;
1211
-
1212
1354
  //Block inner links
1213
1355
  if (params.preventLinks) {
1214
1356
  _this.allowLinks = false;
@@ -1219,71 +1361,86 @@ var Swiper = function (selector, params) {
1219
1361
 
1220
1362
  //Stop AutoPlay if exist
1221
1363
  if (params.autoplay) {
1222
- _this.stopAutoplay();
1364
+ _this.stopAutoplay(true);
1223
1365
  }
1224
- if (!isTouchEvent || event.touches.length == 1) {
1366
+ if (!isTouchEvent || event.touches.length === 1) {
1225
1367
 
1226
- _this.callPlugins('onTouchMoveStart');
1227
- if(event.preventDefault) event.preventDefault();
1368
+ //Moved Flag
1369
+ if (!_this.isMoved) {
1370
+ _this.callPlugins('onTouchMoveStart');
1371
+
1372
+ if (params.loop) {
1373
+ _this.fixLoop();
1374
+ _this.positions.start = _this.getWrapperTranslate();
1375
+ }
1376
+ if (params.onTouchMoveStart) _this.fireCallback(params.onTouchMoveStart, _this);
1377
+ }
1378
+ _this.isMoved = true;
1379
+
1380
+ // cancel event
1381
+ if (event.preventDefault) event.preventDefault();
1228
1382
  else event.returnValue = false;
1229
1383
 
1230
- _this.touches.current = isH ? pageX : pageY ;
1384
+ _this.touches.current = isH ? pageX : pageY;
1231
1385
 
1232
1386
  _this.positions.current = (_this.touches.current - _this.touches.start) * params.touchRatio + _this.positions.start;
1233
1387
 
1234
1388
  //Resistance Callbacks
1235
- if(_this.positions.current > 0 && params.onResistanceBefore) {
1236
- params.onResistanceBefore(_this, _this.positions.current);
1389
+ if (_this.positions.current > 0 && params.onResistanceBefore) {
1390
+ _this.fireCallback(params.onResistanceBefore, _this, _this.positions.current);
1237
1391
  }
1238
- if(_this.positions.current < -maxWrapperPosition() && params.onResistanceAfter) {
1239
- params.onResistanceAfter(_this, Math.abs(_this.positions.current + maxWrapperPosition()));
1392
+ if (_this.positions.current < -maxWrapperPosition() && params.onResistanceAfter) {
1393
+ _this.fireCallback(params.onResistanceAfter, _this, Math.abs(_this.positions.current + maxWrapperPosition()));
1240
1394
  }
1241
1395
  //Resistance
1242
- if (params.resistance && params.resistance!='100%') {
1396
+ if (params.resistance && params.resistance !== '100%') {
1397
+ var resistance;
1243
1398
  //Resistance for Negative-Back sliding
1244
- if(_this.positions.current > 0) {
1245
- var resistance = 1 - _this.positions.current/containerSize/2;
1399
+ if (_this.positions.current > 0) {
1400
+ resistance = 1 - _this.positions.current / containerSize / 2;
1246
1401
  if (resistance < 0.5)
1247
- _this.positions.current = (containerSize/2);
1402
+ _this.positions.current = (containerSize / 2);
1248
1403
  else
1249
1404
  _this.positions.current = _this.positions.current * resistance;
1250
1405
  }
1251
1406
  //Resistance for After-End Sliding
1252
- if ( _this.positions.current < -maxWrapperPosition() ) {
1407
+ if (_this.positions.current < -maxWrapperPosition()) {
1253
1408
 
1254
- var diff = (_this.touches.current - _this.touches.start)*params.touchRatio + (maxWrapperPosition()+_this.positions.start);
1255
- var resistance = (containerSize+diff)/(containerSize);
1256
- var newPos = _this.positions.current-diff*(1-resistance)/2;
1257
- var stopPos = -maxWrapperPosition() - containerSize/2;
1409
+ var diff = (_this.touches.current - _this.touches.start) * params.touchRatio + (maxWrapperPosition() + _this.positions.start);
1410
+ resistance = (containerSize + diff) / (containerSize);
1411
+ var newPos = _this.positions.current - diff * (1 - resistance) / 2;
1412
+ var stopPos = -maxWrapperPosition() - containerSize / 2;
1258
1413
 
1259
- if (newPos < stopPos || resistance<=0)
1414
+ if (newPos < stopPos || resistance <= 0)
1260
1415
  _this.positions.current = stopPos;
1261
1416
  else
1262
1417
  _this.positions.current = newPos;
1263
1418
  }
1264
1419
  }
1265
- if (params.resistance && params.resistance=='100%') {
1420
+ if (params.resistance && params.resistance === '100%') {
1266
1421
  //Resistance for Negative-Back sliding
1267
- if(_this.positions.current > 0 && !(params.freeMode&&!params.freeModeFluid)) {
1422
+ if (_this.positions.current > 0 && !(params.freeMode && !params.freeModeFluid)) {
1268
1423
  _this.positions.current = 0;
1269
1424
  }
1270
1425
  //Resistance for After-End Sliding
1271
- if ( (_this.positions.current) < -maxWrapperPosition() && !(params.freeMode&&!params.freeModeFluid)) {
1426
+ if (_this.positions.current < -maxWrapperPosition() && !(params.freeMode && !params.freeModeFluid)) {
1272
1427
  _this.positions.current = -maxWrapperPosition();
1273
1428
  }
1274
1429
  }
1275
1430
  //Move Slides
1276
- if (!params.followFinger) return
1431
+ if (!params.followFinger) return;
1277
1432
 
1278
1433
  if (!params.moveStartThreshold) {
1279
- if (isH) _this.setWrapperTranslate( _this.positions.current, 0, 0);
1280
- else _this.setWrapperTranslate( 0, _this.positions.current, 0);
1434
+ _this.setWrapperTranslate(_this.positions.current);
1281
1435
  }
1282
1436
  else {
1283
- if ( Math.abs(_this.touches.current - _this.touches.start)>params.moveStartThreshold || allowThresholdMove) {
1284
- allowThresholdMove = true;
1285
- if (isH) _this.setWrapperTranslate( _this.positions.current, 0, 0);
1286
- else _this.setWrapperTranslate( 0, _this.positions.current, 0);
1437
+ if (Math.abs(_this.touches.current - _this.touches.start) > params.moveStartThreshold || allowThresholdMove) {
1438
+ if (!allowThresholdMove) {
1439
+ allowThresholdMove = true;
1440
+ _this.touches.start = _this.touches.current;
1441
+ return;
1442
+ }
1443
+ _this.setWrapperTranslate(_this.positions.current);
1287
1444
  }
1288
1445
  else {
1289
1446
  _this.positions.current = _this.positions.start;
@@ -1303,14 +1460,14 @@ var Swiper = function (selector, params) {
1303
1460
  }
1304
1461
  //Velocity
1305
1462
  if (!velocityPrevPosition) velocityPrevPosition = _this.touches.current;
1306
- if (!velocityPrevTime) velocityPrevTime = (new Date).getTime();
1307
- _this.velocity = (_this.touches.current - velocityPrevPosition)/((new Date).getTime() - velocityPrevTime)/2;
1308
- if (Math.abs(_this.touches.current - velocityPrevPosition)<2) _this.velocity=0;
1463
+ if (!velocityPrevTime) velocityPrevTime = (new Date()).getTime();
1464
+ _this.velocity = (_this.touches.current - velocityPrevPosition) / ((new Date()).getTime() - velocityPrevTime) / 2;
1465
+ if (Math.abs(_this.touches.current - velocityPrevPosition) < 2) _this.velocity = 0;
1309
1466
  velocityPrevPosition = _this.touches.current;
1310
- velocityPrevTime = (new Date).getTime();
1467
+ velocityPrevTime = (new Date()).getTime();
1311
1468
  //Callbacks
1312
1469
  _this.callPlugins('onTouchMoveEnd');
1313
- if (params.onTouchMove) params.onTouchMove(_this);
1470
+ if (params.onTouchMove) _this.fireCallback(params.onTouchMove, _this);
1314
1471
 
1315
1472
  return false;
1316
1473
  }
@@ -1321,8 +1478,8 @@ var Swiper = function (selector, params) {
1321
1478
  _this.swipeReset();
1322
1479
  }
1323
1480
  // If slider is not touched exit
1324
- if ( params.onlyExternal || !_this.isTouched ) return;
1325
- _this.isTouched = false
1481
+ if (params.onlyExternal || !_this.isTouched) return;
1482
+ _this.isTouched = false;
1326
1483
 
1327
1484
  //Return Grab Cursor
1328
1485
  if (params.grabCursor) {
@@ -1333,33 +1490,31 @@ var Swiper = function (selector, params) {
1333
1490
  }
1334
1491
 
1335
1492
  //Check for Current Position
1336
- if (!_this.positions.current && _this.positions.current!==0) {
1337
- _this.positions.current = _this.positions.start
1493
+ if (!_this.positions.current && _this.positions.current !== 0) {
1494
+ _this.positions.current = _this.positions.start;
1338
1495
  }
1339
1496
 
1340
1497
  //For case if slider touched but not moved
1341
1498
  if (params.followFinger) {
1342
- if (isH) _this.setWrapperTranslate( _this.positions.current, 0, 0)
1343
- else _this.setWrapperTranslate( 0, _this.positions.current, 0)
1499
+ _this.setWrapperTranslate(_this.positions.current);
1344
1500
  }
1345
- //--
1346
1501
 
1347
1502
  // TouchEndTime
1348
1503
  _this.times.end = (new Date()).getTime();
1349
1504
 
1350
1505
  //Difference
1351
- _this.touches.diff = _this.touches.current - _this.touches.start
1352
- _this.touches.abs = Math.abs(_this.touches.diff)
1506
+ _this.touches.diff = _this.touches.current - _this.touches.start;
1507
+ _this.touches.abs = Math.abs(_this.touches.diff);
1353
1508
 
1354
- _this.positions.diff = _this.positions.current - _this.positions.start
1355
- _this.positions.abs = Math.abs(_this.positions.diff)
1509
+ _this.positions.diff = _this.positions.current - _this.positions.start;
1510
+ _this.positions.abs = Math.abs(_this.positions.diff);
1356
1511
 
1357
- var diff = _this.positions.diff ;
1358
- var diffAbs =_this.positions.abs ;
1359
- var timeDiff = _this.times.end - _this.times.start
1512
+ var diff = _this.positions.diff;
1513
+ var diffAbs = _this.positions.abs;
1514
+ var timeDiff = _this.times.end - _this.times.start;
1360
1515
 
1361
- if(diffAbs < 5 && (timeDiff) < 300 && _this.allowLinks == false) {
1362
- if (!params.freeMode && diffAbs!=0) _this.swipeReset()
1516
+ if (diffAbs < 5 && (timeDiff) < 300 && _this.allowLinks === false) {
1517
+ if (!params.freeMode && diffAbs !== 0) _this.swipeReset();
1363
1518
  //Release inner links
1364
1519
  if (params.preventLinks) {
1365
1520
  _this.allowLinks = true;
@@ -1368,7 +1523,8 @@ var Swiper = function (selector, params) {
1368
1523
  _this.allowSlideClick = true;
1369
1524
  }
1370
1525
  }
1371
- setTimeout(function(){
1526
+
1527
+ setTimeout(function () {
1372
1528
  //Release inner links
1373
1529
  if (params.preventLinks) {
1374
1530
  _this.allowLinks = true;
@@ -1376,140 +1532,131 @@ var Swiper = function (selector, params) {
1376
1532
  if (params.onSlideClick) {
1377
1533
  _this.allowSlideClick = true;
1378
1534
  }
1379
- },100)
1380
-
1381
- //Exit if not moved
1382
- if (!_this.isMoved) {
1383
- _this.isMoved = false;
1384
- if (params.onTouchEnd) params.onTouchEnd(_this)
1385
- _this.callPlugins('onTouchEnd');
1386
- _this.swipeReset();
1387
- return;
1388
- }
1389
- _this.isMoved = false;
1535
+ }, 100);
1390
1536
 
1391
1537
  var maxPosition = maxWrapperPosition();
1392
1538
 
1393
- //Prevent Negative Back Sliding
1394
- if (_this.positions.current > 0) {
1395
- _this.swipeReset()
1396
- if (params.onTouchEnd) params.onTouchEnd(_this)
1539
+ //Not moved or Prevent Negative Back Sliding/After-End Sliding
1540
+ if (!_this.isMoved && params.freeMode) {
1541
+ _this.isMoved = false;
1542
+ if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this);
1397
1543
  _this.callPlugins('onTouchEnd');
1398
1544
  return;
1399
1545
  }
1400
- //Prevent After-End Sliding
1401
- if (_this.positions.current < -maxPosition) {
1402
- _this.swipeReset()
1403
- if (params.onTouchEnd) params.onTouchEnd(_this)
1546
+ if (!_this.isMoved || _this.positions.current > 0 || _this.positions.current < -maxPosition) {
1547
+ _this.swipeReset();
1548
+ if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this);
1404
1549
  _this.callPlugins('onTouchEnd');
1405
1550
  return;
1406
1551
  }
1407
1552
 
1553
+ _this.isMoved = false;
1554
+
1408
1555
  //Free Mode
1409
1556
  if (params.freeMode) {
1410
- if ( params.freeModeFluid ) {
1411
- var momentumDuration = 1000*params.momentumRatio;
1412
- var momentumDistance = _this.velocity*momentumDuration;
1413
- var newPosition = _this.positions.current + momentumDistance
1557
+ if (params.freeModeFluid) {
1558
+ var momentumDuration = 1000 * params.momentumRatio;
1559
+ var momentumDistance = _this.velocity * momentumDuration;
1560
+ var newPosition = _this.positions.current + momentumDistance;
1414
1561
  var doBounce = false;
1415
1562
  var afterBouncePosition;
1416
- var bounceAmount = Math.abs( _this.velocity )*20*params.momentumBounceRatio;
1563
+ var bounceAmount = Math.abs(_this.velocity) * 20 * params.momentumBounceRatio;
1417
1564
  if (newPosition < -maxPosition) {
1418
1565
  if (params.momentumBounce && _this.support.transitions) {
1419
- if (newPosition + maxPosition < -bounceAmount) newPosition = -maxPosition-bounceAmount;
1566
+ if (newPosition + maxPosition < -bounceAmount) newPosition = -maxPosition - bounceAmount;
1420
1567
  afterBouncePosition = -maxPosition;
1421
- doBounce=true;
1568
+ doBounce = true;
1422
1569
  allowMomentumBounce = true;
1423
1570
  }
1424
1571
  else newPosition = -maxPosition;
1425
1572
  }
1426
1573
  if (newPosition > 0) {
1427
1574
  if (params.momentumBounce && _this.support.transitions) {
1428
- if (newPosition>bounceAmount) newPosition = bounceAmount;
1429
- afterBouncePosition = 0
1575
+ if (newPosition > bounceAmount) newPosition = bounceAmount;
1576
+ afterBouncePosition = 0;
1430
1577
  doBounce = true;
1431
1578
  allowMomentumBounce = true;
1432
1579
  }
1433
1580
  else newPosition = 0;
1434
1581
  }
1435
1582
  //Fix duration
1436
- if (_this.velocity!=0) momentumDuration = Math.abs((newPosition - _this.positions.current)/_this.velocity)
1583
+ if (_this.velocity !== 0) momentumDuration = Math.abs((newPosition - _this.positions.current) / _this.velocity);
1437
1584
 
1438
- if (isH) _this.setWrapperTranslate( newPosition, 0, 0);
1439
- else _this.setWrapperTranslate( 0, newPosition, 0);
1585
+ _this.setWrapperTranslate(newPosition);
1440
1586
 
1441
- _this.setWrapperTransition( momentumDuration );
1587
+ _this.setWrapperTransition(momentumDuration);
1442
1588
 
1443
1589
  if (params.momentumBounce && doBounce) {
1444
- _this.wrapperTransitionEnd(function(){
1590
+ _this.wrapperTransitionEnd(function () {
1445
1591
  if (!allowMomentumBounce) return;
1446
- if (params.onMomentumBounce) params.onMomentumBounce(_this);
1447
- if (isH) _this.setWrapperTranslate(afterBouncePosition, 0, 0);
1448
- else _this.setWrapperTranslate(0, afterBouncePosition, 0);
1592
+ if (params.onMomentumBounce) _this.fireCallback(params.onMomentumBounce, _this);
1593
+ _this.callPlugins('onMomentumBounce');
1594
+
1595
+ _this.setWrapperTranslate(afterBouncePosition);
1449
1596
  _this.setWrapperTransition(300);
1450
- })
1597
+ });
1451
1598
  }
1452
1599
 
1453
- _this.updateActiveSlide(newPosition)
1600
+ _this.updateActiveSlide(newPosition);
1454
1601
  }
1455
- if (!params.freeModeFluid || timeDiff >= 300) _this.updateActiveSlide(_this.positions.current)
1602
+ if (!params.freeModeFluid || timeDiff >= 300) _this.updateActiveSlide(_this.positions.current);
1456
1603
 
1457
- if (params.onTouchEnd) params.onTouchEnd(_this)
1604
+ if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this);
1458
1605
  _this.callPlugins('onTouchEnd');
1459
1606
  return;
1460
1607
  }
1461
1608
 
1462
1609
  //Direction
1463
- direction = diff < 0 ? "toNext" : "toPrev"
1610
+ direction = diff < 0 ? 'toNext' : 'toPrev';
1464
1611
 
1465
1612
  //Short Touches
1466
- if (direction=="toNext" && ( timeDiff <= 300 ) ) {
1467
- if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset()
1613
+ if (direction === 'toNext' && (timeDiff <= 300)) {
1614
+ if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset();
1468
1615
  else _this.swipeNext(true);
1469
1616
  }
1470
1617
 
1471
- if (direction=="toPrev" && ( timeDiff <= 300 ) ) {
1472
- if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset()
1618
+ if (direction === 'toPrev' && (timeDiff <= 300)) {
1619
+ if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset();
1473
1620
  else _this.swipePrev(true);
1474
1621
  }
1475
1622
 
1476
1623
  //Long Touches
1477
1624
  var targetSlideSize = 0;
1478
- if(params.slidesPerView == 'auto') {
1625
+ if (params.slidesPerView === 'auto') {
1479
1626
  //Define current slide's width
1480
- var currentPosition = Math.abs( isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y') );
1627
+ var currentPosition = Math.abs(_this.getWrapperTranslate());
1481
1628
  var slidesOffset = 0;
1482
1629
  var _slideSize;
1483
- for (var i=0; i<_this.slides.length; i++) {
1630
+ for (var i = 0; i < _this.slides.length; i++) {
1484
1631
  _slideSize = isH ? _this.slides[i].getWidth(true) : _this.slides[i].getHeight(true);
1485
- slidesOffset+= _slideSize;
1486
- if (slidesOffset>currentPosition) {
1632
+ slidesOffset += _slideSize;
1633
+ if (slidesOffset > currentPosition) {
1487
1634
  targetSlideSize = _slideSize;
1488
1635
  break;
1489
1636
  }
1490
1637
  }
1491
- if (targetSlideSize>containerSize) targetSlideSize = containerSize;
1638
+ if (targetSlideSize > containerSize) targetSlideSize = containerSize;
1492
1639
  }
1493
1640
  else {
1494
1641
  targetSlideSize = slideSize * params.slidesPerView;
1495
1642
  }
1496
- if (direction=="toNext" && ( timeDiff > 300 ) ) {
1497
- if (diffAbs >= targetSlideSize*0.5) {
1498
- _this.swipeNext(true)
1643
+ if (direction === 'toNext' && (timeDiff > 300)) {
1644
+ if (diffAbs >= targetSlideSize * params.longSwipesRatio) {
1645
+ _this.swipeNext(true);
1499
1646
  }
1500
1647
  else {
1501
- _this.swipeReset()
1648
+ _this.swipeReset();
1502
1649
  }
1503
1650
  }
1504
- if (direction=="toPrev" && ( timeDiff > 300 ) ) {
1505
- if (diffAbs >= targetSlideSize*0.5) {
1651
+ if (direction === 'toPrev' && (timeDiff > 300)) {
1652
+ if (diffAbs >= targetSlideSize * params.longSwipesRatio) {
1506
1653
  _this.swipePrev(true);
1507
1654
  }
1508
1655
  else {
1509
- _this.swipeReset()
1656
+ _this.swipeReset();
1510
1657
  }
1511
1658
  }
1512
- if (params.onTouchEnd) params.onTouchEnd(_this)
1659
+ if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this);
1513
1660
  _this.callPlugins('onTouchEnd');
1514
1661
  }
1515
1662
 
@@ -1517,7 +1664,7 @@ var Swiper = function (selector, params) {
1517
1664
  /*==================================================
1518
1665
  noSwiping Bubble Check by Isaac Strack
1519
1666
  ====================================================*/
1520
- function noSwipingSlide(el){
1667
+ function noSwipingSlide(el) {
1521
1668
  /*This function is specifically designed to check the parent elements for the noSwiping class, up to the wrapper.
1522
1669
  We need to check parents because while onTouchStart bubbles, _this.isTouched is checked in onTouchStart, which stops the bubbling.
1523
1670
  So, if a text box, for example, is the initial target, and the parent slide container has the noSwiping class, the _this.isTouched
@@ -1526,204 +1673,225 @@ var Swiper = function (selector, params) {
1526
1673
 
1527
1674
  // First we create a truthy variable, which is that swiping is allowd (noSwiping = false)
1528
1675
  var noSwiping = false;
1529
-
1676
+
1530
1677
  // Now we iterate up (parentElements) until we reach the node with the wrapperClass.
1531
- do{
1678
+ do {
1532
1679
 
1533
1680
  // Each time, we check to see if there's a 'swiper-no-swiping' class (noSwipingClass).
1534
- if (el.className.indexOf(params.noSwipingClass)>-1)
1681
+ if (el.className.indexOf(params.noSwipingClass) > -1)
1535
1682
  {
1536
1683
  noSwiping = true; // If there is, we set noSwiping = true;
1537
1684
  }
1538
1685
 
1539
1686
  el = el.parentElement; // now we iterate up (parent node)
1540
1687
 
1541
- } while(!noSwiping && el.parentElement && el.className.indexOf(params.wrapperClass)==-1); // also include el.parentElement truthy, just in case.
1688
+ } while (!noSwiping && el.parentElement && el.className.indexOf(params.wrapperClass) === -1); // also include el.parentElement truthy, just in case.
1542
1689
 
1543
1690
  // because we didn't check the wrapper itself, we do so now, if noSwiping is false:
1544
- if (!noSwiping && el.className.indexOf(params.wrapperClass)>-1 && el.className.indexOf(params.noSwipingClass)>-1)
1691
+ if (!noSwiping && el.className.indexOf(params.wrapperClass) > -1 && el.className.indexOf(params.noSwipingClass) > -1)
1545
1692
  noSwiping = true; // if the wrapper has the noSwipingClass, we set noSwiping = true;
1546
1693
 
1547
1694
  return noSwiping;
1548
1695
  }
1549
1696
 
1697
+ function addClassToHtmlString(klass, outerHtml) {
1698
+ var par = document.createElement('div');
1699
+ var child;
1700
+
1701
+ par.innerHTML = outerHtml;
1702
+ child = par.firstChild;
1703
+ child.className += ' ' + klass;
1704
+
1705
+ return child.outerHTML;
1706
+ }
1707
+
1708
+
1550
1709
  /*==================================================
1551
1710
  Swipe Functions
1552
1711
  ====================================================*/
1553
- _this.swipeNext = function(internal){
1712
+ _this.swipeNext = function (internal) {
1554
1713
  if (!internal && params.loop) _this.fixLoop();
1714
+ if (!internal && params.autoplay) _this.stopAutoplay(true);
1555
1715
  _this.callPlugins('onSwipeNext');
1556
- var currentPosition = isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
1716
+ var currentPosition = _this.getWrapperTranslate();
1557
1717
  var newPosition = currentPosition;
1558
- if (params.slidesPerView=='auto') {
1559
- for (var i=0; i<_this.snapGrid.length; i++) {
1560
- if (-currentPosition >= _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) {
1561
- newPosition = -_this.snapGrid[i+1]
1718
+ if (params.slidesPerView === 'auto') {
1719
+ for (var i = 0; i < _this.snapGrid.length; i++) {
1720
+ if (-currentPosition >= _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) {
1721
+ newPosition = -_this.snapGrid[i + 1];
1562
1722
  break;
1563
1723
  }
1564
1724
  }
1565
1725
  }
1566
1726
  else {
1567
1727
  var groupSize = slideSize * params.slidesPerGroup;
1568
- newPosition = -(Math.floor(Math.abs(currentPosition)/Math.floor(groupSize))*groupSize + groupSize);
1728
+ newPosition = -(Math.floor(Math.abs(currentPosition) / Math.floor(groupSize)) * groupSize + groupSize);
1569
1729
  }
1570
- if (newPosition < - maxWrapperPosition()) {
1571
- newPosition = - maxWrapperPosition()
1572
- };
1573
-
1574
- if (newPosition == currentPosition) return false;
1575
-
1730
+ if (newPosition < -maxWrapperPosition()) {
1731
+ newPosition = -maxWrapperPosition();
1732
+ }
1733
+ if (newPosition === currentPosition) return false;
1576
1734
  swipeToPosition(newPosition, 'next');
1577
- return true
1578
- }
1579
- _this.swipePrev = function(internal){
1735
+ return true;
1736
+ };
1737
+ _this.swipePrev = function (internal) {
1580
1738
  if (!internal && params.loop) _this.fixLoop();
1581
- if (!internal && params.autoplay) _this.stopAutoplay();
1739
+ if (!internal && params.autoplay) _this.stopAutoplay(true);
1582
1740
  _this.callPlugins('onSwipePrev');
1583
1741
 
1584
- var currentPosition = Math.ceil( isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y') );
1742
+ var currentPosition = Math.ceil(_this.getWrapperTranslate());
1585
1743
  var newPosition;
1586
- if (params.slidesPerView=='auto') {
1744
+ if (params.slidesPerView === 'auto') {
1587
1745
  newPosition = 0;
1588
- for (var i=1; i<_this.snapGrid.length; i++) {
1589
- if (-currentPosition == _this.snapGrid[i]) {
1590
- newPosition = -_this.snapGrid[i-1]
1746
+ for (var i = 1; i < _this.snapGrid.length; i++) {
1747
+ if (-currentPosition === _this.snapGrid[i]) {
1748
+ newPosition = -_this.snapGrid[i - 1];
1591
1749
  break;
1592
1750
  }
1593
- if (-currentPosition > _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) {
1594
- newPosition = -_this.snapGrid[i]
1751
+ if (-currentPosition > _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) {
1752
+ newPosition = -_this.snapGrid[i];
1595
1753
  break;
1596
1754
  }
1597
1755
  }
1598
1756
  }
1599
1757
  else {
1600
1758
  var groupSize = slideSize * params.slidesPerGroup;
1601
- newPosition = -(Math.ceil(-currentPosition/groupSize)-1)*groupSize;
1759
+ newPosition = -(Math.ceil(-currentPosition / groupSize) - 1) * groupSize;
1602
1760
  }
1603
1761
 
1604
1762
  if (newPosition > 0) newPosition = 0;
1605
1763
 
1606
- if (newPosition == currentPosition) return false;
1764
+ if (newPosition === currentPosition) return false;
1607
1765
  swipeToPosition(newPosition, 'prev');
1608
1766
  return true;
1609
1767
 
1610
- }
1611
- _this.swipeReset = function(){
1768
+ };
1769
+ _this.swipeReset = function () {
1612
1770
  _this.callPlugins('onSwipeReset');
1613
- var currentPosition = isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
1771
+ var currentPosition = _this.getWrapperTranslate();
1614
1772
  var groupSize = slideSize * params.slidesPerGroup;
1615
1773
  var newPosition;
1616
1774
  var maxPosition = -maxWrapperPosition();
1617
- if (params.slidesPerView=='auto') {
1775
+ if (params.slidesPerView === 'auto') {
1618
1776
  newPosition = 0;
1619
- for (var i=0; i<_this.snapGrid.length; i++) {
1620
- if (-currentPosition===_this.snapGrid[i]) return;
1621
- if (-currentPosition >= _this.snapGrid[i] && -currentPosition<_this.snapGrid[i+1]) {
1622
- if(_this.positions.diff>0) newPosition = -_this.snapGrid[i+1]
1623
- else newPosition = -_this.snapGrid[i]
1777
+ for (var i = 0; i < _this.snapGrid.length; i++) {
1778
+ if (-currentPosition === _this.snapGrid[i]) return;
1779
+ if (-currentPosition >= _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) {
1780
+ if (_this.positions.diff > 0) newPosition = -_this.snapGrid[i + 1];
1781
+ else newPosition = -_this.snapGrid[i];
1624
1782
  break;
1625
1783
  }
1626
1784
  }
1627
- if (-currentPosition >= _this.snapGrid[_this.snapGrid.length-1]) newPosition = -_this.snapGrid[_this.snapGrid.length-1];
1628
- if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition()
1785
+ if (-currentPosition >= _this.snapGrid[_this.snapGrid.length - 1]) newPosition = -_this.snapGrid[_this.snapGrid.length - 1];
1786
+ if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition();
1629
1787
  }
1630
1788
  else {
1631
- newPosition = currentPosition<0 ? Math.round(currentPosition/groupSize)*groupSize : 0
1789
+ newPosition = currentPosition < 0 ? Math.round(currentPosition / groupSize) * groupSize : 0;
1632
1790
  }
1633
1791
  if (params.scrollContainer) {
1634
- newPosition = currentPosition<0 ? currentPosition : 0;
1792
+ newPosition = currentPosition < 0 ? currentPosition : 0;
1635
1793
  }
1636
1794
  if (newPosition < -maxWrapperPosition()) {
1637
- newPosition = -maxWrapperPosition()
1795
+ newPosition = -maxWrapperPosition();
1638
1796
  }
1639
- if (params.scrollContainer && (containerSize>slideSize)) {
1797
+ if (params.scrollContainer && (containerSize > slideSize)) {
1640
1798
  newPosition = 0;
1641
1799
  }
1642
1800
 
1643
- if (newPosition == currentPosition) return false;
1801
+ if (newPosition === currentPosition) return false;
1644
1802
 
1645
1803
  swipeToPosition(newPosition, 'reset');
1646
1804
  return true;
1647
- }
1648
- _this.swipeTo = function(index, speed, runCallbacks){
1805
+ };
1806
+
1807
+ _this.swipeTo = function (index, speed, runCallbacks) {
1649
1808
  index = parseInt(index, 10);
1650
- _this.callPlugins('onSwipeTo', {index:index, speed:speed});
1809
+ _this.callPlugins('onSwipeTo', {index: index, speed: speed});
1651
1810
  if (params.loop) index = index + _this.loopedSlides;
1652
- var currentPosition = isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
1653
- if (index > (_this.slides.length-1)) return;
1654
- if (index<0) return;
1655
- var newPosition
1656
- if (params.slidesPerView=='auto') {
1657
- newPosition = -_this.slidesGrid[ index ];
1811
+ var currentPosition = _this.getWrapperTranslate();
1812
+ if (index > (_this.slides.length - 1) || index < 0) return;
1813
+ var newPosition;
1814
+ if (params.slidesPerView === 'auto') {
1815
+ newPosition = -_this.slidesGrid[index];
1658
1816
  }
1659
1817
  else {
1660
- newPosition = -index*slideSize;
1818
+ newPosition = -index * slideSize;
1661
1819
  }
1662
1820
  if (newPosition < - maxWrapperPosition()) {
1663
1821
  newPosition = - maxWrapperPosition();
1664
- };
1822
+ }
1665
1823
 
1666
- if (newPosition == currentPosition) return false;
1824
+ if (newPosition === currentPosition) return false;
1667
1825
 
1668
- runCallbacks = runCallbacks===false ? false : true;
1669
- swipeToPosition(newPosition, 'to', {index:index, speed:speed, runCallbacks:runCallbacks});
1826
+ runCallbacks = runCallbacks === false ? false : true;
1827
+ swipeToPosition(newPosition, 'to', {index: index, speed: speed, runCallbacks: runCallbacks});
1670
1828
  return true;
1671
- }
1829
+ };
1830
+
1672
1831
  function swipeToPosition(newPosition, action, toOptions) {
1832
+ var speed = (action === 'to' && toOptions.speed >= 0) ? toOptions.speed : params.speed;
1833
+ var timeOld = + new Date();
1834
+
1835
+ function anim() {
1836
+ var timeNew = + new Date();
1837
+ var time = timeNew - timeOld;
1838
+ currentPosition += animationStep * time / (1000 / 60);
1839
+ condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition;
1840
+ if (condition) {
1841
+ _this.setWrapperTranslate(Math.round(currentPosition));
1842
+ _this._DOMAnimating = true;
1843
+ window.setTimeout(function () {
1844
+ anim();
1845
+ }, 1000 / 60);
1846
+ }
1847
+ else {
1848
+ if (params.onSlideChangeEnd) {
1849
+ if (action === 'to') {
1850
+ if (toOptions.runCallbacks === true) _this.fireCallback(params.onSlideChangeEnd, _this);
1851
+ }
1852
+ else {
1853
+ _this.fireCallback(params.onSlideChangeEnd, _this);
1854
+ }
1855
+
1856
+ }
1857
+ _this.setWrapperTranslate(newPosition);
1858
+ _this._DOMAnimating = false;
1859
+ }
1860
+ }
1861
+
1673
1862
  if (_this.support.transitions || !params.DOMAnimation) {
1674
- if (isH) _this.setWrapperTranslate(newPosition,0,0);
1675
- else _this.setWrapperTranslate(0,newPosition,0);
1676
- var speed = (action=='to' && toOptions.speed>=0) ? toOptions.speed : params.speed;
1863
+ _this.setWrapperTranslate(newPosition);
1677
1864
  _this.setWrapperTransition(speed);
1678
1865
  }
1679
1866
  else {
1680
1867
  //Try the DOM animation
1681
- var currentPosition = isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
1682
- var speed = (action=='to' && toOptions.speed>=0) ? toOptions.speed : params.speed;
1683
- var animationStep = Math.ceil( (newPosition - currentPosition)/speed*(1000/60) );
1868
+ var currentPosition = _this.getWrapperTranslate();
1869
+ var animationStep = Math.ceil((newPosition - currentPosition) / speed * (1000 / 60));
1684
1870
  var direction = currentPosition > newPosition ? 'toNext' : 'toPrev';
1685
- var condition = direction=='toNext' ? currentPosition > newPosition : currentPosition < newPosition;
1871
+ var condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition;
1686
1872
  if (_this._DOMAnimating) return;
1687
1873
 
1688
- anim()
1689
- }
1690
- function anim(){
1691
- currentPosition += animationStep;
1692
- condition = direction=='toNext' ? currentPosition > newPosition : currentPosition < newPosition;
1693
- if (condition) {
1694
- if (isH) _this.setWrapperTranslate(Math.round(currentPosition),0)
1695
- else _this.setWrapperTranslate(0,Math.round(currentPosition))
1696
- _this._DOMAnimating = true
1697
- window.setTimeout(function(){
1698
- anim()
1699
- }, 1000 / 60)
1700
- }
1701
- else {
1702
- if (params.onSlideChangeEnd) params.onSlideChangeEnd(_this)
1703
- if (isH) _this.setWrapperTranslate(newPosition,0);
1704
- else _this.setWrapperTranslate(0, newPosition);
1705
- _this._DOMAnimating = false;
1706
- }
1874
+ anim();
1707
1875
  }
1708
1876
 
1709
1877
  //Update Active Slide Index
1710
1878
  _this.updateActiveSlide(newPosition);
1711
1879
 
1712
1880
  //Callbacks
1713
- if (params.onSlideNext && action=='next') {
1714
- params.onSlideNext(_this, newPosition)
1881
+ if (params.onSlideNext && action === 'next') {
1882
+ _this.fireCallback(params.onSlideNext, _this, newPosition);
1715
1883
  }
1716
- if (params.onSlidePrev && action=='prev') {
1717
- params.onSlidePrev(_this, newPosition)
1884
+ if (params.onSlidePrev && action === 'prev') {
1885
+ _this.fireCallback(params.onSlidePrev, _this, newPosition);
1718
1886
  }
1719
- //"Reset" Callback
1720
- if (params.onSlideReset && action=='reset') {
1721
- params.onSlideReset(_this, newPosition)
1887
+ //'Reset' Callback
1888
+ if (params.onSlideReset && action === 'reset') {
1889
+ _this.fireCallback(params.onSlideReset, _this, newPosition);
1722
1890
  }
1723
1891
 
1724
- //"Next", "Prev" and "To" Callbacks
1725
- if (action=='next' || action=='prev' || (action=='to' && toOptions.runCallbacks==true))
1726
- slideChangeCallbacks()
1892
+ //'Next', 'Prev' and 'To' Callbacks
1893
+ if (action === 'next' || action === 'prev' || (action === 'to' && toOptions.runCallbacks === true))
1894
+ slideChangeCallbacks(action);
1727
1895
  }
1728
1896
  /*==================================================
1729
1897
  Transition Callbacks
@@ -1731,19 +1899,19 @@ var Swiper = function (selector, params) {
1731
1899
  //Prevent Multiple Callbacks
1732
1900
  _this._queueStartCallbacks = false;
1733
1901
  _this._queueEndCallbacks = false;
1734
- function slideChangeCallbacks() {
1902
+ function slideChangeCallbacks(direction) {
1735
1903
  //Transition Start Callback
1736
1904
  _this.callPlugins('onSlideChangeStart');
1737
1905
  if (params.onSlideChangeStart) {
1738
1906
  if (params.queueStartCallbacks && _this.support.transitions) {
1739
1907
  if (_this._queueStartCallbacks) return;
1740
1908
  _this._queueStartCallbacks = true;
1741
- params.onSlideChangeStart(_this)
1742
- _this.wrapperTransitionEnd(function(){
1909
+ _this.fireCallback(params.onSlideChangeStart, _this, direction);
1910
+ _this.wrapperTransitionEnd(function () {
1743
1911
  _this._queueStartCallbacks = false;
1744
- })
1912
+ });
1745
1913
  }
1746
- else params.onSlideChangeStart(_this)
1914
+ else _this.fireCallback(params.onSlideChangeStart, _this, direction);
1747
1915
  }
1748
1916
  //Transition End Callback
1749
1917
  if (params.onSlideChangeEnd) {
@@ -1751,78 +1919,101 @@ var Swiper = function (selector, params) {
1751
1919
  if (params.queueEndCallbacks) {
1752
1920
  if (_this._queueEndCallbacks) return;
1753
1921
  _this._queueEndCallbacks = true;
1754
- _this.wrapperTransitionEnd(params.onSlideChangeEnd)
1922
+ _this.wrapperTransitionEnd(function (swiper) {
1923
+ _this.fireCallback(params.onSlideChangeEnd, swiper, direction);
1924
+ });
1925
+ }
1926
+ else {
1927
+ _this.wrapperTransitionEnd(function (swiper) {
1928
+ _this.fireCallback(params.onSlideChangeEnd, swiper, direction);
1929
+ });
1755
1930
  }
1756
- else _this.wrapperTransitionEnd(params.onSlideChangeEnd)
1757
1931
  }
1758
1932
  else {
1759
1933
  if (!params.DOMAnimation) {
1760
- setTimeout(function(){
1761
- params.onSlideChangeEnd(_this)
1762
- },10)
1934
+ setTimeout(function () {
1935
+ _this.fireCallback(params.onSlideChangeEnd, _this, direction);
1936
+ }, 10);
1763
1937
  }
1764
1938
  }
1765
1939
  }
1766
1940
  }
1941
+
1767
1942
  /*==================================================
1768
1943
  Update Active Slide Index
1769
1944
  ====================================================*/
1770
- _this.updateActiveSlide = function(position) {
1945
+ _this.updateActiveSlide = function (position) {
1771
1946
  if (!_this.initialized) return;
1772
- if (_this.slides.length==0) return;
1947
+ if (_this.slides.length === 0) return;
1773
1948
  _this.previousIndex = _this.activeIndex;
1774
- if (position>0) position=0;
1775
- if (typeof position=='undefined') position = isH ? _this.getWrapperTranslate('x') : _this.getWrapperTranslate('y');
1776
-
1777
- if (params.slidesPerView == 'auto') {
1949
+ if (typeof position === 'undefined') position = _this.getWrapperTranslate();
1950
+ if (position > 0) position = 0;
1951
+ var i;
1952
+ if (params.slidesPerView === 'auto') {
1778
1953
  var slidesOffset = 0;
1779
1954
  _this.activeIndex = _this.slidesGrid.indexOf(-position);
1780
- if (_this.activeIndex<0) {
1781
- for (var i=0; i<_this.slidesGrid.length-1; i++) {
1782
- if (-position>_this.slidesGrid[i] && -position<_this.slidesGrid[i+1]) {
1955
+ if (_this.activeIndex < 0) {
1956
+ for (i = 0; i < _this.slidesGrid.length - 1; i++) {
1957
+ if (-position > _this.slidesGrid[i] && -position < _this.slidesGrid[i + 1]) {
1783
1958
  break;
1784
1959
  }
1785
1960
  }
1786
- var leftDistance = Math.abs( _this.slidesGrid[i] + position )
1787
- var rightDistance = Math.abs( _this.slidesGrid[i+1] + position )
1788
- if (leftDistance<=rightDistance) _this.activeIndex = i;
1789
- else _this.activeIndex = i+1;
1961
+ var leftDistance = Math.abs(_this.slidesGrid[i] + position);
1962
+ var rightDistance = Math.abs(_this.slidesGrid[i + 1] + position);
1963
+ if (leftDistance <= rightDistance) _this.activeIndex = i;
1964
+ else _this.activeIndex = i + 1;
1790
1965
  }
1791
1966
  }
1792
1967
  else {
1793
- if (params.visibilityFullFit) _this.activeIndex = Math.ceil( -position/slideSize );
1794
- else _this.activeIndex = Math.round( -position/slideSize );
1968
+ _this.activeIndex = Math[params.visibilityFullFit ? 'ceil' : 'round'](-position / slideSize);
1795
1969
  }
1796
- if (_this.activeIndex== _this.slides.length ) _this.activeIndex = _this.slides.length-1;
1797
- if (_this.activeIndex<0) _this.activeIndex = 0;
1970
+
1971
+ if (_this.activeIndex === _this.slides.length) _this.activeIndex = _this.slides.length - 1;
1972
+ if (_this.activeIndex < 0) _this.activeIndex = 0;
1973
+
1798
1974
  // Check for slide
1799
1975
  if (!_this.slides[_this.activeIndex]) return;
1976
+
1800
1977
  // Calc Visible slides
1801
1978
  _this.calcVisibleSlides(position);
1802
1979
 
1803
1980
  // Mark visible and active slides with additonal classes
1804
- var activeClassRegexp = new RegExp( "\\s*" + params.slideActiveClass );
1805
- var inViewClassRegexp = new RegExp( "\\s*" + params.slideVisibleClass );
1806
-
1807
- for (var i = 0; i < _this.slides.length; i++) {
1808
- _this.slides[ i ].className = _this.slides[ i ].className.replace( activeClassRegexp, '' ).replace( inViewClassRegexp, '' );
1809
- if ( _this.visibleSlides.indexOf( _this.slides[ i ] )>=0 ) {
1810
- _this.slides[ i ].className += ' ' + params.slideVisibleClass;
1981
+ if (_this.support.classList) {
1982
+ var slide;
1983
+ for (i = 0; i < _this.slides.length; i++) {
1984
+ slide = _this.slides[i];
1985
+ slide.classList.remove(params.slideActiveClass);
1986
+ if (_this.visibleSlides.indexOf(slide) >= 0) {
1987
+ slide.classList.add(params.slideVisibleClass);
1988
+ } else {
1989
+ slide.classList.remove(params.slideVisibleClass);
1990
+ }
1811
1991
  }
1992
+ _this.slides[_this.activeIndex].classList.add(params.slideActiveClass);
1993
+ } else {
1994
+ var activeClassRegexp = new RegExp('\\s*' + params.slideActiveClass);
1995
+ var inViewClassRegexp = new RegExp('\\s*' + params.slideVisibleClass);
1812
1996
 
1997
+ for (i = 0; i < _this.slides.length; i++) {
1998
+ _this.slides[i].className = _this.slides[i].className.replace(activeClassRegexp, '').replace(inViewClassRegexp, '');
1999
+ if (_this.visibleSlides.indexOf(_this.slides[i]) >= 0) {
2000
+ _this.slides[i].className += ' ' + params.slideVisibleClass;
2001
+ }
2002
+ }
2003
+ _this.slides[_this.activeIndex].className += ' ' + params.slideActiveClass;
1813
2004
  }
1814
- _this.slides[ _this.activeIndex ].className += ' ' + params.slideActiveClass;
1815
2005
 
1816
2006
  //Update loop index
1817
2007
  if (params.loop) {
1818
2008
  var ls = _this.loopedSlides;
1819
2009
  _this.activeLoopIndex = _this.activeIndex - ls;
1820
- if (_this.activeLoopIndex >= _this.slides.length - ls*2 ) {
1821
- _this.activeLoopIndex = _this.slides.length - ls*2 - _this.activeLoopIndex;
2010
+ if (_this.activeLoopIndex >= _this.slides.length - ls * 2) {
2011
+ _this.activeLoopIndex = _this.slides.length - ls * 2 - _this.activeLoopIndex;
1822
2012
  }
1823
- if (_this.activeLoopIndex<0) {
1824
- _this.activeLoopIndex = _this.slides.length - ls*2 + _this.activeLoopIndex;
2013
+ if (_this.activeLoopIndex < 0) {
2014
+ _this.activeLoopIndex = _this.slides.length - ls * 2 + _this.activeLoopIndex;
1825
2015
  }
2016
+ if (_this.activeLoopIndex < 0) _this.activeLoopIndex = 0;
1826
2017
  }
1827
2018
  else {
1828
2019
  _this.activeLoopIndex = _this.activeIndex;
@@ -1831,7 +2022,7 @@ var Swiper = function (selector, params) {
1831
2022
  if (params.pagination) {
1832
2023
  _this.updatePagination(position);
1833
2024
  }
1834
- }
2025
+ };
1835
2026
  /*==================================================
1836
2027
  Pagination
1837
2028
  ====================================================*/
@@ -1839,223 +2030,303 @@ var Swiper = function (selector, params) {
1839
2030
  if (params.paginationClickable && _this.paginationButtons) {
1840
2031
  removePaginationEvents();
1841
2032
  }
1842
- var paginationHTML = "";
1843
- var numOfSlides = _this.slides.length;
1844
- var numOfButtons = numOfSlides;
1845
- if (params.loop) numOfButtons -= _this.loopedSlides*2
1846
- for (var i = 0; i < numOfButtons; i++) {
1847
- paginationHTML += '<'+params.paginationElement+' class="'+params.paginationElementClass+'"></'+params.paginationElement+'>'
1848
- }
1849
2033
  _this.paginationContainer = params.pagination.nodeType ? params.pagination : $$(params.pagination)[0];
1850
- _this.paginationContainer.innerHTML = paginationHTML;
1851
- _this.paginationButtons = []
1852
- if (document.querySelectorAll)
1853
- _this.paginationButtons = _this.paginationContainer.querySelectorAll('.'+params.paginationElementClass);
1854
- else if (window.jQuery)
1855
- _this.paginationButtons = $$(_this.paginationContainer).find('.'+params.paginationElementClass);
1856
- if (!firstInit) _this.updatePagination()
2034
+ if (params.createPagination) {
2035
+ var paginationHTML = '';
2036
+ var numOfSlides = _this.slides.length;
2037
+ var numOfButtons = numOfSlides;
2038
+ if (params.loop) numOfButtons -= _this.loopedSlides * 2;
2039
+ for (var i = 0; i < numOfButtons; i++) {
2040
+ paginationHTML += '<' + params.paginationElement + ' class="' + params.paginationElementClass + '"></' + params.paginationElement + '>';
2041
+ }
2042
+ _this.paginationContainer.innerHTML = paginationHTML;
2043
+ }
2044
+ _this.paginationButtons = $$('.' + params.paginationElementClass, _this.paginationContainer);
2045
+ if (!firstInit) _this.updatePagination();
1857
2046
  _this.callPlugins('onCreatePagination');
1858
2047
  if (params.paginationClickable) {
1859
2048
  addPaginationEvents();
1860
2049
  }
1861
- }
2050
+ };
1862
2051
  function removePaginationEvents() {
1863
2052
  var pagers = _this.paginationButtons;
1864
- for (var i=0; i<pagers.length; i++) {
1865
- _this.h.removeEventListener(pagers[i],'click', paginationClick, false)
2053
+ if (pagers) {
2054
+ for (var i = 0; i < pagers.length; i++) {
2055
+ _this.h.removeEventListener(pagers[i], 'click', paginationClick);
2056
+ }
1866
2057
  }
1867
2058
  }
1868
2059
  function addPaginationEvents() {
1869
2060
  var pagers = _this.paginationButtons;
1870
- for (var i=0; i<pagers.length; i++) {
1871
- _this.h.addEventListener(pagers[i],'click', paginationClick, false)
2061
+ if (pagers) {
2062
+ for (var i = 0; i < pagers.length; i++) {
2063
+ _this.h.addEventListener(pagers[i], 'click', paginationClick);
2064
+ }
1872
2065
  }
1873
2066
  }
1874
- function paginationClick(e){
2067
+ function paginationClick(e) {
1875
2068
  var index;
1876
2069
  var target = e.target || e.srcElement;
1877
2070
  var pagers = _this.paginationButtons;
1878
- for (var i=0; i<pagers.length; i++) {
1879
- if (target===pagers[i]) index = i;
2071
+ for (var i = 0; i < pagers.length; i++) {
2072
+ if (target === pagers[i]) index = i;
1880
2073
  }
1881
- _this.swipeTo(index)
2074
+ _this.swipeTo(index);
1882
2075
  }
1883
- _this.updatePagination = function(position) {
2076
+ _this.updatePagination = function (position) {
1884
2077
  if (!params.pagination) return;
1885
- if (_this.slides.length<1) return;
1886
-
1887
- if (document.querySelectorAll)
1888
- var activePagers = _this.paginationContainer.querySelectorAll('.'+params.paginationActiveClass)
1889
- else if (window.jQuery)
1890
- var activePagers = $$(_this.paginationContainer).find('.'+params.paginationActiveClass);
1891
- if(!activePagers) return;
2078
+ if (_this.slides.length < 1) return;
2079
+ var activePagers = $$('.' + params.paginationActiveClass, _this.paginationContainer);
2080
+ if (!activePagers) return;
1892
2081
 
1893
2082
  //Reset all Buttons' class to not active
1894
2083
  var pagers = _this.paginationButtons;
1895
- if (pagers.length==0) return;
1896
- for (var i=0; i < pagers.length; i++) {
1897
- pagers[i].className = params.paginationElementClass
2084
+ if (pagers.length === 0) return;
2085
+ for (var i = 0; i < pagers.length; i++) {
2086
+ pagers[i].className = params.paginationElementClass;
1898
2087
  }
1899
2088
 
1900
2089
  var indexOffset = params.loop ? _this.loopedSlides : 0;
1901
2090
  if (params.paginationAsRange) {
1902
- if (!_this.visibleSlides) _this.calcVisibleSlides(position)
2091
+ if (!_this.visibleSlides) _this.calcVisibleSlides(position);
1903
2092
  //Get Visible Indexes
1904
2093
  var visibleIndexes = [];
1905
- for (var i = 0; i < _this.visibleSlides.length; i++) {
1906
- var visIndex = _this.slides.indexOf( _this.visibleSlides[i] ) - indexOffset
2094
+ var j; // lopp index - avoid JSHint W004 / W038
2095
+ for (j = 0; j < _this.visibleSlides.length; j++) {
2096
+ var visIndex = _this.slides.indexOf(_this.visibleSlides[j]) - indexOffset;
1907
2097
 
1908
- if (params.loop && visIndex<0) {
1909
- visIndex = _this.slides.length - _this.loopedSlides*2 + visIndex;
2098
+ if (params.loop && visIndex < 0) {
2099
+ visIndex = _this.slides.length - _this.loopedSlides * 2 + visIndex;
1910
2100
  }
1911
- if (params.loop && visIndex>=_this.slides.length-_this.loopedSlides*2) {
1912
- visIndex = _this.slides.length - _this.loopedSlides*2 - visIndex;
1913
- visIndex = Math.abs(visIndex)
2101
+ if (params.loop && visIndex >= _this.slides.length - _this.loopedSlides * 2) {
2102
+ visIndex = _this.slides.length - _this.loopedSlides * 2 - visIndex;
2103
+ visIndex = Math.abs(visIndex);
1914
2104
  }
1915
- visibleIndexes.push( visIndex )
2105
+ visibleIndexes.push(visIndex);
1916
2106
  }
1917
-
1918
- for (i=0; i<visibleIndexes.length; i++) {
1919
- if (pagers[ visibleIndexes[i] ]) pagers[ visibleIndexes[i] ].className += ' ' + params.paginationVisibleClass;
2107
+
2108
+ for (j = 0; j < visibleIndexes.length; j++) {
2109
+ if (pagers[visibleIndexes[j]]) pagers[visibleIndexes[j]].className += ' ' + params.paginationVisibleClass;
1920
2110
  }
1921
-
2111
+
1922
2112
  if (params.loop) {
1923
- pagers[ _this.activeLoopIndex ].className += ' ' + params.paginationActiveClass;
2113
+ if (pagers[_this.activeLoopIndex] !== undefined) {
2114
+ pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass;
2115
+ }
1924
2116
  }
1925
2117
  else {
1926
- pagers[ _this.activeIndex ].className += ' ' + params.paginationActiveClass;
2118
+ pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass;
1927
2119
  }
1928
-
1929
2120
  }
1930
2121
  else {
1931
2122
  if (params.loop) {
1932
- pagers[ _this.activeLoopIndex ].className+=' '+params.paginationActiveClass+' '+params.paginationVisibleClass;
2123
+ if (pagers[_this.activeLoopIndex]) pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass;
1933
2124
  }
1934
2125
  else {
1935
- pagers[ _this.activeIndex ].className+=' '+params.paginationActiveClass+' '+params.paginationVisibleClass;
2126
+ pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass;
1936
2127
  }
1937
-
1938
2128
  }
1939
-
1940
- }
1941
- _this.calcVisibleSlides = function(position){
2129
+ };
2130
+ _this.calcVisibleSlides = function (position) {
1942
2131
  var visibleSlides = [];
1943
2132
  var _slideLeft = 0, _slideSize = 0, _slideRight = 0;
1944
- if (isH && _this.wrapperLeft>0) position = position+_this.wrapperLeft;
1945
- if (!isH && _this.wrapperTop>0) position = position+_this.wrapperTop;
2133
+ if (isH && _this.wrapperLeft > 0) position = position + _this.wrapperLeft;
2134
+ if (!isH && _this.wrapperTop > 0) position = position + _this.wrapperTop;
1946
2135
 
1947
- for (var i=0; i<_this.slides.length; i++) {
2136
+ for (var i = 0; i < _this.slides.length; i++) {
1948
2137
  _slideLeft += _slideSize;
1949
- if (params.slidesPerView == 'auto')
1950
- _slideSize = isH ? _this.h.getWidth(_this.slides[i],true) : _this.h.getHeight(_this.slides[i],true);
2138
+ if (params.slidesPerView === 'auto')
2139
+ _slideSize = isH ? _this.h.getWidth(_this.slides[i], true) : _this.h.getHeight(_this.slides[i], true);
1951
2140
  else _slideSize = slideSize;
1952
2141
 
1953
2142
  _slideRight = _slideLeft + _slideSize;
1954
2143
  var isVisibile = false;
1955
2144
  if (params.visibilityFullFit) {
1956
- if (_slideLeft >= -position && _slideRight <= -position+containerSize) isVisibile = true;
1957
- if (_slideLeft <= -position && _slideRight >= -position+containerSize) isVisibile = true;
2145
+ if (_slideLeft >= -position && _slideRight <= -position + containerSize) isVisibile = true;
2146
+ if (_slideLeft <= -position && _slideRight >= -position + containerSize) isVisibile = true;
1958
2147
  }
1959
2148
  else {
1960
-
1961
- if (_slideRight > -position && _slideRight <= ((-position+containerSize))) isVisibile = true;
1962
- if (_slideLeft >= -position && _slideLeft < ((-position+containerSize))) isVisibile = true;
1963
- if (_slideLeft < -position && _slideRight > ((-position+containerSize))) isVisibile = true;
2149
+ if (_slideRight > -position && _slideRight <= ((-position + containerSize))) isVisibile = true;
2150
+ if (_slideLeft >= -position && _slideLeft < ((-position + containerSize))) isVisibile = true;
2151
+ if (_slideLeft < -position && _slideRight > ((-position + containerSize))) isVisibile = true;
1964
2152
  }
1965
2153
 
1966
- if (isVisibile) visibleSlides.push(_this.slides[i])
2154
+ if (isVisibile) visibleSlides.push(_this.slides[i]);
1967
2155
 
1968
2156
  }
1969
- if (visibleSlides.length==0) visibleSlides = [ _this.slides[ _this.activeIndex ] ]
2157
+ if (visibleSlides.length === 0) visibleSlides = [_this.slides[_this.activeIndex]];
1970
2158
 
1971
2159
  _this.visibleSlides = visibleSlides;
1972
- }
2160
+ };
1973
2161
 
1974
2162
  /*==========================================
1975
2163
  Autoplay
1976
2164
  ============================================*/
1977
- _this.autoPlayIntervalId = undefined;
2165
+ var autoplayTimeoutId, autoplayIntervalId;
1978
2166
  _this.startAutoplay = function () {
1979
- if (typeof _this.autoPlayIntervalId !== 'undefined') return false;
1980
- if (params.autoplay && !params.loop) {
1981
- _this.autoPlayIntervalId = setInterval(function(){
1982
- if (!_this.swipeNext(true)) _this.swipeTo(0);
1983
- }, params.autoplay)
1984
- }
1985
- if (params.autoplay && params.loop) {
1986
- _this.autoPlayIntervalId = setInterval(function(){
1987
- _this.swipeNext();
1988
- }, params.autoplay)
1989
- }
1990
- _this.callPlugins('onAutoplayStart');
1991
- }
1992
- _this.stopAutoplay = function () {
1993
- if (_this.autoPlayIntervalId) clearInterval(_this.autoPlayIntervalId);
1994
- _this.autoPlayIntervalId = undefined;
1995
- _this.callPlugins('onAutoplayStop');
2167
+ if (_this.support.transitions) {
2168
+ if (typeof autoplayTimeoutId !== 'undefined') return false;
2169
+ if (!params.autoplay) return;
2170
+ _this.callPlugins('onAutoplayStart');
2171
+ if (params.onAutoplayStart) _this.fireCallback(params.onAutoplayStart, _this);
2172
+ autoplay();
2173
+ }
2174
+ else {
2175
+ if (typeof autoplayIntervalId !== 'undefined') return false;
2176
+ if (!params.autoplay) return;
2177
+ _this.callPlugins('onAutoplayStart');
2178
+ if (params.onAutoplayStart) _this.fireCallback(params.onAutoplayStart, _this);
2179
+ autoplayIntervalId = setInterval(function () {
2180
+ if (params.loop) {
2181
+ _this.fixLoop();
2182
+ _this.swipeNext(true);
2183
+ }
2184
+ else if (!_this.swipeNext(true)) {
2185
+ if (!params.autoplayStopOnLast) _this.swipeTo(0);
2186
+ else {
2187
+ clearInterval(autoplayIntervalId);
2188
+ autoplayIntervalId = undefined;
2189
+ }
2190
+ }
2191
+ }, params.autoplay);
2192
+ }
2193
+ };
2194
+ _this.stopAutoplay = function (internal) {
2195
+ if (_this.support.transitions) {
2196
+ if (!autoplayTimeoutId) return;
2197
+ if (autoplayTimeoutId) clearTimeout(autoplayTimeoutId);
2198
+ autoplayTimeoutId = undefined;
2199
+ if (internal && !params.autoplayDisableOnInteraction) {
2200
+ _this.wrapperTransitionEnd(function () {
2201
+ autoplay();
2202
+ });
2203
+ }
2204
+ _this.callPlugins('onAutoplayStop');
2205
+ if (params.onAutoplayStop) _this.fireCallback(params.onAutoplayStop, _this);
2206
+ }
2207
+ else {
2208
+ if (autoplayIntervalId) clearInterval(autoplayIntervalId);
2209
+ autoplayIntervalId = undefined;
2210
+ _this.callPlugins('onAutoplayStop');
2211
+ if (params.onAutoplayStop) _this.fireCallback(params.onAutoplayStop, _this);
2212
+ }
2213
+ };
2214
+ function autoplay() {
2215
+ autoplayTimeoutId = setTimeout(function () {
2216
+ if (params.loop) {
2217
+ _this.fixLoop();
2218
+ _this.swipeNext(true);
2219
+ }
2220
+ else if (!_this.swipeNext(true)) {
2221
+ if (!params.autoplayStopOnLast) _this.swipeTo(0);
2222
+ else {
2223
+ clearTimeout(autoplayTimeoutId);
2224
+ autoplayTimeoutId = undefined;
2225
+ }
2226
+ }
2227
+ _this.wrapperTransitionEnd(function () {
2228
+ if (typeof autoplayTimeoutId !== 'undefined') autoplay();
2229
+ });
2230
+ }, params.autoplay);
1996
2231
  }
1997
2232
  /*==================================================
1998
2233
  Loop
1999
2234
  ====================================================*/
2000
2235
  _this.loopCreated = false;
2001
- _this.removeLoopedSlides = function(){
2236
+ _this.removeLoopedSlides = function () {
2002
2237
  if (_this.loopCreated) {
2003
- for (var i=0; i<_this.slides.length; i++) {
2004
- if (_this.slides[i].getData('looped')===true) _this.wrapper.removeChild(_this.slides[i]);
2238
+ for (var i = 0; i < _this.slides.length; i++) {
2239
+ if (_this.slides[i].getData('looped') === true) _this.wrapper.removeChild(_this.slides[i]);
2005
2240
  }
2006
2241
  }
2007
- }
2008
- _this.createLoop = function(){
2009
- if (_this.slides.length==0) return;
2010
- _this.loopedSlides = params.slidesPerView+params.loopAdditionalSlides;
2242
+ };
2011
2243
 
2012
- var slideFirstHTML = '';
2013
- var slideLastHTML = '';
2244
+ _this.createLoop = function () {
2245
+ if (_this.slides.length === 0) return;
2246
+ if (params.slidesPerView === 'auto') {
2247
+ _this.loopedSlides = params.loopedSlides || 1;
2248
+ }
2249
+ else {
2250
+ _this.loopedSlides = params.slidesPerView + params.loopAdditionalSlides;
2251
+ }
2252
+
2253
+ if (_this.loopedSlides > _this.slides.length) {
2254
+ _this.loopedSlides = _this.slides.length;
2255
+ }
2256
+
2257
+ var slideFirstHTML = '',
2258
+ slideLastHTML = '',
2259
+ i;
2260
+ var slidesSetFullHTML = '';
2261
+ /**
2262
+ loopedSlides is too large if loopAdditionalSlides are set.
2263
+ Need to divide the slides by maximum number of slides existing.
2014
2264
 
2015
- //Grab First Slides
2016
- for (var i=0; i<_this.loopedSlides; i++) {
2017
- slideFirstHTML+=_this.slides[i].outerHTML
2265
+ @author Tomaz Lovrec <tomaz.lovrec@blanc-noir.at>
2266
+ */
2267
+ var numSlides = _this.slides.length;
2268
+ var fullSlideSets = Math.floor(_this.loopedSlides / numSlides);
2269
+ var remainderSlides = _this.loopedSlides % numSlides;
2270
+ // assemble full sets of slides
2271
+ for (i = 0; i < (fullSlideSets * numSlides); i++) {
2272
+ var j = i;
2273
+ if (i >= numSlides) {
2274
+ var over = Math.floor(i / numSlides);
2275
+ j = i - (numSlides * over);
2276
+ }
2277
+ slidesSetFullHTML += _this.slides[j].outerHTML;
2278
+ }
2279
+ // assemble remainder slides
2280
+ // assemble remainder appended to existing slides
2281
+ for (i = 0; i < remainderSlides;i++) {
2282
+ slideLastHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML);
2018
2283
  }
2019
- //Grab Last Slides
2020
- for (i=_this.slides.length-_this.loopedSlides; i<_this.slides.length; i++) {
2021
- slideLastHTML+=_this.slides[i].outerHTML
2284
+ // assemble slides that get preppended to existing slides
2285
+ for (i = numSlides - remainderSlides; i < numSlides;i++) {
2286
+ slideFirstHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML);
2022
2287
  }
2023
- wrapper.innerHTML = slideLastHTML + wrapper.innerHTML + slideFirstHTML;
2288
+ // assemble all slides
2289
+ var slides = slideFirstHTML + slidesSetFullHTML + wrapper.innerHTML + slidesSetFullHTML + slideLastHTML;
2290
+ // set the slides
2291
+ wrapper.innerHTML = slides;
2024
2292
 
2025
2293
  _this.loopCreated = true;
2026
2294
  _this.calcSlides();
2027
2295
 
2028
2296
  //Update Looped Slides with special class
2029
- for (i=0; i<_this.slides.length; i++) {
2030
- if (i<_this.loopedSlides || i>=_this.slides.length-_this.loopedSlides) _this.slides[i].setData('looped', true);
2297
+ for (i = 0; i < _this.slides.length; i++) {
2298
+ if (i < _this.loopedSlides || i >= _this.slides.length - _this.loopedSlides) _this.slides[i].setData('looped', true);
2031
2299
  }
2032
2300
  _this.callPlugins('onCreateLoop');
2033
2301
 
2034
- }
2035
- _this.fixLoop = function(){
2302
+ };
2303
+
2304
+ _this.fixLoop = function () {
2305
+ var newIndex;
2036
2306
  //Fix For Negative Oversliding
2037
2307
  if (_this.activeIndex < _this.loopedSlides) {
2038
- var newIndex = _this.slides.length - _this.loopedSlides*3 + _this.activeIndex;
2039
- _this.swipeTo(newIndex, 0, false)
2308
+ newIndex = _this.slides.length - _this.loopedSlides * 3 + _this.activeIndex;
2309
+ _this.swipeTo(newIndex, 0, false);
2040
2310
  }
2041
2311
  //Fix For Positive Oversliding
2042
- else if (_this.activeIndex > _this.slides.length - params.slidesPerView*2) {
2043
- var newIndex = -_this.slides.length + _this.activeIndex + _this.loopedSlides
2044
- _this.swipeTo(newIndex,0, false)
2312
+ else if ((params.slidesPerView === 'auto' && _this.activeIndex >= _this.loopedSlides * 2) || (_this.activeIndex > _this.slides.length - params.slidesPerView * 2)) {
2313
+ newIndex = -_this.slides.length + _this.activeIndex + _this.loopedSlides;
2314
+ _this.swipeTo(newIndex, 0, false);
2045
2315
  }
2046
- }
2316
+ };
2317
+
2047
2318
  /*==================================================
2048
2319
  Slides Loader
2049
2320
  ====================================================*/
2050
- _this.loadSlides = function(){
2321
+ _this.loadSlides = function () {
2051
2322
  var slidesHTML = '';
2052
2323
  _this.activeLoaderIndex = 0;
2053
2324
  var slides = params.loader.slides;
2054
- var slidesToLoad = params.loader.loadAllSlides ? slides.length : params.slidesPerView*(1+params.loader.surroundGroups);
2055
- for (var i=0; i< slidesToLoad; i++) {
2056
- if (params.loader.slidesHTMLType=='outer') slidesHTML+=slides[i];
2325
+ var slidesToLoad = params.loader.loadAllSlides ? slides.length : params.slidesPerView * (1 + params.loader.surroundGroups);
2326
+ for (var i = 0; i < slidesToLoad; i++) {
2327
+ if (params.loader.slidesHTMLType === 'outer') slidesHTML += slides[i];
2057
2328
  else {
2058
- slidesHTML+='<'+params.slideElement+' class="'+params.slideClass+'" data-swiperindex="'+i+'">'+slides[i]+'</'+params.slideElement+'>';
2329
+ slidesHTML += '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + '</' + params.slideElement + '>';
2059
2330
  }
2060
2331
  }
2061
2332
  _this.wrapper.innerHTML = slidesHTML;
@@ -2064,55 +2335,58 @@ var Swiper = function (selector, params) {
2064
2335
  if (!params.loader.loadAllSlides) {
2065
2336
  _this.wrapperTransitionEnd(_this.reloadSlides, true);
2066
2337
  }
2067
- }
2068
- _this.reloadSlides = function(){
2338
+ };
2339
+
2340
+ _this.reloadSlides = function () {
2069
2341
  var slides = params.loader.slides;
2070
- var newActiveIndex = parseInt(_this.activeSlide().data('swiperindex'),10)
2071
- if (newActiveIndex<0 || newActiveIndex>slides.length-1) return //<-- Exit
2342
+ var newActiveIndex = parseInt(_this.activeSlide().data('swiperindex'), 10);
2343
+ if (newActiveIndex < 0 || newActiveIndex > slides.length - 1) return; //<-- Exit
2072
2344
  _this.activeLoaderIndex = newActiveIndex;
2073
- var firstIndex = Math.max(0, newActiveIndex - params.slidesPerView*params.loader.surroundGroups)
2074
- var lastIndex = Math.min(newActiveIndex+params.slidesPerView*(1+params.loader.surroundGroups)-1, slides.length-1)
2345
+ var firstIndex = Math.max(0, newActiveIndex - params.slidesPerView * params.loader.surroundGroups);
2346
+ var lastIndex = Math.min(newActiveIndex + params.slidesPerView * (1 + params.loader.surroundGroups) - 1, slides.length - 1);
2075
2347
  //Update Transforms
2076
- if (newActiveIndex>0) {
2077
- var newTransform = -slideSize*(newActiveIndex-firstIndex)
2078
- if (isH) _this.setWrapperTranslate(newTransform,0,0)
2079
- else _this.setWrapperTranslate(0,newTransform,0)
2080
- _this.setWrapperTransition(0)
2348
+ if (newActiveIndex > 0) {
2349
+ var newTransform = -slideSize * (newActiveIndex - firstIndex);
2350
+ _this.setWrapperTranslate(newTransform);
2351
+ _this.setWrapperTransition(0);
2081
2352
  }
2353
+ var i; // loop index
2082
2354
  //New Slides
2083
- if (params.loader.logic==='reload') {
2355
+ if (params.loader.logic === 'reload') {
2084
2356
  _this.wrapper.innerHTML = '';
2085
2357
  var slidesHTML = '';
2086
- for (var i = firstIndex; i<=lastIndex; i++) {
2087
- slidesHTML += params.loader.slidesHTMLType == 'outer' ? slides[i] : '<'+params.slideElement+' class="'+params.slideClass+'" data-swiperindex="'+i+'">'+slides[i]+'</'+params.slideElement+'>';
2358
+ for (i = firstIndex; i <= lastIndex; i++) {
2359
+ slidesHTML += params.loader.slidesHTMLType === 'outer' ? slides[i] : '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + '</' + params.slideElement + '>';
2088
2360
  }
2089
2361
  _this.wrapper.innerHTML = slidesHTML;
2090
2362
  }
2091
2363
  else {
2092
- var minExistIndex=1000;
2093
- var maxExistIndex=0;
2094
- for (var i=0; i<_this.slides.length; i++) {
2364
+ var minExistIndex = 1000;
2365
+ var maxExistIndex = 0;
2366
+
2367
+ for (i = 0; i < _this.slides.length; i++) {
2095
2368
  var index = _this.slides[i].data('swiperindex');
2096
- if (index<firstIndex || index>lastIndex) {
2369
+ if (index < firstIndex || index > lastIndex) {
2097
2370
  _this.wrapper.removeChild(_this.slides[i]);
2098
2371
  }
2099
2372
  else {
2100
- minExistIndex = Math.min(index, minExistIndex)
2101
- maxExistIndex = Math.max(index, maxExistIndex)
2373
+ minExistIndex = Math.min(index, minExistIndex);
2374
+ maxExistIndex = Math.max(index, maxExistIndex);
2102
2375
  }
2103
2376
  }
2104
- for (var i=firstIndex; i<=lastIndex; i++) {
2105
- if (i<minExistIndex) {
2106
- var newSlide = document.createElement(params.slideElement);
2377
+ for (i = firstIndex; i <= lastIndex; i++) {
2378
+ var newSlide;
2379
+ if (i < minExistIndex) {
2380
+ newSlide = document.createElement(params.slideElement);
2107
2381
  newSlide.className = params.slideClass;
2108
- newSlide.setAttribute('data-swiperindex',i);
2382
+ newSlide.setAttribute('data-swiperindex', i);
2109
2383
  newSlide.innerHTML = slides[i];
2110
2384
  _this.wrapper.insertBefore(newSlide, _this.wrapper.firstChild);
2111
2385
  }
2112
- if (i>maxExistIndex) {
2113
- var newSlide = document.createElement(params.slideElement);
2386
+ if (i > maxExistIndex) {
2387
+ newSlide = document.createElement(params.slideElement);
2114
2388
  newSlide.className = params.slideClass;
2115
- newSlide.setAttribute('data-swiperindex',i);
2389
+ newSlide.setAttribute('data-swiperindex', i);
2116
2390
  newSlide.innerHTML = slides[i];
2117
2391
  _this.wrapper.appendChild(newSlide);
2118
2392
  }
@@ -2120,13 +2394,14 @@ var Swiper = function (selector, params) {
2120
2394
  }
2121
2395
  //reInit
2122
2396
  _this.reInit(true);
2123
- }
2397
+ };
2398
+
2124
2399
  /*==================================================
2125
2400
  Make Swiper
2126
2401
  ====================================================*/
2127
- function makeSwiper(){
2402
+ function makeSwiper() {
2128
2403
  _this.calcSlides();
2129
- if (params.loader.slides.length>0 && _this.slides.length==0) {
2404
+ if (params.loader.slides.length > 0 && _this.slides.length === 0) {
2130
2405
  _this.loadSlides();
2131
2406
  }
2132
2407
  if (params.loop) {
@@ -2134,11 +2409,12 @@ var Swiper = function (selector, params) {
2134
2409
  }
2135
2410
  _this.init();
2136
2411
  initEvents();
2137
- if (params.pagination && params.createPagination) {
2412
+ if (params.pagination) {
2138
2413
  _this.createPagination(true);
2139
2414
  }
2140
- if (params.loop || params.initialSlide>0) {
2141
- _this.swipeTo( params.initialSlide, 0, false );
2415
+
2416
+ if (params.loop || params.initialSlide > 0) {
2417
+ _this.swipeTo(params.initialSlide, 0, false);
2142
2418
  }
2143
2419
  else {
2144
2420
  _this.updateActiveSlide(0);
@@ -2146,109 +2422,141 @@ var Swiper = function (selector, params) {
2146
2422
  if (params.autoplay) {
2147
2423
  _this.startAutoplay();
2148
2424
  }
2425
+ /**
2426
+ * Set center slide index.
2427
+ *
2428
+ * @author Tomaz Lovrec <tomaz.lovrec@gmail.com>
2429
+ */
2430
+ _this.centerIndex = _this.activeIndex;
2149
2431
 
2432
+ // Callbacks
2433
+ if (params.onSwiperCreated) _this.fireCallback(params.onSwiperCreated, _this);
2434
+ _this.callPlugins('onSwiperCreated');
2150
2435
  }
2436
+
2151
2437
  makeSwiper();
2152
- }
2438
+ };
2153
2439
 
2154
2440
  Swiper.prototype = {
2155
2441
  plugins : {},
2442
+
2156
2443
  /*==================================================
2157
2444
  Wrapper Operations
2158
2445
  ====================================================*/
2159
- wrapperTransitionEnd : function(callback, permanent) {
2160
- var a = this
2161
- var el = a.wrapper
2162
- var events = ['webkitTransitionEnd','transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'];
2446
+ wrapperTransitionEnd : function (callback, permanent) {
2447
+ 'use strict';
2448
+ var a = this,
2449
+ el = a.wrapper,
2450
+ events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
2451
+ i;
2452
+
2163
2453
  function fireCallBack() {
2164
- callback(a)
2165
- if (a.params.queueEndCallbacks) a._queueEndCallbacks = false
2454
+ callback(a);
2455
+ if (a.params.queueEndCallbacks) a._queueEndCallbacks = false;
2166
2456
  if (!permanent) {
2167
- for (var i=0; i<events.length; i++) {
2168
- a.h.removeEventListener(el,events[i], fireCallBack, false)
2457
+ for (i = 0; i < events.length; i++) {
2458
+ a.h.removeEventListener(el, events[i], fireCallBack);
2169
2459
  }
2170
2460
  }
2171
2461
  }
2462
+
2172
2463
  if (callback) {
2173
- for (var i=0; i<events.length; i++) {
2174
- a.h.addEventListener(el,events[i], fireCallBack, false)
2464
+ for (i = 0; i < events.length; i++) {
2465
+ a.h.addEventListener(el, events[i], fireCallBack);
2175
2466
  }
2176
2467
  }
2177
2468
  },
2178
2469
 
2179
- getWrapperTranslate : function(axis){
2180
- var el = this.wrapper
2181
- var matrix;
2182
- var curTransform;
2183
- if (window.WebKitCSSMatrix) {
2184
- var transformMatrix = new WebKitCSSMatrix(window.getComputedStyle(el, null).webkitTransform)
2185
- matrix = transformMatrix.toString().split(',');
2186
- }
2187
- else {
2188
- var transformMatrix = window.getComputedStyle(el, null).MozTransform || window.getComputedStyle(el, null).OTransform || window.getComputedStyle(el, null).MsTransform || window.getComputedStyle(el, null).msTransform || window.getComputedStyle(el, null).transform|| window.getComputedStyle(el, null).getPropertyValue("transform").replace("translate(", "matrix(1, 0, 0, 1,");
2189
- matrix = transformMatrix.toString().split(',');
2470
+ getWrapperTranslate : function (axis) {
2471
+ 'use strict';
2472
+ var el = this.wrapper,
2473
+ matrix, curTransform, curStyle, transformMatrix;
2190
2474
 
2475
+ // automatic axis detection
2476
+ if (typeof axis === 'undefined') {
2477
+ axis = this.params.mode === 'horizontal' ? 'x' : 'y';
2191
2478
  }
2192
- if (this.params.useCSS3Transforms) {
2193
- if (axis=='x') {
2194
- //Crazy IE10 Matrix
2195
- if (matrix.length==16)
2196
- curTransform = parseFloat( matrix[12] )
2479
+
2480
+ if (this.support.transforms && this.params.useCSS3Transforms) {
2481
+ curStyle = window.getComputedStyle(el, null);
2482
+ if (window.WebKitCSSMatrix) {
2483
+ transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform);
2484
+ }
2485
+ else {
2486
+ transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
2487
+ matrix = transformMatrix.toString().split(',');
2488
+ }
2489
+
2490
+ if (axis === 'x') {
2197
2491
  //Latest Chrome and webkits Fix
2198
- else if (window.WebKitCSSMatrix)
2199
- curTransform = transformMatrix.m41
2492
+ if (window.WebKitCSSMatrix)
2493
+ curTransform = transformMatrix.m41;
2494
+ //Crazy IE10 Matrix
2495
+ else if (matrix.length === 16)
2496
+ curTransform = parseFloat(matrix[12]);
2200
2497
  //Normal Browsers
2201
2498
  else
2202
- curTransform = parseFloat( matrix[4] )
2499
+ curTransform = parseFloat(matrix[4]);
2203
2500
  }
2204
- if (axis=='y') {
2205
- //Crazy IE10 Matrix
2206
- if (matrix.length==16)
2207
- curTransform = parseFloat( matrix[13] )
2501
+ if (axis === 'y') {
2208
2502
  //Latest Chrome and webkits Fix
2209
- else if (window.WebKitCSSMatrix)
2210
- curTransform = transformMatrix.m42
2503
+ if (window.WebKitCSSMatrix)
2504
+ curTransform = transformMatrix.m42;
2505
+ //Crazy IE10 Matrix
2506
+ else if (matrix.length === 16)
2507
+ curTransform = parseFloat(matrix[13]);
2211
2508
  //Normal Browsers
2212
2509
  else
2213
- curTransform = parseFloat( matrix[5] )
2510
+ curTransform = parseFloat(matrix[5]);
2214
2511
  }
2215
2512
  }
2216
2513
  else {
2217
- if (axis=='x') curTransform = parseFloat(el.style.left,10) || 0
2218
- if (axis=='y') curTransform = parseFloat(el.style.top,10) || 0
2514
+ if (axis === 'x') curTransform = parseFloat(el.style.left, 10) || 0;
2515
+ if (axis === 'y') curTransform = parseFloat(el.style.top, 10) || 0;
2219
2516
  }
2220
2517
  return curTransform || 0;
2221
2518
  },
2222
2519
 
2223
- setWrapperTranslate : function(x,y,z) {
2224
- var es = this.wrapper.style
2225
- x=x||0;
2226
- y=y||0;
2227
- z=z||0;
2228
- if (this.params.useCSS3Transforms) {
2229
- if (this.support.transforms3d) {
2230
- es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = 'translate3d('+x+'px, '+y+'px, '+z+'px)'
2231
- }
2232
- else {
2520
+ setWrapperTranslate : function (x, y, z) {
2521
+ 'use strict';
2522
+ var es = this.wrapper.style,
2523
+ coords = {x: 0, y: 0, z: 0},
2524
+ translate;
2233
2525
 
2234
- es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = 'translate('+x+'px, '+y+'px)'
2235
- if (!this.support.transforms) {
2236
- es.left = x+'px'
2237
- es.top = y+'px'
2238
- }
2526
+ // passed all coordinates
2527
+ if (arguments.length === 3) {
2528
+ coords.x = x;
2529
+ coords.y = y;
2530
+ coords.z = z;
2531
+ }
2532
+
2533
+ // passed one coordinate and optional axis
2534
+ else {
2535
+ if (typeof y === 'undefined') {
2536
+ y = this.params.mode === 'horizontal' ? 'x' : 'y';
2239
2537
  }
2538
+ coords[y] = x;
2539
+ }
2540
+
2541
+ if (this.support.transforms && this.params.useCSS3Transforms) {
2542
+ translate = this.support.transforms3d ? 'translate3d(' + coords.x + 'px, ' + coords.y + 'px, ' + coords.z + 'px)' : 'translate(' + coords.x + 'px, ' + coords.y + 'px)';
2543
+ es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = translate;
2240
2544
  }
2241
2545
  else {
2242
- es.left = x+'px';
2243
- es.top = y+'px';
2546
+ es.left = coords.x + 'px';
2547
+ es.top = coords.y + 'px';
2244
2548
  }
2245
- this.callPlugins('onSetWrapperTransform', {x:x, y:y, z:z})
2549
+ this.callPlugins('onSetWrapperTransform', coords);
2550
+ if (this.params.onSetWrapperTransform) this.fireCallback(this.params.onSetWrapperTransform, this, coords);
2246
2551
  },
2247
2552
 
2248
- setWrapperTransition : function(duration) {
2249
- var es = this.wrapper.style
2250
- es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration/1000+'s';
2251
- this.callPlugins('onSetWrapperTransition', {duration: duration})
2553
+ setWrapperTransition : function (duration) {
2554
+ 'use strict';
2555
+ var es = this.wrapper.style;
2556
+ es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = (duration / 1000) + 's';
2557
+ this.callPlugins('onSetWrapperTransition', {duration: duration});
2558
+ if (this.params.onSetWrapperTransition) this.fireCallback(this.params.onSetWrapperTransition, this, duration);
2559
+
2252
2560
  },
2253
2561
 
2254
2562
  /*==================================================
@@ -2256,29 +2564,32 @@ Swiper.prototype = {
2256
2564
  ====================================================*/
2257
2565
  h : {
2258
2566
  getWidth: function (el, outer) {
2259
- var width = window.getComputedStyle(el, null).getPropertyValue('width')
2567
+ 'use strict';
2568
+ var width = window.getComputedStyle(el, null).getPropertyValue('width');
2260
2569
  var returnWidth = parseFloat(width);
2261
2570
  //IE Fixes
2262
- if(isNaN(returnWidth) || width.indexOf('%')>0) {
2571
+ if (isNaN(returnWidth) || width.indexOf('%') > 0) {
2263
2572
  returnWidth = el.offsetWidth - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right'));
2264
2573
  }
2265
- if (outer) returnWidth += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right'))
2574
+ if (outer) returnWidth += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right'));
2266
2575
 
2267
2576
  return returnWidth;
2268
2577
  },
2269
- getHeight: function(el, outer) {
2578
+ getHeight: function (el, outer) {
2579
+ 'use strict';
2270
2580
  if (outer) return el.offsetHeight;
2271
2581
 
2272
- var height = window.getComputedStyle(el, null).getPropertyValue('height')
2582
+ var height = window.getComputedStyle(el, null).getPropertyValue('height');
2273
2583
  var returnHeight = parseFloat(height);
2274
2584
  //IE Fixes
2275
- if(isNaN(returnHeight) || height.indexOf('%')>0) {
2585
+ if (isNaN(returnHeight) || height.indexOf('%') > 0) {
2276
2586
  returnHeight = el.offsetHeight - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom'));
2277
2587
  }
2278
- if (outer) returnHeight += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom'))
2588
+ if (outer) returnHeight += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom'));
2279
2589
  return returnHeight;
2280
2590
  },
2281
- getOffset: function(el) {
2591
+ getOffset: function (el) {
2592
+ 'use strict';
2282
2593
  var box = el.getBoundingClientRect();
2283
2594
  var body = document.body;
2284
2595
  var clientTop = el.clientTop || body.clientTop || 0;
@@ -2295,126 +2606,163 @@ Swiper.prototype = {
2295
2606
  left: box.left + scrollLeft - clientLeft
2296
2607
  };
2297
2608
  },
2298
- windowWidth : function() {
2299
- if (window.innerWidth) return window.innerWidth
2609
+ windowWidth : function () {
2610
+ 'use strict';
2611
+ if (window.innerWidth) return window.innerWidth;
2300
2612
  else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
2301
2613
  },
2302
- windowHeight : function() {
2303
- if (window.innerHeight) return window.innerHeight
2614
+ windowHeight : function () {
2615
+ 'use strict';
2616
+ if (window.innerHeight) return window.innerHeight;
2304
2617
  else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
2305
2618
  },
2306
- windowScroll : function() {
2307
- var left=0, top=0;
2308
- if (typeof pageYOffset != 'undefined') {
2619
+ windowScroll : function () {
2620
+ 'use strict';
2621
+ if (typeof pageYOffset !== 'undefined') {
2309
2622
  return {
2310
2623
  left: window.pageXOffset,
2311
2624
  top: window.pageYOffset
2312
- }
2625
+ };
2313
2626
  }
2314
2627
  else if (document.documentElement) {
2315
2628
  return {
2316
2629
  left: document.documentElement.scrollLeft,
2317
2630
  top: document.documentElement.scrollTop
2318
- }
2631
+ };
2319
2632
  }
2320
2633
  },
2321
2634
 
2322
2635
  addEventListener : function (el, event, listener, useCapture) {
2636
+ 'use strict';
2637
+ if (typeof useCapture === 'undefined') {
2638
+ useCapture = false;
2639
+ }
2640
+
2323
2641
  if (el.addEventListener) {
2324
- el.addEventListener(event, listener, useCapture)
2642
+ el.addEventListener(event, listener, useCapture);
2325
2643
  }
2326
2644
  else if (el.attachEvent) {
2327
- el.attachEvent('on'+event, listener)
2645
+ el.attachEvent('on' + event, listener);
2328
2646
  }
2329
2647
  },
2648
+
2330
2649
  removeEventListener : function (el, event, listener, useCapture) {
2650
+ 'use strict';
2651
+ if (typeof useCapture === 'undefined') {
2652
+ useCapture = false;
2653
+ }
2654
+
2331
2655
  if (el.removeEventListener) {
2332
- el.removeEventListener(event, listener, useCapture)
2656
+ el.removeEventListener(event, listener, useCapture);
2333
2657
  }
2334
2658
  else if (el.detachEvent) {
2335
- el.detachEvent('on'+event, listener)
2659
+ el.detachEvent('on' + event, listener);
2336
2660
  }
2337
2661
  }
2338
2662
  },
2339
2663
  setTransform : function (el, transform) {
2340
- var es = el.style
2341
- es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transform
2664
+ 'use strict';
2665
+ var es = el.style;
2666
+ es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transform;
2342
2667
  },
2343
2668
  setTranslate : function (el, translate) {
2344
- var es = el.style
2669
+ 'use strict';
2670
+ var es = el.style;
2345
2671
  var pos = {
2346
2672
  x : translate.x || 0,
2347
2673
  y : translate.y || 0,
2348
2674
  z : translate.z || 0
2349
2675
  };
2350
- var transformString = this.support.transforms3d ? 'translate3d('+(pos.x)+'px,'+(pos.y)+'px,'+(pos.z)+'px)' : 'translate('+(pos.x)+'px,'+(pos.y)+'px)';
2676
+ var transformString = this.support.transforms3d ? 'translate3d(' + (pos.x) + 'px,' + (pos.y) + 'px,' + (pos.z) + 'px)' : 'translate(' + (pos.x) + 'px,' + (pos.y) + 'px)';
2351
2677
  es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transformString;
2352
2678
  if (!this.support.transforms) {
2353
- es.left = pos.x+'px'
2354
- es.top = pos.y+'px'
2679
+ es.left = pos.x + 'px';
2680
+ es.top = pos.y + 'px';
2355
2681
  }
2356
2682
  },
2357
2683
  setTransition : function (el, duration) {
2358
- var es = el.style
2359
- es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration+'ms';
2684
+ 'use strict';
2685
+ var es = el.style;
2686
+ es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration + 'ms';
2360
2687
  },
2361
2688
  /*==================================================
2362
2689
  Feature Detection
2363
2690
  ====================================================*/
2364
2691
  support: {
2365
2692
 
2366
- touch : (window.Modernizr && Modernizr.touch===true) || (function() {
2367
- return !!(("ontouchstart" in window) || window.DocumentTouch && document instanceof DocumentTouch);
2693
+ touch : (window.Modernizr && Modernizr.touch === true) || (function () {
2694
+ 'use strict';
2695
+ return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
2368
2696
  })(),
2369
2697
 
2370
- transforms3d : (window.Modernizr && Modernizr.csstransforms3d===true) || (function() {
2371
- var div = document.createElement('div');
2372
- return ( "webkitPerspective" in div.style || "MozPerspective" in div.style || "OPerspective" in div.style || "MsPerspective" in div.style || "perspective" in div.style );
2698
+ transforms3d : (window.Modernizr && Modernizr.csstransforms3d === true) || (function () {
2699
+ 'use strict';
2700
+ var div = document.createElement('div').style;
2701
+ return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
2373
2702
  })(),
2374
2703
 
2375
- transforms : (window.Modernizr && Modernizr.csstransforms===true) || (function(){
2376
- var div = document.createElement('div').style
2377
- return ('transform' in div) || ('WebkitTransform' in div) || ('MozTransform' in div) || ('msTransform' in div) || ('MsTransform' in div) || ('OTransform' in div);
2704
+ transforms : (window.Modernizr && Modernizr.csstransforms === true) || (function () {
2705
+ 'use strict';
2706
+ var div = document.createElement('div').style;
2707
+ return ('transform' in div || 'WebkitTransform' in div || 'MozTransform' in div || 'msTransform' in div || 'MsTransform' in div || 'OTransform' in div);
2378
2708
  })(),
2379
2709
 
2380
- transitions : (window.Modernizr && Modernizr.csstransitions===true) || (function(){
2381
- var div = document.createElement('div').style
2382
- return ('transition' in div) || ('WebkitTransition' in div) || ('MozTransition' in div) || ('msTransition' in div) || ('MsTransition' in div) || ('OTransition' in div);
2710
+ transitions : (window.Modernizr && Modernizr.csstransitions === true) || (function () {
2711
+ 'use strict';
2712
+ var div = document.createElement('div').style;
2713
+ return ('transition' in div || 'WebkitTransition' in div || 'MozTransition' in div || 'msTransition' in div || 'MsTransition' in div || 'OTransition' in div);
2714
+ })(),
2715
+
2716
+ classList : (function () {
2717
+ 'use strict';
2718
+ var div = document.createElement('div').style;
2719
+ return 'classList' in div;
2383
2720
  })()
2384
2721
  },
2385
2722
 
2386
2723
  browser : {
2387
2724
 
2388
- ie8 : (function(){
2725
+ ie8 : (function () {
2726
+ 'use strict';
2389
2727
  var rv = -1; // Return value assumes failure.
2390
- if (navigator.appName == 'Microsoft Internet Explorer') {
2728
+ if (navigator.appName === 'Microsoft Internet Explorer') {
2391
2729
  var ua = navigator.userAgent;
2392
- var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
2393
- if (re.exec(ua) != null)
2730
+ var re = new RegExp(/MSIE ([0-9]{1,}[\.0-9]{0,})/);
2731
+ if (re.exec(ua) !== null)
2394
2732
  rv = parseFloat(RegExp.$1);
2395
2733
  }
2396
- return rv != -1 && rv < 9;
2734
+ return rv !== -1 && rv < 9;
2397
2735
  })(),
2398
2736
 
2399
- ie10 : window.navigator.msPointerEnabled
2737
+ ie10 : window.navigator.msPointerEnabled,
2738
+ ie11 : window.navigator.pointerEnabled
2400
2739
  }
2401
- }
2740
+ };
2402
2741
 
2403
2742
  /*=========================
2404
2743
  jQuery & Zepto Plugins
2405
2744
  ===========================*/
2406
- if (window.jQuery||window.Zepto) {
2407
- (function($){
2408
- $.fn.swiper = function(params) {
2409
- var s = new Swiper($(this)[0], params)
2410
- $(this).data('swiper',s);
2411
- return s
2412
- }
2413
- })(window.jQuery||window.Zepto)
2745
+ if (window.jQuery || window.Zepto) {
2746
+ (function ($) {
2747
+ 'use strict';
2748
+ $.fn.swiper = function (params) {
2749
+ var s = new Swiper($(this)[0], params);
2750
+ $(this).data('swiper', s);
2751
+ return s;
2752
+ };
2753
+ })(window.jQuery || window.Zepto);
2414
2754
  }
2415
2755
 
2416
2756
  // component
2417
- if ( typeof( module ) !== 'undefined' )
2757
+ if (typeof(module) !== 'undefined')
2418
2758
  {
2419
2759
  module.exports = Swiper;
2420
2760
  }
2761
+
2762
+ // requirejs support
2763
+ if (typeof define === 'function' && define.amd) {
2764
+ define([], function () {
2765
+ 'use strict';
2766
+ return Swiper;
2767
+ });
2768
+ }