forked from nolimits4web/swiper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidangerous.swiper-1.9.4.js
1553 lines (1386 loc) · 56.4 KB
/
idangerous.swiper-1.9.4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Swiper 1.9.4 - Mobile Touch Slider
* http://www.idangero.us/sliders/swiper/
*
* Copyright 2012-2013, Vladimir Kharlampidi
* The iDangero.us
* http://www.idangero.us/
*
* Licensed under GPL & MIT
*
* Updated on: May 23, 2013
*/
var Swiper = function (selector, params, callback) {
/*=========================
A little bit dirty but required part for IE8 and old FF support
===========================*/
if (!window.addEventListener) {
if (!window.Element)
Element = function () { };
Element.prototype.addEventListener = HTMLDocument.prototype.addEventListener = addEventListener = function (type, listener, useCapture) { this.attachEvent('on' + type, listener); }
Element.prototype.removeEventListener = HTMLDocument.prototype.removeEventListener = removeEventListener = function (type, listener, useCapture) { this.detachEvent('on' + type, listener); }
}
if (document.body.__defineGetter__) {
if (HTMLElement) {
var element = HTMLElement.prototype;
if (element.__defineGetter__)
element.__defineGetter__("outerHTML", function () { return new XMLSerializer().serializeToString(this); } );
}
}
if (!window.getComputedStyle) {
window.getComputedStyle = function (el, pseudo) {
this.el = el;
this.getPropertyValue = function (prop) {
var re = /(\-([a-z]){1})/g;
if (prop == 'float') prop = 'styleFloat';
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
}
return el.currentStyle[prop] ? el.currentStyle[prop] : null;
}
return this;
}
}
/* End Of Polyfills*/
if(!(selector.nodeType))
if (!document.querySelectorAll||document.querySelectorAll(selector).length==0) return;
function dQ(s) {
return document.querySelectorAll(s)
}
var _this = this
_this.touches = {};
_this.positions = {
current : 0
};
_this.id = (new Date()).getTime();
_this.container = (selector.nodeType) ? selector : dQ(selector)[0];
_this.times = {};
_this.isTouched = false;
_this.realIndex = 0;
_this.activeSlide = 0;
_this.activeIndex = 0;
_this.previousSlide = null;
_this.previousIndex = null;
_this.langDirection = window.getComputedStyle(_this.container, null).getPropertyValue('direction')
/*=========================
New Support Object
===========================*/
_this.support = {
touch : _this.isSupportTouch(),
threeD : _this.isSupport3D(),
transitions : _this.isSupportTransitions()
}
//For fallback with older versions
_this.use3D = _this.support.threeD;
/*=========================
Default Parameters
===========================*/
var defaults = {
mode : 'horizontal',
ratio : 1,
speed : 300,
freeMode : false,
freeModeFluid : false,
slidesPerSlide : 1,
slidesPerGroup : 1,
simulateTouch : true,
followFinger : true,
shortSwipes : true,
moveStartThreshold:false,
autoPlay:false,
onlyExternal : false,
createPagination : true,
pagination : false,
resistance : true,
nopeek : false,
scrollContainer : false,
preventLinks : true,
preventClassNoSwiping : true,
initialSlide: 0,
keyboardControl: false,
mousewheelControl : false,
resizeEvent : 'auto', //or 'resize' or 'orientationchange'
useCSS3Transforms : true,
queueStartCallbacks : false,
queueEndCallbacks : false,
//Namespace
slideElement : 'div',
slideClass : 'swiper-slide',
wrapperClass : 'swiper-wrapper',
paginationClass: 'swiper-pagination-switch' ,
paginationActiveClass : 'swiper-active-switch'
}
params = params || {};
for (var prop in defaults) {
if (! (prop in params)) {
params[prop] = defaults[prop]
}
}
_this.params = params;
if (params.scrollContainer) {
params.freeMode = true;
params.freeModeFluid = true;
}
var _widthFromCSS = false
if (params.slidesPerSlide=='auto') {
_widthFromCSS = true;
params.slidesPerSlide = 1;
}
//Default Vars
var wrapper, isHorizontal,
slideSize, numOfSlides, wrapperSize, direction, isScrolling, containerSize;
//Define wrapper
for (var i = _this.container.childNodes.length - 1; i >= 0; i--) {
if (_this.container.childNodes[i].className) {
var _wrapperClasses = _this.container.childNodes[i].className.split(' ')
for (var j = 0; j < _wrapperClasses.length; j++) {
if (_wrapperClasses[j]===params.wrapperClass) {
wrapper = _this.container.childNodes[i]
}
};
}
};
_this.wrapper = wrapper;
//Mode
isHorizontal = params.mode == 'horizontal';
//Define Touch Events
_this.touchEvents = {
touchStart : _this.support.touch || !params.simulateTouch ? 'touchstart' : (_this.ie10 ? 'MSPointerDown' : 'mousedown'),
touchMove : _this.support.touch || !params.simulateTouch ? 'touchmove' : (_this.ie10 ? 'MSPointerMove' : 'mousemove'),
touchEnd : _this.support.touch || !params.simulateTouch ? 'touchend' : (_this.ie10 ? 'MSPointerUp' : 'mouseup')
};
/*=========================
Slide API
===========================*/
_this._extendSwiperSlide = function (el) {
el.append = function () {
_this.wrapper.appendChild(el);
_this.reInit();
return el;
}
el.prepend = function () {
_this.wrapper.insertBefore(el, _this.wrapper.firstChild)
_this.reInit();
return el;
}
el.insertAfter = function (index) {
if(typeof index === 'undefined') return false;
var beforeSlide = _this.slides[index+1]
_this.wrapper.insertBefore(el, beforeSlide)
_this.reInit();
return el;
}
el.clone = function () {
return _this._extendSwiperSlide(el.cloneNode(true))
}
el.remove = function () {
_this.wrapper.removeChild(el);
_this.reInit()
}
el.html = function (html) {
if (typeof html === 'undefined') {
return el.innerHTML
}
else {
el.innerHTML = html;
return el;
}
}
el.index = function () {
var index
for (var i = _this.slides.length - 1; i >= 0; i--) {
if(el==_this.slides[i]) index = i
};
return index;
}
el.isActive = function () {
if (el.index() == _this.activeIndex) return true;
else return false;
}
if (!el.swiperSlideDataStorage) el.swiperSlideDataStorage={};
el.getData = function (name) {
return el.swiperSlideDataStorage[name]
}
el.setData = function (name, value) {
el.swiperSlideDataStorage[name] = value;
return el;
}
el.data = function (name, value) {
if (!value) {
return el.getAttribute('data-'+name);
}
else {
el.setAttribute('data-'+name,value);
return el;
}
}
return el;
}
//Calculate information about slides
_this._calcSlides = function () {
var oldNumber = _this.slides ? _this.slides.length : false;
_this.slides = []
for (var i = 0; i < _this.wrapper.childNodes.length; i++) {
if (_this.wrapper.childNodes[i].className) {
var _slideClasses = _this.wrapper.childNodes[i].className.split(' ')
for (var j = 0; j < _slideClasses.length; j++) {
if(_slideClasses[j]===params.slideClass) _this.slides.push(_this.wrapper.childNodes[i])
};
}
};
for (var i = _this.slides.length - 1; i >= 0; i--) {
_this._extendSwiperSlide(_this.slides[i]);
};
if (!oldNumber) return;
if(oldNumber!=_this.slides.length && _this.createPagination) {
// Number of slides has been changed
_this.createPagination();
_this.callPlugins('numberOfSlidesChanged')
}
/*
if (_this.langDirection=='rtl') {
for (var i = 0; i < _this.slides.length; i++) {
_this.slides[i].style.float="right"
};
}
*/
}
_this._calcSlides();
//Create Slide
_this.createSlide = function (html, slideClassList, el) {
var slideClassList = slideClassList || _this.params.slideClass;
var el = el||params.slideElement;
var newSlide = document.createElement(el)
newSlide.innerHTML = html||'';
newSlide.className = slideClassList;
return _this._extendSwiperSlide(newSlide);
}
//Append Slide
_this.appendSlide = function (html, slideClassList, el) {
if (!html) return;
if (html.nodeType) {
return _this._extendSwiperSlide(html).append()
}
else {
return _this.createSlide(html, slideClassList, el).append()
}
}
_this.prependSlide = function (html, slideClassList, el) {
if (!html) return;
if (html.nodeType) {
return _this._extendSwiperSlide(html).prepend()
}
else {
return _this.createSlide(html, slideClassList, el).prepend()
}
}
_this.insertSlideAfter = function (index, html, slideClassList, el) {
if (!index) return false;
if (html.nodeType) {
return _this._extendSwiperSlide(html).insertAfter(index)
}
else {
return _this.createSlide(html, slideClassList, el).insertAfter(index)
}
}
_this.removeSlide = function (index) {
if (_this.slides[index]) {
_this.slides[index].remove()
return true;
}
else return false;
}
_this.removeLastSlide = function () {
if (_this.slides.length>0) {
_this.slides[ (_this.slides.length-1) ].remove();
return true
}
else {
return false
}
}
_this.removeAllSlides = function () {
for (var i = _this.slides.length - 1; i >= 0; i--) {
_this.slides[i].remove()
};
}
_this.getSlide = function (index) {
return _this.slides[index]
}
_this.getLastSlide = function () {
return _this.slides[ _this.slides.length-1 ]
}
_this.getFirstSlide = function () {
return _this.slides[0]
}
//Currently Active Slide
_this.currentSlide = function () {
return _this.slides[_this.activeIndex]
}
/*=========================
Find All Plugins
!!! Plugins API is in beta !!!
===========================*/
var _plugins = [];
for (var plugin in _this.plugins) {
if (params[plugin]) {
var p = _this.plugins[plugin](_this, params[plugin])
if (p)
_plugins.push( p )
}
}
_this.callPlugins = function(method, args) {
if (!args) args = {}
for (var i=0; i<_plugins.length; i++) {
if (method in _plugins[i]) {
_plugins[i][method](args);
}
}
}
/*=========================
WP8 Fix
===========================*/
if (_this.ie10 && !params.onlyExternal) {
if (isHorizontal) _this.wrapper.classList.add('swiper-wp8-horizontal')
else _this.wrapper.classList.add('swiper-wp8-vertical')
}
/*=========================
Loop
===========================*/
if (params.loop) {
(function(){
numOfSlides = _this.slides.length;
if (_this.slides.length==0) return;
var slideFirstHTML = '';
var slideLastHTML = '';
//Grab First Slides
for (var i=0; i<params.slidesPerSlide; i++) {
slideFirstHTML+=_this.slides[i].outerHTML
}
//Grab Last Slides
for (var i=numOfSlides-params.slidesPerSlide; i<numOfSlides; i++) {
slideLastHTML+=_this.slides[i].outerHTML
}
wrapper.innerHTML = slideLastHTML + wrapper.innerHTML + slideFirstHTML;
_this._calcSlides()
_this.callPlugins('onCreateLoop');
})();
}
//Init Function
var firstInit = false;
//ReInitizize function. Good to use after dynamically changes of Swiper, like after add/remove slides
_this.reInit = function () {
_this.init(true)
}
_this.init = function(reInit) {
var _width = window.getComputedStyle(_this.container, null).getPropertyValue('width')
var _height = window.getComputedStyle(_this.container, null).getPropertyValue('height')
var newWidth = parseInt(_width,10);
var newHeight = parseInt(_height,10);
//IE8 Fixes
if(isNaN(newWidth) || _width.indexOf('%')>0) {
newWidth = _this.container.offsetWidth - parseInt(window.getComputedStyle(_this.container, null).getPropertyValue('padding-left'),10) - parseInt(window.getComputedStyle(_this.container, null).getPropertyValue('padding-right'),10)
}
if(isNaN(newHeight) || _height.indexOf('%')>0) {
newHeight = _this.container.offsetHeight - parseInt(window.getComputedStyle(_this.container, null).getPropertyValue('padding-top'),10) - parseInt(window.getComputedStyle(_this.container, null).getPropertyValue('padding-bottom'),10)
}
if (!reInit) {
if (_this.width==newWidth && _this.height==newHeight) return
}
if (reInit || firstInit) {
_this._calcSlides();
if (params.pagination) {
_this.updatePagination()
}
}
_this.width = newWidth;
_this.height = newHeight;
var dividerVertical = isHorizontal ? 1 : params.slidesPerSlide,
dividerHorizontal = isHorizontal ? params.slidesPerSlide : 1,
slideWidth, slideHeight, wrapperWidth, wrapperHeight;
numOfSlides = _this.slides.length
if (!params.scrollContainer) {
if (!_widthFromCSS) {
slideWidth = _this.width/dividerHorizontal;
slideHeight = _this.height/dividerVertical;
}
else {
slideWidth = _this.slides[0].offsetWidth;
slideHeight = _this.slides[0].offsetHeight;
}
containerSize = isHorizontal ? _this.width : _this.height;
slideSize = isHorizontal ? slideWidth : slideHeight;
wrapperWidth = isHorizontal ? numOfSlides * slideWidth : _this.width;
wrapperHeight = isHorizontal ? _this.height : numOfSlides*slideHeight;
if (_widthFromCSS) {
//Re-Calc sps for pagination
params.slidesPerSlide = Math.round(containerSize/slideSize)
}
}
else {
//Unset dimensions in vertical scroll container mode to recalculate slides
if (!isHorizontal) {
wrapper.style.width='';
wrapper.style.height='';
_this.slides[0].style.width='';
_this.slides[0].style.height='';
}
slideWidth = _this.slides[0].offsetWidth;
slideHeight = _this.slides[0].offsetHeight;
containerSize = isHorizontal ? _this.width : _this.height;
slideSize = isHorizontal ? slideWidth : slideHeight;
wrapperWidth = slideWidth;
wrapperHeight = slideHeight;
}
wrapperSize = isHorizontal ? wrapperWidth : wrapperHeight;
for (var i=0; i<_this.slides.length; i++ ) {
var el = _this.slides[i];
if (!_widthFromCSS) {
el.style.width=slideWidth+"px"
el.style.height=slideHeight+"px"
}
if (params.onSlideInitialize) {
params.onSlideInitialize(_this, el);
}
}
wrapper.style.width = wrapperWidth+"px";
wrapper.style.height = wrapperHeight+"px";
// Set Initial Slide Position
if(params.initialSlide > 0 && params.initialSlide < numOfSlides && !firstInit) {
_this.realIndex = _this.activeIndex = params.initialSlide;
if (params.loop) {
_this.activeIndex = _this.realIndex-params.slidesPerSlide;
}
//Legacy
_this.activeSlide = _this.activeIndex;
//--
if (isHorizontal) {
_this.positions.current = -params.initialSlide * slideWidth;
_this.setTransform( _this.positions.current, 0, 0);
}
else {
_this.positions.current = -params.initialSlide * slideHeight;
_this.setTransform( 0, _this.positions.current, 0);
}
}
if (!firstInit) _this.callPlugins('onFirstInit');
else _this.callPlugins('onInit');
firstInit = true;
}
_this.init()
//Get Max And Min Positions
function maxPos() {
var a = (wrapperSize - containerSize);
if (params.loop) a = a - containerSize;
if (params.scrollContainer) {
a = slideSize - containerSize;
if (a<0) a = 0;
}
if (params.slidesPerSlide > _this.slides.length) a = 0;
return a;
}
function minPos() {
var a = 0;
if (params.loop) a = containerSize;
return a;
}
/*=========================
Pagination
===========================*/
_this.updatePagination = function() {
if (_this.slides.length<2) return;
var activeSwitch = dQ(params.pagination+' .'+params.paginationActiveClass)
if(!activeSwitch) return
for (var i=0; i < activeSwitch.length; i++) {
activeSwitch.item(i).className = params.paginationClass
}
var pagers = dQ(params.pagination+' .'+params.paginationClass).length;
var minPagerIndex = params.loop ? _this.realIndex-params.slidesPerSlide : _this.realIndex;
var maxPagerIndex = minPagerIndex + (params.slidesPerSlide-1);
for (var i = minPagerIndex; i <= maxPagerIndex; i++ ) {
var j = i;
if (j>=pagers) j=j-pagers;
if (j<0) j = pagers + j;
if (j<numOfSlides) {
dQ(params.pagination+' .'+params.paginationClass).item( j ).className = params.paginationClass+' '+params.paginationActiveClass
}
if (i==minPagerIndex) dQ(params.pagination+' .'+params.paginationClass).item( j ).className+=' swiper-activeslide-switch'
}
}
_this.createPagination = function () {
if (params.pagination && params.createPagination) {
var paginationHTML = "";
var numOfSlides = _this.slides.length;
var numOfButtons = params.loop ? numOfSlides - params.slidesPerSlide*2 : numOfSlides;
for (var i = 0; i < numOfButtons; i++) {
paginationHTML += '<span class="'+params.paginationClass+'"></span>'
}
dQ(params.pagination)[0].innerHTML = paginationHTML
_this.updatePagination()
_this.callPlugins('onCreatePagination');
}
}
_this.createPagination();
//Window Resize Re-init
_this.resizeEvent = params.resizeEvent==='auto'
? ('onorientationchange' in window) ? 'orientationchange' : 'resize'
: params.resizeEvent
_this.resizeFix = function(){
_this.callPlugins('beforeResizeFix');
_this.init()
//To fix translate value
if (!params.scrollContainer)
_this.swipeTo(_this.activeIndex, 0, false)
else {
var pos = isHorizontal ? _this.getTranslate('x') : _this.getTranslate('y')
if (pos < -maxPos()) {
var x = isHorizontal ? -maxPos() : 0;
var y = isHorizontal ? 0 : -maxPos();
_this.setTransition(0)
_this.setTransform(x,y,0)
}
}
_this.callPlugins('afterResizeFix');
}
if (!params.disableAutoResize) {
//Check for resize event
window.addEventListener(_this.resizeEvent, _this.resizeFix, false)
}
/*==========================================
Autoplay
============================================*/
var autoPlay
_this.startAutoPlay = function() {
if (params.autoPlay && !params.loop) {
autoPlay = setInterval(function(){
var newSlide = _this.realIndex + 1
if ( newSlide == numOfSlides) newSlide = 0
if ( newSlide == numOfSlides - params.slidesPerSlide + 1) newSlide=0;
_this.swipeTo(newSlide)
}, params.autoPlay)
}
else if (params.autoPlay && params.loop) {
autoPlay = setInterval(function(){
_this.fixLoop();
_this.swipeNext(true)
}, params.autoPlay)
}
_this.callPlugins('onAutoPlayStart');
}
_this.stopAutoPlay = function() {
if (autoPlay)
clearInterval(autoPlay)
_this.callPlugins('onAutoPlayStop');
}
if (params.autoPlay) {
_this.startAutoPlay()
}
/*==========================================
Event Listeners
============================================*/
if (!_this.ie10) {
if (_this.support.touch) {
wrapper.addEventListener('touchstart', onTouchStart, false);
wrapper.addEventListener('touchmove', onTouchMove, false);
wrapper.addEventListener('touchend', onTouchEnd, false);
}
if (params.simulateTouch) {
wrapper.addEventListener('mousedown', onTouchStart, false);
document.addEventListener('mousemove', onTouchMove, false);
document.addEventListener('mouseup', onTouchEnd, false);
}
}
else {
wrapper.addEventListener(_this.touchEvents.touchStart, onTouchStart, false);
document.addEventListener(_this.touchEvents.touchMove, onTouchMove, false);
document.addEventListener(_this.touchEvents.touchEnd, onTouchEnd, false);
}
//Remove Events
_this.destroy = function(removeResizeFix){
removeResizeFix = removeResizeFix===false ? removeResizeFix : removeResizeFix || true
if (removeResizeFix) {
window.removeEventListener(_this.resizeEvent, _this.resizeFix, false);
}
if (_this.ie10) {
wrapper.removeEventListener(_this.touchEvents.touchStart, onTouchStart, false);
document.removeEventListener(_this.touchEvents.touchMove, onTouchMove, false);
document.removeEventListener(_this.touchEvents.touchEnd, onTouchEnd, false);
}
else {
if (_this.support.touch) {
wrapper.removeEventListener('touchstart', onTouchStart, false);
wrapper.removeEventListener('touchmove', onTouchMove, false);
wrapper.removeEventListener('touchend', onTouchEnd, false);
}
wrapper.removeEventListener('mousedown', onTouchStart, false);
document.removeEventListener('mousemove', onTouchMove, false);
document.removeEventListener('mouseup', onTouchEnd, false);
}
if (params.keyboardControl) {
document.removeEventListener('keydown', handleKeyboardKeys, false);
}
if (params.mousewheelControl && _this._wheelEvent) {
_this.container.removeEventListener(_this._wheelEvent, handleMousewheel, false);
}
if (params.autoPlay) {
_this.stopAutoPlay()
}
_this.callPlugins('onDestroy');
}
/*=========================
Prevent Links
===========================*/
_this.allowLinks = true;
if (params.preventLinks) {
var links = _this.container.querySelectorAll('a')
for (var i=0; i<links.length; i++) {
links[i].addEventListener('click', preventClick, false)
}
}
function preventClick(e) {
if (!_this.allowLinks) (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
}
/*==========================================
Keyboard Control
============================================*/
if (params.keyboardControl) {
function handleKeyboardKeys (e) {
var kc = e.keyCode || e.charCode;
if (isHorizontal) {
if (kc==37 || kc==39) e.preventDefault();
if (kc == 39) _this.swipeNext()
if (kc == 37) _this.swipePrev()
}
else {
if (kc==38 || kc==40) e.preventDefault();
if (kc == 40) _this.swipeNext()
if (kc == 38) _this.swipePrev()
}
}
document.addEventListener('keydown',handleKeyboardKeys, false);
}
/*==========================================
Mousewheel Control. Beta!
============================================*/
// detect available wheel event
_this._wheelEvent = false;
if (params.mousewheelControl) {
if ( document.onmousewheel !== undefined ) {
_this._wheelEvent = "mousewheel"
}
try {
WheelEvent("wheel");
_this._wheelEvent = "wheel";
} catch (e) {}
if ( !_this._wheelEvent ) {
_this._wheelEvent = "DOMMouseScroll";
}
function handleMousewheel (e) {
var we = _this._wheelEvent;
var delta;
//Opera & IE
if (e.detail) delta = -e.detail;
//WebKits
else if (we == 'mousewheel') delta = e.wheelDelta;
//Old FireFox
else if (we == 'DOMMouseScroll') delta = -e.detail;
//New FireFox
else if (we == 'wheel') {
delta = Math.abs(e.deltaX)>Math.abs(e.deltaY) ? - e.deltaX : - e.deltaY;
}
if (!params.freeMode) {
if(delta<0) _this.swipeNext()
else _this.swipePrev()
}
else {
//Freemode or scrollContainer:
var currentTransform =isHorizontal ? _this.getTranslate('x') : _this.getTranslate('y')
var x,y;
if (isHorizontal) {
x = _this.getTranslate('x') + delta;
y = _this.getTranslate('y');
if (x>0) x = 0;
if (x<-maxPos()) x = -maxPos();
}
else {
x = _this.getTranslate('x');
y = _this.getTranslate('y')+delta;
if (y>0) y = 0;
if (y<-maxPos()) y = -maxPos();
}
_this.setTransition(0)
_this.setTransform(x,y,0)
}
if(e.preventDefault) e.preventDefault();
else e.returnValue = false;
return false;
}
if (_this._wheelEvent) {
_this.container.addEventListener(_this._wheelEvent, handleMousewheel, false);
}
}
/*=========================
Grab Cursor
===========================*/
if (params.grabCursor) {
_this.container.style.cursor = 'move';
_this.container.style.cursor = 'grab';
_this.container.style.cursor = '-moz-grab';
_this.container.style.cursor = '-webkit-grab';
}
/*=========================
Handle Touches
===========================*/
//Detect event type for devices with both touch and mouse support
var isTouchEvent = false;
var allowThresholdMove;
function onTouchStart(event) {
//Exit if slider is already was touched
if (_this.isTouched || params.onlyExternal) {
return false
}
if (params.preventClassNoSwiping && event.target && event.target.className.indexOf('NoSwiping') > -1) return false;
//Check For Nested Swipers
_this.isTouched = true;
isTouchEvent = event.type=='touchstart';
if (!isTouchEvent || event.targetTouches.length == 1 ) {
_this.callPlugins('onTouchStartBegin');
if (params.loop) _this.fixLoop();
if(!isTouchEvent) {
if(event.preventDefault) event.preventDefault();
else event.returnValue = false;
}
var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX)
var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY)
//Start Touches to check the scrolling
_this.touches.startX = _this.touches.currentX = pageX;
_this.touches.startY = _this.touches.currentY = pageY;
_this.touches.start = _this.touches.current = isHorizontal ? _this.touches.startX : _this.touches.startY ;
//Set Transition Time to 0
_this.setTransition(0)
//Get Start Translate Position
_this.positions.start = _this.positions.current = isHorizontal ? _this.getTranslate('x') : _this.getTranslate('y');
//Set Transform
if (isHorizontal) {
_this.setTransform( _this.positions.start, 0, 0)
}
else {
_this.setTransform( 0, _this.positions.start, 0)
}
//TouchStartTime
var tst = new Date()
_this.times.start = tst.getTime()
//Unset Scrolling
isScrolling = undefined;
//Define Clicked Slide without additional event listeners
if (params.onSlideClick || params.onSlideTouch) {
;(function () {
var el = _this.container;
var box = el.getBoundingClientRect();
var body = document.body;
var clientTop = el.clientTop || body.clientTop || 0;
var clientLeft = el.clientLeft || body.clientLeft || 0;
var scrollTop = window.pageYOffset || el.scrollTop;
var scrollLeft = window.pageXOffset || el.scrollLeft;
var x = pageX - box.left + clientLeft - scrollLeft;
var y = pageY - box.top - clientTop - scrollTop;
var touchOffset = isHorizontal ? x : y;
var beforeSlides = -Math.round(_this.positions.current/slideSize)
var realClickedIndex = Math.floor(touchOffset/slideSize) + beforeSlides
var clickedIndex = realClickedIndex;
if (params.loop) {
var clickedIndex = realClickedIndex - params.slidesPerSlide;
if (clickedIndex<0) {
clickedIndex = _this.slides.length+clickedIndex-(params.slidesPerSlide*2);
}
}
_this.clickedSlideIndex = clickedIndex
_this.clickedSlide = _this.getSlide(realClickedIndex);
if (params.onSlideTouch) {
params.onSlideTouch(_this);
_this.callPlugins('onSlideTouch');
}
})();
}
//Set Treshold
if (params.moveStartThreshold>0) allowThresholdMove = false;
//CallBack
if (params.onTouchStart) params.onTouchStart(_this)
_this.callPlugins('onTouchStartEnd');
}
}
function onTouchMove(event) {
// If slider is not touched - exit
if (!_this.isTouched || params.onlyExternal) return;
if (isTouchEvent && event.type=='mousemove') return;
var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX)
var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY)
//check for scrolling
if ( typeof isScrolling === 'undefined' && isHorizontal) {
isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs( pageX - _this.touches.startX ) )
}
if ( typeof isScrolling === 'undefined' && !isHorizontal) {
isScrolling = !!( isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs( pageX - _this.touches.startX ) )
}
if (isScrolling ) {
_this.isTouched = false;
return
}
//Check For Nested Swipers
if (event.assignedToSwiper) {
_this.isTouched = false;
return
}
event.assignedToSwiper = true;
//Block inner links
if (params.preventLinks) {
_this.allowLinks = false;
}
//Stop AutoPlay if exist
if (params.autoPlay) {
_this.stopAutoPlay()
}
if (!isTouchEvent || event.touches.length == 1) {
_this.callPlugins('onTouchMoveStart');
if(event.preventDefault) event.preventDefault();
else event.returnValue = false;
_this.touches.current = isHorizontal ? pageX : pageY ;
_this.positions.current = (_this.touches.current - _this.touches.start)*params.ratio + _this.positions.start
if (params.resistance) {
//Resistance for Negative-Back sliding
if(_this.positions.current > 0 && !(params.freeMode&&!params.freeModeFluid)) {
if (params.loop) {
var resistance = 1;
if (_this.positions.current>0) _this.positions.current = 0;
}
else {
var resistance = (containerSize*2-_this.positions.current)/containerSize/2;
}
if (resistance < 0.5)
_this.positions.current = (containerSize/2)
else
_this.positions.current = _this.positions.current * resistance
if (params.nopeek)
_this.positions.current = 0;
}
//Resistance for After-End Sliding
if ( (_this.positions.current) < -maxPos() && !(params.freeMode&&!params.freeModeFluid)) {
if (params.loop) {
var resistance = 1;
var newPos = _this.positions.current
var stopPos = -maxPos() - containerSize
}
else {
var diff = (_this.touches.current - _this.touches.start)*params.ratio + (maxPos()+_this.positions.start)
var resistance = (containerSize+diff)/(containerSize);
var newPos = _this.positions.current-diff*(1-resistance)/2
var stopPos = -maxPos() - containerSize/2;
}
if (params.nopeek) {
newPos = _this.positions.current-diff;
stopPos = -maxPos();
}
if (newPos < stopPos || resistance<=0)
_this.positions.current = stopPos;
else
_this.positions.current = newPos
}
}
//Move Slides
if (!params.followFinger) return
if (!params.moveStartThreshold) {
if (isHorizontal) _this.setTransform( _this.positions.current, 0, 0)
else _this.setTransform( 0, _this.positions.current, 0)
}
else {
if ( Math.abs(_this.touches.current - _this.touches.start)>params.moveStartThreshold || allowThresholdMove) {
allowThresholdMove = true;
if (isHorizontal) _this.setTransform( _this.positions.current, 0, 0)
else _this.setTransform( 0, _this.positions.current, 0)
}
else {
_this.positions.current = _this.positions.start
}
}
if (params.freeMode) {
_this.updateActiveSlide(_this.positions.current)
}
//Prevent onSlideClick Fallback if slide is moved