Skip to content

Commit 5b7acae

Browse files
committed
Added "direction" to the beforeChange event in the Carousel
1 parent f3edb43 commit 5b7acae

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

src/carousel/Carousel.js

+45-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,42 @@ if(!javaxt.dhtml) javaxt.dhtml={};
99
* can cycle through the panels using the back() and next() functions. The
1010
* carousel can store a fixed set of panels or you can create the illusion
1111
* of having infinite panels by updating panels when they are out of view.
12+
* Example:
13+
<pre>
14+
var carousel = new javaxt.dhtml.Carousel(parent,{
15+
loop: true,
16+
animate: true
17+
});
18+
</pre>
19+
* Once the carousel is instantiated you can call any of the public methods.
20+
* The first thing to do is to add panels. Example:
21+
<pre>
22+
var p1 = document.createElement('div');
23+
p1.style.background = "#f0f8ff";
24+
p1.style.height = "100%";
25+
carousel.add(p1);
26+
27+
var p2 = document.createElement('div');
28+
p2.style.background = "#96a5b2";
29+
p2.style.height = "100%";
30+
carousel.add(p2);
31+
32+
var p3 = document.createElement('div');
33+
p3.style.background = "#ffd8d6";
34+
p3.style.height = "100%";
35+
carousel.add(p3);
36+
</pre>
37+
* After panels have been added to the carousel, you can call the back() and
38+
* next() methods to switch panels. Typically these methods are called from
39+
* "onclick" events fired from other DOM elements (e.g. button).
40+
*
41+
* Finally, you can also add event listeners by overriding any of the public
42+
* "on" or "before" methods like this:
43+
<pre>
44+
carousel.onChange = function(currPanel, prevPanel){
45+
console.log("currPanel", currPanel);
46+
};
47+
</pre>
1248
*
1349
******************************************************************************/
1450

@@ -140,7 +176,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
140176
height: "100%",
141177
position: "relative"
142178
});
143-
outerDiv.setAttribute("desc", me.className);
179+
outerDiv.className = "javaxt-carousel";
144180
me.el = outerDiv;
145181

146182

@@ -337,6 +373,8 @@ javaxt.dhtml.Carousel = function(parent, config) {
337373
//**************************************************************************
338374
//** resize
339375
//**************************************************************************
376+
/** Used to force the component to resize to fit the parent container
377+
*/
340378
this.resize = function(){
341379
var w = outerDiv.offsetWidth;
342380
if (w===0 || isNaN(w)){
@@ -528,7 +566,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
528566
nextDiv = nextPanel.childNodes[0].childNodes[0];
529567

530568

531-
me.beforeChange(currDiv, nextDiv);
569+
me.beforeChange(currDiv, nextDiv, "next");
532570

533571
var onChange = function(){
534572
me.onChange(nextDiv, currDiv);
@@ -574,7 +612,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
574612

575613
nextDiv = clone.childNodes[0].childNodes[0];
576614

577-
me.beforeChange(currDiv, nextDiv);
615+
me.beforeChange(currDiv, nextDiv, "next");
578616

579617
var onChange = function(){
580618
innerDiv.style.left = start + "px";
@@ -682,7 +720,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
682720

683721
nextDiv = nextPanel.childNodes[0].childNodes[0];
684722

685-
me.beforeChange(currDiv, nextDiv);
723+
me.beforeChange(currDiv, nextDiv, "back");
686724

687725
var onChange = function(){
688726
me.onChange(nextDiv, currDiv);
@@ -729,7 +767,7 @@ javaxt.dhtml.Carousel = function(parent, config) {
729767

730768
nextDiv = clone.childNodes[0].childNodes[0];
731769

732-
me.beforeChange(currDiv, nextDiv);
770+
me.beforeChange(currDiv, nextDiv, "back");
733771

734772
var onChange = function(){
735773
me.onChange(nextDiv, currDiv);
@@ -801,8 +839,9 @@ javaxt.dhtml.Carousel = function(parent, config) {
801839
/** Called before the carousel switches panels.
802840
* @param currPanel Content of the active panel
803841
* @param prevPanel Content of the next active panel
842+
* @param direction "back" or "next"
804843
*/
805-
this.beforeChange = function(currPanel, nextPanel){};
844+
this.beforeChange = function(currPanel, nextPanel, direction){};
806845

807846

808847
//**************************************************************************

0 commit comments

Comments
 (0)