-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarousel.js
More file actions
1202 lines (900 loc) · 35.6 KB
/
Carousel.js
File metadata and controls
1202 lines (900 loc) · 35.6 KB
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
if(!javaxt) var javaxt={};
if(!javaxt.dhtml) javaxt.dhtml={};
//******************************************************************************
//** Carousel
//******************************************************************************
/**
* Component used to render two or more panels in a horizonal layout. Users
* can cycle through the panels using the back() and next() functions. The
* carousel can store a fixed set of panels or you can create the illusion
* of having infinite panels by updating panels when they are out of view.
* Example:
<pre>
var carousel = new javaxt.dhtml.Carousel(parent,{
loop: true,
animate: true
});
</pre>
* Once the carousel is instantiated you can call any of the public methods.
* The first thing to do is to add panels. Example:
<pre>
var p1 = document.createElement('div');
p1.style.background = "#f0f8ff";
p1.style.height = "100%";
carousel.add(p1);
var p2 = document.createElement('div');
p2.style.background = "#96a5b2";
p2.style.height = "100%";
carousel.add(p2);
var p3 = document.createElement('div');
p3.style.background = "#ffd8d6";
p3.style.height = "100%";
carousel.add(p3);
</pre>
* After panels have been added to the carousel, you can call the back() and
* next() methods to switch panels. Typically these methods are called from
* "onclick" events fired from other DOM elements (e.g. button).
*
* Finally, you can also add event listeners by overriding any of the public
* "on" or "before" methods like this:
<pre>
carousel.onChange = function(currPanel, prevPanel){
console.log("currPanel", currPanel);
};
</pre>
*
******************************************************************************/
javaxt.dhtml.Carousel = function(parent, config) {
this.className = "javaxt.dhtml.Carousel";
var me = this;
var outerDiv, innerDiv;
var currPanel;
var sliding = false;
var noselect;
var resizeListener;
var defaultConfig = {
/** If true, will animate transitions when calling the back() and next()
* functions.
*/
animate: true,
/** Time to transition between panels, in milliseconds. Only applicable
* when "animate" is set to true.
*/
animationSteps: 250.0,
/** Transition effect. Only applicable when "animate" is set to true and
* an "fx" config is given. See the javaxt.dhtml.Effects class for
* a list of options.
*/
transitionEffect: "linear",
/** An instance of a javaxt.dhtml.Effects class used to animate
* transitions. Only used when "animate" is set to true.
*/
fx: null,
/** By default, a user cannot go past the last panel in the carousel when
* calling next() or past the first panel when calling back(). However,
* when "loop" is set to true, users can go past the first/last panels
* by cloning the "next" or "previous" panel and appending it to
* the carousel so you can cycle through elements.
*/
loop: false,
/** If true, will move the next panel over the current panel during
* transitions. Only applicable when "animate" is set to true.
*/
slideOver: false,
/** If true, will allow touchscreen users to slide back and forth through
* the panels using touch gestures.
*/
drag: true,
/** Currently unused
*/
visiblePanels: 1,
/** Amount of padding between panels, in pixels.
*/
padding: 0
};
//**************************************************************************
//** Constructor
//**************************************************************************
var init = function(){
if (typeof parent === "string"){
parent = document.getElementById(parent);
}
if (!parent) return;
//Clone the config so we don't modify the original config object
var clone = {};
merge(clone, config);
//Merge clone with default config
merge(clone, defaultConfig);
config = clone;
//Update event handlers
for (var key in config) {
if (config.hasOwnProperty(key)){
if (typeof config[key] == "function") {
if (me[key] && typeof me[key] == "function"){
me[key] = config[key];
}
}
}
}
//Remove anything found inside the parent
var items = [];
if (config.items){
items = config.items;
}
else{
for (var i=0; i<parent.childNodes.length; i++){
var node = parent.childNodes[i];
if (node.nodeType===1){
items.push(node);
}
}
for (var i=0; i<items.length; i++){
parent.removeChild(items[i]);
}
parent.innerHTML = "";
}
//Create overflow divs
outerDiv = createElement('div', parent, {
width: "100%",
height: "100%",
position: "relative"
});
outerDiv.className = "javaxt-carousel";
me.el = outerDiv;
var overflowDiv = createElement('div', outerDiv, {
width: "100%",
height: "100%",
position: "absolute",
overflow: "hidden"
});
var padding = config.padding;
if (padding>0){
overflowDiv.style.padding = "0 " + padding + "px";
overflowDiv.style.left = -padding + "px";
}
outerDiv.appendChild(overflowDiv);
//Create main div used to store panels. This div will move horizontally
innerDiv = createElement('div', overflowDiv, {
left: "0px",
height: "100%",
position: "absolute"
});
if (config.drag===true){
addNoSelectRule();
initDrag(innerDiv);
}
/*
//Create logic to process touch events
var touchStartTime;
var touchEndTime;
var x1, x2, y1, y2;
innerDiv.ontouchstart = function(e) {
e.preventDefault();
x1 = e.changedTouches[0].pageX;
y1 = e.changedTouches[0].pageY;
touchStartTime = new Date().getTime();
touchEndTime = null;
};
innerDiv.ontouchend = function(e) {
touchEndTime= new Date().getTime();
x2 = e.changedTouches[0].pageX;
y2 = e.changedTouches[0].pageY;
var distance = Math.sqrt( (x2-=x1)*x2 + (y2-=y1)*y2 );
if (distance<0) distance = -distance;
var duration = touchEndTime - touchStartTime;
if (duration <= 500 && distance <= 10) {
// Person tapped their finger (do click/tap stuff here)
}
if (duration > 500 && distance <= 10) {
// Person pressed their finger (not a quick tap)
}
if (duration <= 100 && distance > 10) {
// Person flicked their finger
}
if (duration > 100 && distance > 10) {
// Person dragged their finger
}
};
*/
for (var i=0; i<items.length; i++){
me.add(items[i]);
}
//Add public show/hide methods
addShowHide(me);
//Watch for resize events
resizeListener = addResizeListener(parent, function(){
me.resize();
});
//Check whether the carousel has been added to the DOM
onRender(outerDiv, function(){
me.resize();
me.onRender();
});
};
//**************************************************************************
//** destroy
//**************************************************************************
/** Used to destroy the carousel and remove it from the DOM
*/
this.destroy = function(){
if (resizeListener) resizeListener.destroy();
me.disableAnimation();
sliding = true;
destroy(me);
me = null;
return me;
};
//**************************************************************************
//** onRender
//**************************************************************************
/** Called after the carousel has been added to the DOM
*/
this.onRender = function(){};
//**************************************************************************
//** onResize
//**************************************************************************
/** Called after the carousel has been resized
*/
this.onResize = function(){};
//**************************************************************************
//** add
//**************************************************************************
/** Used to add a panel to the carousel
*/
this.add = function(el){
//Get width of the innerDiv before adding a new panel
var w = parseInt(innerDiv.style.width);
if (isNaN(w)) w = 0;
//Create divs (for overflow purposes)
var div = createElement('div', innerDiv, {
width: outerDiv.offsetWidth+"px",
height: "100%",
position: "relative",
display: "inline-block"
});
var padding = config.padding;
if (padding>0){
div.style.width=(outerDiv.offsetWidth + (padding*2))+"px";
}
var overflowDiv = createElement('div', div, {
width: "100%",
height: "100%",
position: "absolute",
overflow: "hidden"
});
if (padding>0){
overflowDiv.style.padding = "0 " + padding + "px";
overflowDiv.style.width=outerDiv.offsetWidth+"px";
}
//Add element to the overflow div
overflowDiv.appendChild(el);
//Update width
innerDiv.style.width = (w+div.offsetWidth)+"px";
if (!currPanel) currPanel = div;
//Resize all the divs (bug fix for Chrome)
me.resize();
};
//**************************************************************************
//** clear
//**************************************************************************
/** Used to remove all the panels from the carousel
*/
this.clear = function(){
currPanel = null;
innerDiv.innerHTML = "";
innerDiv.style.left = "0px";
sliding = false;
resize();
};
//**************************************************************************
//** resize
//**************************************************************************
/** Used to force the component to resize to fit the parent container
*/
this.resize = function(){
var w = outerDiv.offsetWidth;
if (w===0 || isNaN(w)){
var timer;
var checkWidth = function(){
var w = outerDiv.offsetWidth;
if (w===0 || isNaN(w)){
timer = setTimeout(checkWidth, 100);
}
else{
clearTimeout(timer);
resize();
}
};
timer = setTimeout(checkWidth, 100);
}
else{
resize();
}
};
var resize = function(){
//Compute width of individual panels
var width = outerDiv.offsetWidth;
var padding = config.padding;
if (padding>0){
width += (padding*2);
}
//Update panel container
var numPanels = innerDiv.childNodes.length;
innerDiv.style.width = (width*numPanels) + "px";
//Update individual panels
var currPanelIdx = 0;
for (var i=0; i<numPanels; i++){
innerDiv.childNodes[i].style.width = width + "px";
if (padding>0){
var overflowDiv = innerDiv.childNodes[i].childNodes[0];
overflowDiv.style.width=outerDiv.offsetWidth+"px";
}
if (innerDiv.childNodes[i]==currPanel){
currPanelIdx = i;
}
}
me.onResize();
//Update position
if (sliding) return;
innerDiv.style.left = -(currPanelIdx*width)+"px";
};
//**************************************************************************
//** slide
//**************************************************************************
var slide = function(el, start, end, lastTick, timeLeft, callback){
if (config.fx){
setTimeout(function(){
config.fx.setTransition(el, config.transitionEffect, config.animationSteps);
el.style.left = end+"px";
setTimeout(function(){
el.style.WebkitTransition =
el.style.MozTransition =
el.style.MsTransition =
el.style.OTransition =
el.style.transition = "";
if (callback) callback.apply(me, []);
}, config.animationSteps+50);
}, 50);
}
else{
var curTick = new Date().getTime();
var elapsedTicks = curTick - lastTick;
//If the animation is complete, ensure that the panel is completely visible
if (timeLeft <= elapsedTicks){
el.style.left = end+"px";
if (callback) callback.apply(me, []);
return;
}
timeLeft -= elapsedTicks;
var d = start-end;
var percentComplete = 1-(timeLeft/config.animationSteps);
var offset = Math.round(percentComplete * d);
el.style.left = start-offset + "px";
setTimeout(function(){
slide(el, start, end, curTick, timeLeft, callback);
}, 33);
}
};
//**************************************************************************
//** next
//**************************************************************************
/** Used to make the next panel visible. In a horizontal configuration, the
* active panel will slide left.
*/
this.next = function(){
if (config.animate===true){
if (sliding) return;
sliding = true;
}
var start = parseInt(innerDiv.style.left);
var w;
var currDiv = currPanel.childNodes[0].childNodes[0];
var nextDiv;
var next = function(callback){
var end = start-w;
if (config.animate===true){
slide(innerDiv, start, end, new Date().getTime(), config.animationSteps, callback);
}
else{
innerDiv.style.left = end+"px";
if (callback) callback.apply(me, []);
}
};
var raiseDiv = function(div){
//Get y-offset of nextPanel
var s = 0;
for (var i=0; i<innerDiv.childNodes.length; i++){
var p = innerDiv.childNodes[i];
s+=p.offsetWidth;
if (p===currPanel) break;
}
//Update div to be an absolute div
div.style.display = "none";
currPanel.style.marginRight = w +"px";
div.style.position = "absolute";
div.style.zIndex = 2;
div.style.left = s + "px";
div.style.top = "0px";
div.style.display = "";
return s;
};
var lowerDiv = function(div){
div.style.display = "inline-block";
div.style.position = "relative";
div.style.zIndex = "";
div.style.left = "";
div.style.top = "";
};
var nextPanel = currPanel.nextSibling;
if (nextPanel) {
nextDiv = nextPanel.childNodes[0].childNodes[0];
me.beforeChange(currDiv, nextDiv, "next");
var onChange = function(){
me.onChange(nextDiv, currDiv);
currPanel = nextPanel;
sliding = false;
};
w = nextPanel.offsetWidth;
if (config.slideOver===true && config.animate===true){
//Update nextPanel to be an absolute div
var s = raiseDiv(nextPanel);
//Slide nextPanel over currPanel
slide(nextPanel, s, s-w, new Date().getTime(), config.animationSteps, function(){
//Slide innerDiv
var end = start-w;
innerDiv.style.left = end+"px";
currPanel.style.marginRight = "0px";
//Update nextPanel to it's original state (e.g. relative div)
lowerDiv(nextPanel);
//Call onChange
onChange();
});
}
else{
next(onChange);
}
}
else{
if (config.loop===true){
var firstDiv = innerDiv.childNodes[0];
w = firstDiv.offsetWidth;
var clone = firstDiv.cloneNode(true);
innerDiv.style.width = (innerDiv.offsetWidth+w)+"px";
innerDiv.appendChild(clone);
nextDiv = clone.childNodes[0].childNodes[0];
me.beforeChange(currDiv, nextDiv, "next");
var onChange = function(){
innerDiv.style.left = start + "px";
innerDiv.removeChild(firstDiv);
innerDiv.style.width = (innerDiv.offsetWidth-w)+"px";
me.onChange(nextDiv, currDiv);
currPanel = clone;
sliding = false;
};
if (config.slideOver===true && config.animate===true){
//Update clone to be an absolute div
var s = raiseDiv(clone);
//Slide nextPanel over currPanel
slide(clone, s, s-w, new Date().getTime(), config.animationSteps, function(){
//Slide innerDiv
currPanel.style.marginRight = "0px";
//Update clone to it's original state (e.g. relative div)
lowerDiv(clone);
//Call onChange
onChange();
});
}
else{
next(onChange);
}
}
else{
sliding = false;
}
}
};
//**************************************************************************
//** back
//**************************************************************************
/** Used to make the previous panel visible. In a horizontal configuration,
* the active panel will slide right.
*/
this.back = function(){
if (config.animate===true){
if (sliding) return;
sliding = true;
}
var start, end, w;
var currDiv = currPanel.childNodes[0].childNodes[0];
var nextDiv;
var back = function(callback){
if (config.animate===true){
slide(innerDiv, start, end, new Date().getTime(), config.animationSteps, callback);
}
else{
innerDiv.style.left = end+"px";
if (callback) callback.apply(me, []);
}
};
var raiseDiv = function(div){
//Get y-offset of div
var s = 0;
for (var i=0; i<innerDiv.childNodes.length; i++){
var p = innerDiv.childNodes[i];
if (p===div) break;
s+=p.offsetWidth;
}
//Update div to be an absolute div
div.style.display = "none";
currPanel.style.marginLeft = w +"px";
div.style.position = "absolute";
div.style.zIndex = 2;
div.style.left = s + "px";
div.style.top = "0px";
div.style.display = "";
return s;
};
var lowerDiv = function(div){
div.style.display = "inline-block";
div.style.position = "relative";
div.style.zIndex = "";
div.style.left = "";
div.style.top = "";
};
var nextPanel = currPanel.previousSibling;
if (nextPanel){
nextDiv = nextPanel.childNodes[0].childNodes[0];
me.beforeChange(currDiv, nextDiv, "back");
var onChange = function(){
me.onChange(nextDiv, currDiv);
currPanel = nextPanel;
sliding = false;
};
w = nextPanel.offsetWidth;
start = parseFloat(innerDiv.style.left);
end = start + w;
if (config.slideOver===true && config.animate===true){
//Update nextPanel to be an absolute div
var s = raiseDiv(nextPanel);
//Slide nextPanel over currPanel
slide(nextPanel, s, s+w, new Date().getTime(), config.animationSteps, function(){
//Slide innerDiv
innerDiv.style.left = end+"px";
currPanel.style.marginLeft = "0px";
//Update nextPanel to it's original state (e.g. relative div)
lowerDiv(nextPanel);
//Call onChange
onChange();
});
}
else{
back(onChange);
}
}
else{
if (config.loop===true){
var lastDiv = innerDiv.childNodes[innerDiv.childNodes.length-1];
w = lastDiv.offsetWidth;
var clone = lastDiv.cloneNode(true);
innerDiv.style.width = (innerDiv.offsetWidth+w)+"px";
innerDiv.insertBefore(clone, innerDiv.firstChild);
nextDiv = clone.childNodes[0].childNodes[0];
me.beforeChange(currDiv, nextDiv, "back");
var onChange = function(){
me.onChange(nextDiv, currDiv);
currPanel = clone;
sliding = false;
};
start = -w;
end = 0;
if (config.slideOver===true && config.animate===true){
//Update clone to be an absolute div
raiseDiv(clone);
var s = -w;
clone.style.left = s + "px";
innerDiv.style.width = (innerDiv.offsetWidth-w)+"px";
currPanel.style.marginLeft = "0px";
//Slide clone over currPanel
slide(clone, s, s+w, new Date().getTime(), config.animationSteps, function(){
//Remove lastDiv
innerDiv.removeChild(lastDiv);
//Update clone to it's original state (e.g. relative div)
lowerDiv(clone);
//Call onChange
onChange();
});
}
else{
innerDiv.style.left = start + "px";
back(function(){
innerDiv.removeChild(lastDiv);
innerDiv.style.width = (innerDiv.offsetWidth-w)+"px";
onChange();
});
}
}
else{
sliding = false;
}
}
};
//**************************************************************************
//** onChange
//**************************************************************************
/** Called after the carousel switches panels
* @param currPanel Content of the active panel
* @param prevPanel Content of the previously active panel
*/
this.onChange = function(currPanel, prevPanel){};
//**************************************************************************
//** beforeChange
//**************************************************************************
/** Called before the carousel switches panels.
* @param currPanel Content of the active panel
* @param prevPanel Content of the next active panel
* @param direction "back" or "next"
*/
this.beforeChange = function(currPanel, nextPanel, direction){};
//**************************************************************************
//** getPanels
//**************************************************************************
/** Returns an array with information for each panel in the carousel. Each
* element in the array contains the following information:
* <ul>
* <li>div: DOM element associated with the panel</li>
* <li>isVisible: Used to indicate whether the panel is intersects the
* parent container</li>
* <li>visibleArea: Total area that the panel covers in the parent
* container</li>
* </ul>
*/
this.getPanels = function(){
var arr = [];
var r1 = _getRect(outerDiv);
var n = parseInt(config.padding);
if (isNaN(n)) n = 0;
for (var i=0; i<innerDiv.childNodes.length; i++){
var panel = innerDiv.childNodes[i];
var r2 = _getRect(panel);
var isVisible = false; //intersects(r1, r2);
var leftOverlap = 0;
var rightOverlap = 0;
if (r2.right > r1.left && r2.left < r1.right){
isVisible = true;
if (r2.right < r1.right){
leftOverlap = r2.right - r1.left;
}
else{
rightOverlap = r1.right - r2.left;
}
}
if (isVisible){
if ((leftOverlap-n>0 && leftOverlap-n<1) || (rightOverlap-n>0 && rightOverlap-n<1)){
isVisible = false;
}
}
arr.push({
div: panel.childNodes[0].childNodes[0],
isVisible: isVisible,
visibleArea: getAreaOfIntersection(r1, r2)
});
}
return arr;
};
//**************************************************************************
//** enableAnimation
//**************************************************************************
/** Used to enable animations when transitioning between panels
*/
this.enableAnimation = function(){
config.animate = true;
};
//**************************************************************************
//** disableAnimation
//**************************************************************************
/** Used to disable animations when transitioning between panels
*/
this.disableAnimation = function(){
config.animate = false;
};
//**************************************************************************
//** initDrag
//**************************************************************************
var initDrag = function(){
//This is how many milliseconds to wait before recognizing a hold
var holdDelay = 50;
var startX, offsetX;
var prevPanel;
//Function called when a drag is initiated
var onDragStart = function(e){
startX = e.clientX;
offsetX = parseInt(innerDiv.style.left);
//Disable text selection in the entire document - very important!
var body = document.getElementsByTagName('body')[0];
if (!body.className.match(/(?:^|\s)javaxt-noselect(?!\S)/) ){
body.className += (body.className.length==0 ? "" : " ") + "javaxt-noselect";
}
prevPanel = currPanel;
innerDiv.style.cursor = 'move';
};
//Function called while the div is being dragged
var onDrag = function(e){
var x = e.clientX;
var d = startX-x; //If d is positive, client is sliding to the right.
//Otherwise, client is sliding to the left.
var left = offsetX-d;
innerDiv.style.left = left + 'px';
if (left>0){ //dragged to the left beyond the first div
if (config.loop===true){
var previousDiv = currPanel.previousSibling;
if (previousDiv){
}
else{
//Clone the last div and insert it to the left
var lastDiv = innerDiv.childNodes[innerDiv.childNodes.length-1];
var w = lastDiv.offsetWidth;
var clone = lastDiv.cloneNode(true);
innerDiv.insertBefore(clone, innerDiv.firstChild);
innerDiv.removeChild(lastDiv);
innerDiv.style.left = (-w+parseInt(innerDiv.style.left)) + "px";
startX+=w;
currPanel = clone;
}
}
else{
//Prevent dragging any further to the right
}
}
else{
//Compute max offset
var x = 0;
var lastDivWidth = 0;
for (var i=0; i<innerDiv.childNodes.length; i++){
var w = innerDiv.childNodes[i].offsetWidth;
x = x-w;
lastDivWidth = w;