Skip to content

Commit 9abf5af

Browse files
author
Jesse Allen
committed
Handling one or zero items with circular
Having one item with circular set to true resulted in a single item cloned and scrolling, which is not a desirable condition. Having zero items with circular set to true resulted in an error. By enforcing a check more similar to the one performed when circular is false, we are able to catch this condition. Additionally, the prev and next buttons are set to disabled in the case of one or zero items.
1 parent d65b237 commit 9abf5af

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/scrollable/scrollable.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,12 @@
192192
};
193193
});
194194

195+
// next/prev buttons
196+
var prev = find(root, conf.prev).click(function() { self.prev(); }),
197+
next = find(root, conf.next).click(function() { self.next(); });
198+
195199
// circular loop
196-
if (conf.circular) {
200+
if (conf.circular && self.getSize() > 1) {
197201

198202
var cloned1 = self.getItems().slice(-1).clone().prependTo(itemWrap),
199203
cloned2 = self.getItems().eq(1).clone().appendTo(itemWrap);
@@ -225,13 +229,8 @@
225229

226230
// seek over the cloned item
227231
self.seekTo(0, 0, function() {});
228-
}
229-
230-
// next/prev buttons
231-
var prev = find(root, conf.prev).click(function() { self.prev(); }),
232-
next = find(root, conf.next).click(function() { self.next(); });
233-
234-
if (!conf.circular && self.getSize() > 1) {
232+
233+
} else if (!conf.circular && self.getSize() > 1) {
235234

236235
self.onBeforeSeek(function(e, i) {
237236
setTimeout(function() {
@@ -245,6 +244,9 @@
245244
if (!conf.initialIndex) {
246245
prev.addClass(conf.disabledClass);
247246
}
247+
} else { // the case where there is one or zero items
248+
prev.addClass(conf.disabledClass);
249+
next.addClass(conf.disabledClass);
248250
}
249251

250252
// mousewheel support

0 commit comments

Comments
 (0)