Skip to content

Commit 8f7da7c

Browse files
committed
Issue 189. next/prev buttons are now disabled if there is nothing to scroll
1 parent b75f8fd commit 8f7da7c

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/scrollable/scrollable.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125

126126
if (!conf.circular) {
127127
itemWrap.append(item);
128+
next.removeClass("disabled");
129+
128130
} else {
129131
itemWrap.children("." + conf.clonedClass + ":last").before(item);
130132
itemWrap.children("." + conf.clonedClass + ":first").replaceWith(item.clone().addClass(conf.clonedClass));
@@ -229,10 +231,9 @@
229231

230232
// next/prev buttons
231233
var prev = find(root, conf.prev).click(function() { self.prev(); }),
232-
next = find(root, conf.next).click(function() { self.next(); });
234+
next = find(root, conf.next).click(function() { self.next(); });
233235

234-
if (!conf.circular && self.getSize() > 1) {
235-
236+
if (!conf.circular) {
236237
self.onBeforeSeek(function(e, i) {
237238
setTimeout(function() {
238239
if (!e.isDefaultPrevented()) {
@@ -241,10 +242,14 @@
241242
}
242243
}, 1);
243244
});
245+
}
246+
247+
if (!conf.initialIndex) {
248+
prev.addClass(conf.disabledClass);
249+
}
244250

245-
if (!conf.initialIndex) {
246-
prev.addClass(conf.disabledClass);
247-
}
251+
if (self.getSize() < 2) {
252+
prev.add(next).addClass(conf.disabledClass);
248253
}
249254

250255
// mousewheel support

test/scrollable/single.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
<script src="../../src/scrollable/scrollable.js"></script>
44

55
<link rel="stylesheet" type="text/css" href="style.css"/>
6+
<style>
7+
.disabled {
8+
visibility:hidden;
9+
}
10+
</style>
611

712
<script>
813
$(function() {
9-
$(".scrollable").scrollable({
14+
var api = $(".scrollable").scrollable({
1015
onSeek: function() {
1116
console.info("jou");
1217
}
13-
});
18+
}).data("scrollable");
19+
20+
api.addItem("<div>added</div>");
1421
});
1522
</script>
1623

@@ -25,12 +32,12 @@
2532

2633
<div class="items">
2734
<div>0</div>
28-
<div>1</div>
35+
<!-- <div>1</div>
2936
<div>2</div>
3037
<div>3</div>
3138
<div>4</div>
3239
<div>5</div>
33-
<div>6</div>
40+
<div>6</div> -->
3441
</div>
3542

3643
</div>

0 commit comments

Comments
 (0)