-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarousel.html
1124 lines (1000 loc) · 40.3 KB
/
carousel.html
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
<script>
(function (root, factory) {
root.Elliptical.Behaviors=root.Elliptical.Behaviors || {};
root.Elliptical.Behaviors.Carousel=factory();
}(this, function () {
var _indicatorNavSelector = 'carousel-navigation.indicators';
var _innerContainer = 'carousel-inner-container';
var _item = 'carousel-item';
var INTERVAL_PERIOD=250;
return {
/*==========================================
PRIVATE
*===========================================*/
_isVisible:function(){
return this.element.is(':visible');
},
_passVisibilityCheck:function(){
if(this.initOnVisibility) return this._isVisible();
else return true;
},
_assignLocalData:function(){
this._data.set('innerContainer',null);
this._data.set('innerContainerSelector',_innerContainer);
this._data.set('size',0);
this._data.set('iteration',0);
this._data.set('prevNav',null);
this._data.set('nextNav',null);
this._data.set('readyState',false);
this._data.set('timeoutId',null);
this._data.set('intervalId',null);
this._data.set('currentSlide',null);
this._data.set('itemWidth',0);
this._data.set('itemMargin',0);
this._data.set('itemBorder',0);
this._data.set('item',_item);
this._data.set('visible','nav-visible');
this._data.set('carouselItems',null);
this._data.set('autoInterval',4000);
this._data.set('fadeAutoInterval',8000);
this._data.set('element',null);
},
_initCarousel:function(){
if(!this._data) this._destroy();
var hasTemplate=this._hasTemplate();
if(hasTemplate) this._initializeDelay();
else this._initialize();
},
_isPhone: function () {
var width = window.innerWidth || $(window).width();
return (width < 500);
},
_hasTemplate:function(){
var node=this;
return (node.hasAttribute('template'));
},
_initVisibilityListener:function(){
var self=this;
var intervalId=setInterval(function(){
if(self._isVisible()){
clearInterval(intervalId);
self._initCarousel();
}
},INTERVAL_PERIOD);
},
_initializeDelay:function(){
var self=this;
var delay=this.renderDelay;
setTimeout(function(){
self._initialize();
},delay);
},
_initialize: function(){
this._setFingerEvents();
this._initialization();
this._onInitialization();
},
/**
*
* @private
*/
_initialization: function () {
var element = this.element;
//get size=total number of slides
this._data.set('size',element.find(this._data.get('item')).length);
//get the current slide=1st element
this._data.set('currentSlide',element.find(this._data.get('item') + ':first'));
this._data.set('iteration',0);
var currentSlide = this._data.get('currentSlide');
this._data.set('indicators',null);
if (this.indicators) {
this._initIndicatorNav();
}
},
_onInitialization: function () {
this._setDuration();
var animation = this.animation;
if (animation === 'fade') {
this._readyState();
if (this._isPhone() && this.showOnLoad) {
var slideIndex_ = parseInt(this.showOnLoad);
this._FadeSlide(slideIndex_);
} else {
if (this.auto) this._initAutoInterval();
}
} else {
/* multi-slide or slide transition */
if (!this._mq.touch && this.hardwareAcceleration) {
var body = $('body');
this._setHardwareAcceleration(body);
}
if (this.preload === true) this._preloadImages(this.element, this._onPreload.bind(this));
else this._onPreload(null, null);
}
this._setInnerContainerVisibility();
},
/**
* on preload handler
* @param err
* @param data
* @private
*/
_onPreload: function (err, data) {
this._readyState();
var animation = this.animation;
var auto = this.auto;
if (animation === 'multi-slide') this._initMultiSlide();
else if (animation === 'slide') this._initSlide();
this._setInnerContainerVisibility();
var evtData = {};
if (data) {
evtData.length = data.length;
this._triggerPreloadEvent(evtData);
}
if (animation === 'slide' && auto) this._initAutoSlideInterval();
},
/**
* carousel component is ready to begin
* @private
*/
_readyState: function () {
this._data.set('readyState',true);
this._initContainers();
this._initNav();
this.__events();
},
/**
*
* @private
*/
_initAutoInterval: function () {
if (this._isPhone()) return false;
var self = this;
setTimeout(function () {
self._autoFadeSlide();
}, self.initInterval);
},
/**
*
* @private
*/
_initAutoSlideInterval: function () {
var MAX_COUNT=this.maxIntervals;
var count=0;
var self = this;
var intervalId = setInterval(function () {
self._data.set('intervalId',intervalId);
self._setIndicatorNav();
self._nextSlide();
if(MAX_COUNT){
count++;
if(count > MAX_COUNT)clearInterval(intervalId);
}
}, self.autoInterval);
},
/**
*
* @private
*/
_initSlide: function () {
/* disable prev nav */
var prevNav=this._data.get('prevNav');
var nextNav=this._data.get('nextNav');
this._hideNav(prevNav);
var size = this._data.get('size');
if (size < 2) this._hideNav(nextNav);
},
/**
* init multi-slide
* @private
*/
_initMultiSlide: function () {
var ele = this.element;
var size = this._data.get('size');
var li = ele.find(this._data.get('item') + ':first');
this._data.set('itemWidth',li.outerWidth());
this._data.set('itemMargin',parseInt(li.css('margin-right'), 10));
/* disable prev nav */
var prevNav=this._data.get('prevNav');
var nextNav=this._data.get('nextNav');
this._hideNav(prevNav);
/* check to disable next nav */
if (size < 2) this._hideNav(nextNav);
else {
//if no content to slide
if (!this._contentToSlide()) this._hideNav(nextNav);
}
this._setInnerContainerBorder();
},
/**
* private method that sets the containers
* @private
*/
_initContainers: function () {
var element = this.element;
var containerSelector=this._data.get('innerContainerSelector');
this._data.set('innerContainer',element.find(containerSelector));
this._data.set('itemsContainer',element.find('carousel-items'));
},
/**
* set inner container to visible
* @private
*/
_setInnerContainerVisibility: function () {
var innerContainer=this._data.get('innerContainer');
if(innerContainer)innerContainer.addClass('visible');
else{
this._initContainers();
innerContainer=this._data.get('innerContainer');
innerContainer.addClass('visible');
}
},
/**
* for multi-slide, set a transparent border class, if no existing border
* @private
*/
_setInnerContainerBorder: function () {
var innerContainer = this._data.get('innerContainer');
var border = parseInt(innerContainer.css('border'), 10);
if (border === 0) innerContainer.addClass('multi-border');
},
/**
* trigger preload event
* @param evtData
* @private
*/
_triggerPreloadEvent: function (evtData) {
var self = this;
setTimeout(function () {
self._fireEvent('preloaded', evtData);
}, 10);
},
/**
* private method that handles transition to next slide(css prop transitioned is margin-left)
* @private
*/
_nextSlide: function () {
var ele = this._data.get('itemsContainer');
var iteration = this._data.get('iteration');
var self = this;
var contentToSlide=this._contentToSlide();
if (contentToSlide) { //if the left offset position of last-child is greater than container width, we can do a next slide
var slideDistanceFactor = this._slideDistanceFactor('first');
iteration++;
this._data.set('iteration',iteration);
var marginLeft = (-1) * iteration * slideDistanceFactor;
var offset=parseInt(this._currentOffset);
marginLeft=marginLeft - offset;
marginLeft=marginLeft - this._runningOffset;
this._runningOffset=this._runningOffset + offset;
marginLeft=marginLeft.toString() + 'px';
var evtData = {
slideIndex: iteration
};
this._fireEvent('sliding', evtData);
this._transition(ele, {
'margin-left': marginLeft,
duration: this.duration,
easing: this.easing
}, function () {
self._swipeExecuting=false;
/* remove any disabled css markup from nav */
var prevNav=self._data.get('prevNav');
var nextNav=self._data.get('nextNav');
if(prevNav[0]) self._showNav(prevNav);
/* check if nextNav needs to be disabled */
if (!self._contentToSlide()) self._hideNav(nextNav);
self._fireEvent('slide', evtData);
});
}else{
var intervalId=this._data.get('intervalId');
if(intervalId) clearInterval(intervalId);
}
},
_getCarouselItems: function () {
var items = this._data.get('carouselItems');
if (!items) items = this.element.find('carousel-item');
return items;
},
_getSize: function () {
var items = this._getCarouselItems();
return items.length;
},
/**
* private method that handles transition to prev slide (css prop transitioned is margin-left)
* @private
*/
_prevSlide: function () {
var ele = this._data.get('itemsContainer');
var iteration = this._data.get('iteration');
var self = this;
if (iteration > 0) { //if first-child is not the first visible position, we can do a previous slide
var slideDistanceFactor = this._slideDistanceFactor('first');
iteration--;
this._data.set('iteration',iteration);
var marginLeft = (-1) * iteration * slideDistanceFactor;
var offset=parseInt(this._currentOffset);
this._runningOffset = this._runningOffset + offset;
marginLeft= marginLeft - this._runningOffset;
marginLeft=marginLeft.toString()+ 'px';
var evtData = {
slideIndex: iteration
};
this._fireEvent('sliding', evtData);
this._transition(ele, {
'margin-left': marginLeft,
duration: this.duration,
easing: this.easing
}, function () {
self._swipeExecuting=false;
/* remove any disabled css markup from nav */
var prevNav=self._data.get('prevNav');
var nextNav=self._data.get('nextNav');
self._showNav(nextNav);
/* check if prevNav needs to be disabled */
if (iteration === 0) self._hideNav(prevNav);
self._fireEvent('slide', evtData);
});
}
},
/**
* private method handles both next and prev slide for fade transition
* @param slideIndex
* @private
*/
_FadeSlide: function (slideIndex) {
var items = this._getCarouselItems();
var nextSlide_ = items[slideIndex];
var nextSlide = $(nextSlide_);
var currentSlide = this._data.get('currentSlide');
currentSlide.css({
position: 'absolute',
display: 'block',
float: 'none',
'z-index': 1
});
nextSlide.css({
position: 'relative',
display: 'list-item',
float: 'left',
'z-index': 2
});
var evtData = {
slideIndex: slideIndex
};
var duration = this.duration;
var crossFade = this.crossFade;
this._data.set('currentSlide',nextSlide);
this._data.set('iteration',slideIndex);
if (crossFade===true) {
this._crossFadeTransition(currentSlide, nextSlide, duration, evtData);
} else {
this._fadeTransition(currentSlide, nextSlide, duration, evtData);
}
},
_crossFadeTransition: function(currentSlide,nextSlide,duration,evtData){
this._transition(currentSlide, {
opacity: 0,
duration: duration-50
});
var self=this;
setTimeout(function(){
self._transition(nextSlide, {
opacity: 1,
duration: duration
});
},10);
this._fireEvent('slide', evtData);
},
_fadeTransition: function (currentSlide, nextSlide, duration, evtData) {
var self = this;
this._transition(currentSlide, {
opacity: 0,
duration: duration
}, function () {
self._transition(nextSlide, {
opacity: 1,
duration: duration
});
self._fireEvent('slide', evtData);
});
},
/**
* private method handles auto fade
* @returns {boolean}
* @private
*/
_autoFadeSlide: function () {
var MAX_COUNT=this.maxIntervals;
var count=0;
//abort if nav has been manually invoked
if (!this.auto) return false;
var iteration = this._data.get('iteration');
iteration = (iteration < this._data.get('size') - 1) ? (iteration + 1) : 0;
this._updateIndicatorNav(iteration);
this._FadeSlide(iteration);
var self = this;
var timeoutId = setTimeout(function () {
self._data.set('timeoutId',timeoutId);
self._autoFadeSlide();
if(MAX_COUNT){
count++;
if(count > MAX_COUNT) clearTimeout(timeoutId);
}
}, self.autoInterval);
},
/**
* private method that clears timeoutid for setTimeout
* @private
*/
_clearTimeout: function () {
var timeoutId=this._data.get('timeoutId');
var intervalId=this._data.get('intervalId');
this.auto=false;
if (timeoutId){
clearTimeout(timeoutId);
} else if(intervalId) clearInterval(intervalId);
},
/**
* private method that sets the transition duration
* @private
*/
_setDuration: function () {
var animation = this.animation;
if (animation === 'fade') {
if (this._device.touch) this.duration = this.touchFadeDuration;
else this.duration = this.desktopFadeDuration;
if (!this.autoInterval) this.autoInterval = this._data.get('fadeAutoInterval');
} else {
if (!this.autoInterval) this.autoInterval = this._data.get('autoInterval');
if (this._device.touch) this.duration = this.touchDuration;
else this.duration = this.desktopDuration;
}
},
/**
* private method that returns the left position of requested li child
* @param child
@returns {int}
* @private
*/
_leftPos: function (child) {
var innerContainer=this.element.find('carousel-inner-container');
var innerContainerOffset = innerContainer.offset();
var item = this.element.find(this._data.get('item') + ':' + child + '-child');
var offset = item.offset();
if(!offset){
this._destroy();
return;
}
var innerContainerOffsetLeft=innerContainerOffset.left;
var scrollLeft=innerContainer.scrollLeft();
offset.left -= innerContainerOffsetLeft - scrollLeft;
return offset.left;
},
/**
* private method that returns the inner container width
* @returns {int}
* @private
*/
_innerContainerWidth: function () {
var container = this._data.get('innerContainer');
if(container===undefined) container=this.element.find('carousel-inner.container');
return container.width();
},
_showNav:function(nav){
nav.removeClass('disabled');
nav.addClass(this._data.get('visible'));
nav.attr('style','');
},
_hideNav:function(nav){
nav.addClass('disabled');
},
/**
*
*/
_enableNextNav:function(){
return this._contentToSlide();
},
/**
* private method that inits the nav controls
* @private
*/
_initNav: function () {
var animation=this.animation;
if(animation==='multi-slide') this._initMultiSlideNav();
else this.__initNav();
},
__initNav:function(){
var outerContainer = this.element;
var next = outerContainer.find(this.nextNavSelector);
var prev = outerContainer.find(this.prevNavSelector);
this._showNav(next);
this._showNav(prev);
this._data.set('nextNav',next);
this._data.set('prevNav',prev);
},
_initMultiSlideNav:function(){
var outerContainer = this.element;
var next = outerContainer.find(this.nextNavSelector);
var prev = outerContainer.find(this.prevNavSelector);
if(this._enableNextNav()) this._showNav(next);
else this._hideNav(next);
this._hideNav(prev);
this._data.set('nextNav',next);
this._data.set('prevNav',prev);
},
_initIndicatorNav: function () {
var outerContainer = this.element;
var indicators = outerContainer.find(_indicatorNavSelector);
var length = this._getSize();
var strLi = '';
for (var i = 0; i < length; i++) {
if (i === 0) strLi += '<li class="active"> </li>';
else strLi += '<li> </li>';
}
indicators.append($(strLi));
indicators.addClass('show');
this._data.set('indicatorNav',indicators);
this._indicatorEvents();
},
_setIndicatorNav:function(){
var iteration = this._data.get('iteration');
iteration = (iteration !== undefined) ? (iteration) : 0;
var size = this._getSize();
size--;
if (iteration < size) {
iteration++;
this._updateIndicatorNav(iteration);
} else this._clearTimeout();
},
_updateIndicatorNav: function (index) {
var indicatorNav = this._data.get('indicatorNav');
if (!indicatorNav) return false;
indicatorNav.find('.active')
.removeClass('active');
var items = indicatorNav.find('li');
var item = items[index];
if (item) $(item).addClass('active');
},
/**
* private method that returns bool regarding not reaching the end of the hidden content to slide
* @returns {boolean}
* @private
*/
_contentToSlide: function () {
var child = 'last';
var innerContainerWidth = this._innerContainerWidth();
var left = this._leftPos(child);
var width = this._slideDistanceFactor('last');
left += width;
left=left-2;
return (left > innerContainerWidth);
},
/**
* private method that returns the calculated width factor of the distance to slide
* @param child
* @returns {number}
* @private
*/
_slideDistanceFactor: function (child) {
var distance=this.slideDistance;
if (distance) return distance;
else {
var ele = this.element;
var item;
if(child==='last' || child==='first') item = ele.find(this._data.get('item') + ':' + child + '-child');
else item = ele.find(this._data.get('item') + ':nth-child(' + child + ')');
var width = item.outerWidth();
var margin = item.css('margin-right');
return parseInt(width) + parseInt(margin, 10);
}
},
_isFirstSlide:function(){
var iteration = this._data.get('iteration');
iteration = (iteration !== undefined) ? (iteration) : 0;
return (iteration < 1);
},
_isLastSlide:function(){
var iteration = this._data.get('iteration');
iteration = (iteration !== undefined) ? (iteration) : 0;
var size = this._getSize();
iteration+=1;
return(iteration >=size);
},
/**
* event trigger handler for selected slide
* @param index
* @param item
* @private
*/
_onSelected: function (index, item) {
var url = 'url';
var evtData = {
index: index,
url: item.attr(url),
target: item
};
this._fireEvent('selected', evtData);
},
/**
* private method for next slide request
* @private
*/
_onNext: function (index) {
var animation = this.animation;
var iteration=index;
if (this._data.get('readyState')) {
this._clearTimeout();
this.auto = false;
if (animation === 'fade') { /* fade */
if(typeof iteration !== 'number'){
iteration= this._data.get('iteration');
iteration = (iteration < this._data.get('size') - 1) ? (iteration + 1) : 0;
}
this._FadeSlide(iteration);
} else {
/* slide mode */
if (typeof iteration === 'number') {
iteration--;
this._data.set('iteration',iteration);
}
this._nextSlide();
}
}
},
/**
* private method for prev slide request
* @private
*/
_onPrev: function (index) {
var animation = this.animation;
var iteration = index;
if (this._data.get('readyState')) {
this._clearTimeout();
this.auto = false;
if (animation === 'fade') { /* fade */
if (typeof iteration !== 'number') {
iteration = this._data.get('iteration');
iteration = (iteration > 0) ? (iteration - 1) : this._data.get('size') - 1;
}
this._FadeSlide(iteration);
} else {
/* slide mode */
if (typeof iteration === 'number') {
iteration++;
this._data.set('iteration',iteration);
}
this._prevSlide();
}
}
},
_pause:function(){
this._clearTimeout();
},
/**
*
* @private
*/
_enableNav: function () {
var size=this.element.find(this._data.item).length;
this._data.set('size',size);
var next = this._data.get('nextNav');
var prev = this._data.get('prevNav');
if (size > 1) {
next.show();
prev.show();
}
},
/**
*
* @private
*/
_disableNav: function () {
var next = this._data.get('nextNav');
var prev = this._data.get('prevNav');
next.hide();
prev.hide();
},
/**
* for fade transitions, show slide at index
* @param index {Number}
* @private
*/
_onSlide: function (index) {
var animation = this.animation;
if (animation === 'fade') { /* fade */
if (index < 0) index = 0;
if (index > this._data.size - 1) index = this._data.size - 1;
this._clearTimeout();
this.auto = false;
this._FadeSlide(index);
}else{
this._clearTimeout();
this.auto = false;
var currentIndex = this._data.get('iteration');
if (index > currentIndex) this._onNext(index);
else this._onPrev(index);
this._updateIndicatorNav(index);
}
},
_onOrientationChange: function () {
var animation = this.animation;
if (animation === 'slide') {
this._data.set('iteration',0);
this.element.css({ 'margin-left': 0 });
}
},
_onIndicatorClick: function (event) {
var indicatorNav = this._data.get('indicatorNav');
var items = indicatorNav.find('li');
var item = $(event.target);
var index = items.index(item);
var currentIndex = this._data.get('iteration');
if (index > currentIndex) this._onNext(index);
else this._onPrev(index);
this._updateIndicatorNav(index);
},
/**
* touch event handler
* @param event {Object}
* @param data {Object}
* @private
*/
_onGesture: function (event,data) {
if(this.suspended) return;
var animation = this.animation;
var distance;
if(data) distance=data.distance;
switch (event.type) {
case 'swiperight':
event.preventDefault();
if(this._isFirstSlide()){
this._resetToRunningOffsetPosition();
return;
}
if (this._data.get('readyState')) {
this._swipeExecuting=true;
this._onPrev();
this._currentOffset=0;
}
break;
case 'swipeleft':
event.preventDefault();
if(this._isLastSlide()){
this._swipeExecuting=true;
this._resetToOffsetPositionForLastItem();
return;
}
if (this._data.get('readyState')) {
this._swipeExecuting=true;
this._onNext();
this._currentOffset=0;
}
break;
case 'tap':
event.preventDefault();
var item = $(event.target);
var carouselItem;
if (item[0].nodeName.toLowerCase() === 'carousel-item') carouselItem = item;
else carouselItem = item.parents('carousel-item');
this._onSelected(carouselItem.index(), carouselItem);
break;
case 'release':
break;
}
},
_onFingerDrag:function(event,data){
if(this.suspended) return;
var animation = this.animation;
if (animation === 'multi-slide' || animation==='fade') return;
var self=this;
var ele = this._data.get('itemsContainer');
ele=ele[0];
setTimeout(function(){
if (!self._swipeExecuting){
var x=-1*data.distance.x;
self._currentOffset=x;
x+=parseInt(self._runningOffset);
self._elementTranslate(ele,x);
}
},150);
},
_onFingerEnd:function(event,data){
//var animation=this.animation;
//if (animation === 'multi-slide' || animation==='fade') return;
//this._resetToRunningOffsetPosition();
},
_getItemsWidth:function(){
if(this._itemsWidth>0) return this._itemsWidth;
else{
var width=0;
var length=this._getSize();
for(var i=0;i<length;i++){
var child=i+1;
width+=this._slideDistanceFactor(child);
}
return width;
}
},
_resetToInitialPosition:function(){
var ele = this._data.get('itemsContainer');
ele.attr('style','');
this._runningOffset=0;
this._currentOffset=0;
this._swipeExecuting=false;
this._data.set('iteration',0);
this._updateIndicatorNav(0);
},
_resetToLastPosition:function(){
var ele = this._data.get('itemsContainer');
var lastWidth=this._slideDistanceFactor('last');
var width=this._getItemsWidth();
width=width-lastWidth;
var style='margin-left:-' + width + 'px';
ele.attr('style',style);
this._runningOffset=0;
this._currentOffset=0;
this._swipeExecuting=false;
var size=this._getSize();
var index=size-1;
this._data.set('iteration',index);
this._updateIndicatorNav(index);
},
_resetToRunningOffsetPosition:function(){
var animation = this.animation;
if (animation === 'multi-slide' || animation==='fade') return;
var ele = this._data.get('itemsContainer');
ele=ele[0];
var x=this._runningOffset;
this._elementTranslate(ele,x);
},
_resetToOffsetPositionForLastItem:function(){
var animation = this.animation;
if (animation === 'multi-slide' || animation==='fade') return;
var self=this;
var ele = this._data.get('itemsContainer');
ele=ele[0];
var x=this._runningOffset;
this._elementTranslate(ele,x);
setTimeout(function(){
self._swipeExecuting=false;
},150);
},
_elementTranslate:function(ele,x){
ele.style.webkitTransform = "translate3d(" + x + "px, 0,0)";
},
/**
* element events
* @private
*/
__events: function () {
var animation = this.animation;
var isTouch = this._device.touch;
var element = this.element;
var orientationEvent = this._device.orientationEvent;
var next = this._data.get('nextNav');
var prev = this._data.get('prevNav');
if (this._data.get('size') < 1) {
next.hide();
prev.hide();
}
/* click special event name */
//var click = this._data.click;
var click = this.__press();
/* for desktop click */
if(next===undefined || prev===undefined) return;
this._event(next, click, this._onNext.bind(this));
this._event(prev, click, this._onPrev.bind(this));
/* resize */
this._event($(window), orientationEvent, this._onOrientationChange.bind(this));
/* touch swipe event handling */
if (isTouch) {
this._event(element, 'swipeleft swiperight tap', this._onGesture.bind(this));
this._event(element, 'fingerdrag', this._onFingerDrag.bind(this));
this._event(element, 'fingerend', this._onFingerEnd.bind(this));
}
},
__press: function () {