Skip to content

Commit

Permalink
added direction parameter to callbacks. fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
kswedberg committed Sep 1, 2011
1 parent 1aaf580 commit eb39b29
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 55 deletions.
82 changes: 40 additions & 42 deletions jcarousellite.js
@@ -1,7 +1,7 @@
/*!
* jQuery jCarousellite Plugin v1.4
*
* Date: Sun Aug 28 12:14:39 2011 EDT
* Date: Wed Aug 31 23:04:45 2011 EDT
* Requires: jQuery v1.4+
*
* Copyright 2007 Ganeshji Marwaha (gmarwaha.com)
Expand Down Expand Up @@ -148,53 +148,51 @@ $.fn.jCarouselLite = function(options) {
}

function go(to) {
if (!running) {

if (o.beforeStart) {
o.beforeStart.call(this, vis());
if (running) { return false; }
var direction = to > curr;
if (o.beforeStart) {
o.beforeStart.call(this, vis(), direction);
}
// If circular we are in first or last, then goto the other end
if (o.circular) {
// If first, then goto last
if (to <= start - v - 1) {
ul.css( animCss, -( (itemLength - (v*2) ) * liSize ) + "px" );
// If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
curr = to == start - v - 1 ? itemLength-(v*2) - 1 : itemLength-(v*2)-o.scroll;
} else if (to>=itemLength-v+1) { // If last, then goto first
ul.css(animCss, -( v * liSize ) + "px" );

// If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
curr = (to == itemLength - v + 1) ? v + 1 : v + o.scroll;
} else {
curr = to;
}
// If circular we are in first or last, then goto the other end
if (o.circular) {
// If first, then goto last
if (to <= start - v - 1) {
ul.css( animCss, -( (itemLength - (v*2) ) * liSize ) + "px" );
// If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
curr = to == start - v - 1 ? itemLength-(v*2) - 1 : itemLength-(v*2)-o.scroll;
} else if (to>=itemLength-v+1) { // If last, then goto first
ul.css(animCss, -( (v) * liSize ) + "px" );

// If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
curr = (to == itemLength - v + 1) ? v + 1 : v + o.scroll;
} else {
curr = to;
}

// If non-circular and to points beyond first or last, we change to first or last.
// If non-circular and to points beyond first or last, we change to first or last.
} else {
// Disable buttons when the carousel reaches the last/first, and enable when not
o.$btnPrev.toggleClass(o.btnDisabledClass, o.btnPrev && to <= 0);
o.$btnNext.toggleClass(o.btnDisabledClass, o.btnNext && to > itemLength-v);

if (to<0) {
curr = 0;
} else if (to>itemLength-v) {
curr = itemLength-v;
} else {
// Disable buttons when the carousel reaches the last/first, and enable when not
o.$btnPrev.toggleClass(o.btnDisabledClass, o.btnPrev && to <= 0);
o.$btnNext.toggleClass(o.btnDisabledClass, o.btnNext && to > itemLength-v);

if (to<0) {
curr = 0;
} else if (to>itemLength-v) {
curr = itemLength-v;
} else {
curr = to;
}
curr = to;
}
}

running = true;
aniProps[animCss] = -(curr*liSize);

ul.animate(aniProps, o.speed, o.easing, function() {
if (o.afterEnd) {
o.afterEnd.call(this, vis());
}
running = false;
});
running = true;
aniProps[animCss] = -(curr*liSize);

} // end if !running
ul.animate(aniProps, o.speed, o.easing, function() {
if (o.afterEnd) {
o.afterEnd.call(this, vis(), direction);
}
running = false;
});
return false;
} // end go function

Expand Down
16 changes: 8 additions & 8 deletions jcarousellite.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions readme.md
Expand Up @@ -242,18 +242,17 @@ example
$(".carousel").jCarouselLite({
btnNext: ".next",
btnPrev: ".prev",
beforeStart: function(a) {
beforeStart: function(a, direction) {
alert("Before animation starts:" + a);
},
afterEnd: function(a) {
afterEnd: function(a, , direction) {
alert("After animation ends:" + a);
}
});
```

If you want to do some logic before the slide starts and after the slide ends, you can
register these 2 callbacks. The functions will be passed an argument that represents an array of elements that
are visible at the time of callback.
register these 2 callbacks. The functions will be passed two arguments. The first represents an array of elements that are visible at the time of callback. The second is a Boolean indicating whether the direction is forward (`true`) or backward (`false`);

## Events

Expand All @@ -274,7 +273,7 @@ Pauses an autoscrolling carousel until `resumeCarousel` is triggered. Note: if t
example

```javascript
$(".carousel").trigger("pauseCarousel")
$(".carousel").trigger("resumeCarousel")
```

Resumes an autoscrolling carousel after having been paused.
Expand Down

0 comments on commit eb39b29

Please sign in to comment.