Skip to content

Commit 6f3192f

Browse files
committed
Issue 169: slideshow behaviour now similar to autoscroll. hitting play() won't proceed to next tab automatically. simplified code.
1 parent 7f70550 commit 6f3192f

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

src/scrollable/scrollable.autoscroll.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
// interval stuff
4040
var timer, stopped = true;
4141

42-
api.play = function() {
43-
42+
api.play = function() {
4443

4544
// do not start additional timer if already exists
4645
if (timer) { return; }

src/tabs/tabs.slideshow.js

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@
3333
fire = root.add(this),
3434
tabs = root.data("tabs"),
3535
timer,
36-
hoverTimer,
37-
startTimer,
38-
stopped = false;
36+
stopped = true;
3937

4038

4139
// next / prev buttons
@@ -51,7 +49,7 @@
5149
var prevButton = find(conf.prev).click(function() {
5250
tabs.prev();
5351
});
54-
52+
5553

5654
// extend the Tabs API with slideshow methods
5755
$.extend(self, {
@@ -68,39 +66,39 @@
6866
play: function() {
6967

7068
// do not start additional timer if already exists
71-
if (timer) { return; }
69+
if (timer) { return self; }
7270

7371
// onBeforePlay
7472
var e = $.Event("onBeforePlay");
75-
fire.trigger(e);
76-
73+
fire.trigger(e);
7774
if (e.isDefaultPrevented()) { return self; }
7875

79-
stopped = false;
8076

8177
// construct new timer
8278
timer = setInterval(tabs.next, conf.interval);
83-
79+
stopped = false;
80+
8481
// onPlay
8582
fire.trigger("onPlay");
8683

87-
tabs.next();
84+
return self;
8885
},
8986

9087
pause: function() {
9188

92-
if (!timer && !startTimer) { return self; }
89+
if (!timer) { return self; }
9390

9491
// onBeforePause
9592
var e = $.Event("onBeforePause");
9693
fire.trigger(e);
9794
if (e.isDefaultPrevented()) { return self; }
9895

9996
timer = clearInterval(timer);
100-
startTimer = clearInterval(startTimer);
10197

10298
// onPause
103-
fire.trigger("onPause");
99+
fire.trigger("onPause");
100+
101+
return self;
104102
},
105103

106104
// when stopped - mouseover won't restart
@@ -116,35 +114,25 @@
116114

117115
// configuration
118116
if ($.isFunction(conf[name])) {
119-
self.bind(name, conf[name]);
117+
$(self).bind(name, conf[name]);
120118
}
121119

122120
// API methods
123121
self[name] = function(fn) {
124-
return self.bind(name, fn);
122+
return $(self).bind(name, fn);
125123
};
126124
});
127125

128126

129127
/* when mouse enters, slideshow stops */
130128
if (conf.autopause) {
131-
var els = tabs.getTabs().add(nextButton).add(prevButton).add(tabs.getPanes());
132-
133-
els.hover(function() {
134-
self.pause();
135-
hoverTimer = clearInterval(hoverTimer);
136-
137-
}, function() {
138-
if (!stopped) {
139-
hoverTimer = setTimeout(self.play, conf.interval);
140-
}
129+
tabs.getTabs().add(nextButton).add(prevButton).add(tabs.getPanes()).hover(self.pause, function() {
130+
if (!stopped) { self.play(); }
141131
});
142132
}
143133

144134
if (conf.autoplay) {
145-
startTimer = setTimeout(self.play, conf.interval);
146-
} else {
147-
self.stop();
135+
self.play();
148136
}
149137

150138
if (conf.clickable) {
@@ -156,23 +144,15 @@
156144
// manage disabling of next/prev buttons
157145
if (!tabs.getConf().rotate) {
158146

159-
var cls = conf.disabledClass;
147+
var disabled = conf.disabledClass;
160148

161149
if (!tabs.getIndex()) {
162-
prevButton.addClass(cls);
150+
prevButton.addClass(disabled);
163151
}
164-
tabs.onBeforeClick(function(e, i) {
165-
if (!i) {
166-
prevButton.addClass(cls);
167-
} else {
168-
prevButton.removeClass(cls);
169-
170-
if (i == tabs.getTabs().length -1) {
171-
nextButton.addClass(cls);
172-
} else {
173-
nextButton.removeClass(cls);
174-
}
175-
}
152+
153+
tabs.onBeforeClick(function(e, i) {
154+
prevButton.toggleClass(disabled, !i);
155+
nextButton.toggleClass(disabled, i == tabs.getTabs().length -1);
176156
});
177157
}
178158
}

test/tabs/slideshow.htm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<script src="../../src/tabs/tabs.slideshow.js"></script>
55
<link rel="stylesheet" type="text/css" href="css/tabs.css"/>
66

7+
<style>
8+
.disabled {
9+
visibility:hidden;
10+
}
11+
</style>
712

813
<!-- tabs -->
914
<ul class="tabs">
@@ -45,11 +50,27 @@
4550
</div>
4651
</div>
4752

53+
<button class="backward">Prev</button>
54+
<button class="forward">Next</button>
4855

4956
<script>
5057
var api = $(".tabs").tabs(".pane", { rotate: true }).slideshow({
51-
autoplay: true,
52-
interval: 1000
58+
effect: 'fade',
59+
fadeOutSpeed: "slow",
60+
interval: 1000,
61+
62+
onBeforePlay: function() {
63+
console.info("onBeforePlay");
64+
},
65+
onPlay: function() {
66+
console.info("onPlay");
67+
},
68+
onBeforePause: function() {
69+
console.info("onBeforePause");
70+
},
71+
onPause: function() {
72+
console.info("onPause");
73+
}
5374

5475
}).data("slideshow");
5576
</script>
@@ -58,3 +79,4 @@
5879
<button onClick='api.stop();'>Stop</button>
5980

6081

82+

0 commit comments

Comments
 (0)