Permalink
Browse files

Fire button callbacks also if no buttons are specified (Closes #39)

  • Loading branch information...
1 parent e7c2858 commit f10693dbd806afe5e50e56781fe13f453d4a19e8 @jsor committed Sep 7, 2010
Showing with 38 additions and 19 deletions.
  1. +38 −19 lib/jquery.jcarousel.js
View
@@ -62,11 +62,13 @@
this.locked = false;
- this.container = null;
- this.clip = null;
- this.list = null;
- this.buttonNext = null;
- this.buttonPrev = null;
+ this.container = null;
+ this.clip = null;
+ this.list = null;
+ this.buttonNext = null;
+ this.buttonPrev = null;
+ this.buttonNextState = null;
+ this.buttonPrevState = null;
// Only set if not explicitly passed as option
if (!o || o.rtl === undefined) {
@@ -803,27 +805,44 @@
var self = this;
- this.buttonNext.unbind(this.options.buttonNextEvent + '.jcarousel', this.funcNext);
- this.buttonPrev.unbind(this.options.buttonPrevEvent + '.jcarousel', this.funcPrev);
+ if (this.buttonNext.size() > 0) {
+ this.buttonNext.unbind(this.options.buttonNextEvent + '.jcarousel', this.funcNext);
- if (n) {
- this.buttonNext.bind(this.options.buttonNextEvent + '.jcarousel', this.funcNext);
- }
+ if (n) {
+ this.buttonNext.bind(this.options.buttonNextEvent + '.jcarousel', this.funcNext);
+ }
- if (p) {
- this.buttonPrev.bind(this.options.buttonPrevEvent + '.jcarousel', this.funcPrev);
+ this.buttonNext[n ? 'removeClass' : 'addClass'](this.className('jcarousel-next-disabled')).attr('disabled', n ? false : true);
+
+ if (this.options.buttonNextCallback !== null && this.buttonNext.data('jcarouselstate') != n) {
+ this.buttonNext.each(function() { self.options.buttonNextCallback(self, this, n); }).data('jcarouselstate', n);
+ }
+ } else {
+ if (this.options.buttonNextCallback !== null && this.buttonNextState != n) {
+ this.options.buttonNextCallback(self, null, n);
+ }
}
- this.buttonNext[n ? 'removeClass' : 'addClass'](this.className('jcarousel-next-disabled')).attr('disabled', n ? false : true);
- this.buttonPrev[p ? 'removeClass' : 'addClass'](this.className('jcarousel-prev-disabled')).attr('disabled', p ? false : true);
+ if (this.buttonPrev.size() > 0) {
+ this.buttonPrev.unbind(this.options.buttonPrevEvent + '.jcarousel', this.funcPrev);
- if (this.options.buttonNextCallback !== null && this.buttonNext.data('jcarouselstate') != n) {
- this.buttonNext.each(function() { self.options.buttonNextCallback(self, this, n); }).data('jcarouselstate', n);
- }
+ if (p) {
+ this.buttonPrev.bind(this.options.buttonPrevEvent + '.jcarousel', this.funcPrev);
+ }
- if (this.options.buttonPrevCallback !== null && (this.buttonPrev.data('jcarouselstate') != p)) {
- this.buttonPrev.each(function() { self.options.buttonPrevCallback(self, this, p); }).data('jcarouselstate', p);
+ this.buttonPrev[p ? 'removeClass' : 'addClass'](this.className('jcarousel-prev-disabled')).attr('disabled', p ? false : true);
+
+ if (this.options.buttonPrevCallback !== null && this.buttonPrev.data('jcarouselstate') != p) {
+ this.buttonPrev.each(function() { self.options.buttonPrevCallback(self, this, p); }).data('jcarouselstate', p);
+ }
+ } else {
+ if (this.options.buttonPrevCallback !== null && this.buttonPrevState != p) {
+ this.options.buttonPrevCallback(self, null, p);
+ }
}
+
+ this.buttonNextState = n;
+ this.buttonPrevState = p;
},
/**

0 comments on commit f10693d

Please sign in to comment.