Skip to content

Commit d2ffa58

Browse files
committed
Fixed bug where the beforeChange event was not being called when dragging panels in the Carousel control. Also added "dragCursor" config and new onDragStart and onDragEnd events.
1 parent 29c782a commit d2ffa58

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

src/carousel/Carousel.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,18 @@ javaxt.dhtml.Carousel = function(parent, config) {
100100
slideOver: false,
101101

102102

103-
/** If true, will allow touchscreen users to slide back and forth through
104-
* the panels using touch gestures.
103+
/** If true, will allow users to slide back and forth through the panels
104+
* using touch gestures.
105105
*/
106106
drag: true,
107107

108108

109+
/** Cursor style when dragging. Only applicable when "drag" is set to
110+
* true.
111+
*/
112+
dragCursor: "ew-resize", //grabbing
113+
114+
109115
/** Currently unused
110116
*/
111117
visiblePanels: 1,
@@ -844,6 +850,24 @@ javaxt.dhtml.Carousel = function(parent, config) {
844850
this.beforeChange = function(currPanel, nextPanel, direction){};
845851

846852

853+
//**************************************************************************
854+
//** onDragStart
855+
//**************************************************************************
856+
/** Called when a client begins to drag a panel in the carousel
857+
* @param currPanel Content of the active panel
858+
*/
859+
this.onDragStart = function(currPanel){};
860+
861+
862+
//**************************************************************************
863+
//** onDragEnd
864+
//**************************************************************************
865+
/** Called when a client completes a drag event
866+
* @param currPanel Content of the active panel
867+
*/
868+
this.onDragEnd = function(currPanel){};
869+
870+
847871
//**************************************************************************
848872
//** getPanels
849873
//**************************************************************************
@@ -932,6 +956,8 @@ javaxt.dhtml.Carousel = function(parent, config) {
932956

933957
//Function called when a drag is initiated
934958
var onDragStart = function(e){
959+
me.onDragStart(currPanel.childNodes[0].childNodes[0]);
960+
935961
startX = e.clientX;
936962
offsetX = parseInt(innerDiv.style.left);
937963

@@ -945,7 +971,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
945971

946972

947973
prevPanel = currPanel;
948-
innerDiv.style.cursor = 'move';
974+
innerDiv.style.cursor = config.dragCursor;
949975
};
950976

951977

@@ -1082,10 +1108,17 @@ javaxt.dhtml.Carousel = function(parent, config) {
10821108
if (animationSteps<0) animationSteps = -animationSteps;
10831109
//console.log(start + "/" + end + " --> move " + (start-end) + "px in " + animationSteps + "ms");
10841110

1111+
var direction = (start-end)>0 ? "next" : "back";
1112+
1113+
1114+
10851115
slide(innerDiv, start, end, new Date().getTime(), 100, function(){
10861116
currPanel = innerDiv.childNodes[visiblePanel];
1117+
var nextPanel = currPanel.childNodes[0].childNodes[0];
1118+
me.onDragEnd(nextPanel);
10871119
if (currPanel!=prevPanel){
1088-
me.onChange(currPanel.childNodes[0].childNodes[0], prevPanel.childNodes[0].childNodes[0]);
1120+
me.beforeChange(prevPanel.childNodes[0].childNodes[0], nextPanel, direction);
1121+
me.onChange(nextPanel, prevPanel.childNodes[0].childNodes[0]);
10891122
}
10901123
});
10911124

@@ -1108,6 +1141,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
11081141
//MouseDown
11091142
innerDiv.onmousedown = function(e){
11101143
if (sliding) return;
1144+
if (e.button>0) return;
11111145

11121146
// Do not take any immediate action - just set the holdStarter
11131147
// to wait for the predetermined delay, and then begin a hold
@@ -1162,7 +1196,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
11621196
document.detachEvent("onmousemove", onDrag);
11631197
document.detachEvent("onmouseup", onMouseUp);
11641198
}
1165-
innerDiv.style.cursor = 'pointer';
1199+
innerDiv.style.cursor = '';
11661200
onDragEnd();
11671201

11681202
//Remove the "javaxt-noselect" class

0 commit comments

Comments
 (0)