Permalink
Browse files

added direction parameter to callbacks. fixes #2

  • Loading branch information...
1 parent 1aaf580 commit eb39b29f49f2957cae523700050397fc2c69112b @kswedberg committed Sep 1, 2011
Showing with 52 additions and 55 deletions.
  1. +40 −42 jcarousellite.js
  2. +8 −8 jcarousellite.min.js
  3. +4 −5 readme.md
View
@@ -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)
@@ -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
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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
@@ -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.

0 comments on commit eb39b29

Please sign in to comment.