Skip to content

Commit e91d8bb

Browse files
author
Kai Schlamp
committed
Fixed a bug when nextItem returned null. Renamed next to nextItem. Renamed slidingTime to scrollTime. More tests.
1 parent 37354da commit e91d8bb

File tree

8 files changed

+90
-34
lines changed

8 files changed

+90
-34
lines changed

tests/unit/ticker/ticker_core.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,24 @@ var el;
88

99
module("ticker: core");
1010

11+
test("nextItem returns null", function() {
12+
expect(2);
13+
stop();
14+
15+
$("#ticker").ticker({
16+
initialTimeout: 0,
17+
scrollTime: 0,
18+
fadeTime: 0,
19+
nextItem: function(lastItem) {
20+
ok(true, "nextItem is called")
21+
return null;
22+
}
23+
});
24+
25+
window.setTimeout(function() {
26+
equals($("#ticker li:first").text(), "Item1", "ticker has not scrolled");
27+
start();
28+
}, 100);
29+
});
30+
1131
})(jQuery);

tests/unit/ticker/ticker_defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ var ticker_defaults = {
88
initialTimeout: 4000,
99
mouseOnTimeout: 8000,
1010
mouseOffTimeout: 4000,
11-
slidingTime: 800,
11+
scrollTime: 800,
1212
fadeTime: 1000,
13-
next: null
13+
nextItem: null
1414
};
1515

1616
commonWidgetTests('ticker', { defaults: ticker_defaults });

tests/unit/ticker/ticker_events.js

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ test("beforeScroll", function() {
1111

1212
$("#ticker").ticker({
1313
initialTimeout: 0,
14-
slidingTime: 0,
14+
scrollTime: 0,
1515
fadeTime: 0,
16-
next: function(lastItem) { return '<li>TestItem</li>'; },
16+
nextItem: function(lastItem) { return $('<li>TestItem</li>'); },
1717
beforeScroll: function(event, ui) {
1818
ok(true, 'before scrolling fires beforeScroll callback');
1919
equals($("#ticker li").length, 6, "list does have all items");
@@ -31,9 +31,9 @@ test("afterScroll", function() {
3131

3232
$("#ticker").ticker({
3333
initialTimeout: 0,
34-
slidingTime: 0,
34+
scrollTime: 0,
3535
fadeTime: 10000,
36-
next: function(lastItem) { return '<li>TestItem</li>'; },
36+
nextItem: function(lastItem) { return $('<li>TestItem</li>'); },
3737
afterScroll: function(event, ui) {
3838
ok(true, 'after scrolling fires afterScroll callback');
3939
equals($("#ticker li").length, 6, "list does have all items");
@@ -52,9 +52,9 @@ test("afterFade", function() {
5252

5353
$("#ticker").ticker({
5454
initialTimeout: 0,
55-
slidingTime: 0,
55+
scrollTime: 0,
5656
fadeTime: 100,
57-
next: function(lastItem) { return '<li>TestItem</li>'; },
57+
nextItem: function(lastItem) { return $('<li>TestItem</li>'); },
5858
afterFade: function(event, ui) {
5959
ok(true, 'after fade fires afterFade callback');
6060
equals($("#ticker li").length, 6, "list does have all items");
@@ -67,4 +67,40 @@ test("afterFade", function() {
6767
window.setTimeout(function() { start(); }, 200);
6868
});
6969

70+
test("correct order of nextItem call and events", function() {
71+
expect(4);
72+
stop();
73+
74+
var counter = 0;
75+
76+
$("#ticker").ticker({
77+
initialTimeout: 0,
78+
scrollTime: 50,
79+
fadeTime: 50,
80+
nextItem: function(lastItem) {
81+
if (counter == 0) {
82+
ok(true, "nextItem was called first")
83+
}
84+
return $('<li>TestItem</li>');
85+
},
86+
beforeScroll: function(event, ui) {
87+
if (counter == 0) {
88+
ok(true, "beforeScroll was called second")
89+
}
90+
},
91+
afterScroll: function(event, ui) {
92+
if (counter == 0) {
93+
ok(true, "afterScroll was called third")
94+
}
95+
},
96+
afterFade: function(event, ui) {
97+
if (counter == 0) {
98+
ok(true, "afterFade was called fourth")
99+
}
100+
}
101+
});
102+
103+
window.setTimeout(function() { start(); }, 200);
104+
});
105+
70106
})(jQuery);

tests/unit/ticker/ticker_methods.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test("initial stop", function() {
3939

4040
$("#ticker").ticker({
4141
initialTimeout: 100,
42-
next: function(lastItem) {
42+
nextItem: function(lastItem) {
4343
ok(false, "ticker should not scroll after it was stopped");
4444
return lastItem;
4545
}
@@ -59,9 +59,9 @@ test("stop after scroll", function() {
5959
initialTimeout: 0,
6060
mouseOnTimeout: 100,
6161
mouseOffTimeout: 100,
62-
slidingTime: 0,
62+
scrollTime: 0,
6363
fadeTime: 0,
64-
next: function(lastItem) {
64+
nextItem: function(lastItem) {
6565
if (counter == 0) {
6666
ok(true, "ticker scrolled one time");
6767
$("#ticker").ticker("stop");
@@ -88,9 +88,9 @@ test("start", function() {
8888
initialTimeout: 100,
8989
mouseOnTimeout: 100,
9090
mouseOffTimeout: 100,
91-
slidingTime: 0,
91+
scrollTime: 0,
9292
fadeTime: 0,
93-
next: function(lastItem) {
93+
nextItem: function(lastItem) {
9494
if (started) {
9595
ok(true, "ticker scrolled after it was started");
9696
$("#ticker").ticker("stop");
@@ -99,7 +99,7 @@ test("start", function() {
9999
});
100100
$("#ticker").ticker("stop");
101101
window.setTimeout(function() { started = true; $("#ticker").ticker("start"); }, 200);
102-
window.setTimeout(function() { start(); }, 300);
102+
window.setTimeout(function() { start(); }, 500);
103103
});
104104

105105
})(jQuery);

tests/unit/ticker/ticker_options.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test("{initalTimout: 200}", function() {
1111
var nextCalled = false;
1212
$("#ticker").ticker({
1313
initialTimeout: 200,
14-
next: function(lastItem) {
14+
nextItem: function(lastItem) {
1515
nextCalled = true;
1616
return lastItem;
1717
}
@@ -37,7 +37,7 @@ test("{initialTimeout: 200} after calling start method", function() {
3737
var nextCalled = false;
3838
$("#ticker").ticker({
3939
initialTimeout: 200,
40-
next: function(lastItem) {
40+
nextItem: function(lastItem) {
4141
nextCalled = true;
4242
return lastItem;
4343
}
@@ -71,7 +71,7 @@ test("{mouseOffTimeout: 100}", function() {
7171
initialTimeout: 0,
7272
mouseOnTimeout: 10000,
7373
mouseOffTimeout: 100,
74-
next: function(lastItem) {
74+
nextItem: function(lastItem) {
7575
ok(true, "Next called (one time after init and one time afterwards");
7676
if (counter == 1) {
7777
$("#ticker").ticker("stop");
@@ -96,7 +96,7 @@ test("{mouseOnTimeout: 100}", function() {
9696
initialTimeout: 0,
9797
mouseOnTimeout: 100,
9898
mouseOffTimeout: 10000,
99-
next: function(lastItem) {
99+
nextItem: function(lastItem) {
100100
ok(true, "Next called (one time after init and one time afterwards");
101101
if (counter == 1) {
102102
$("#ticker").ticker("stop");
@@ -110,19 +110,19 @@ test("{mouseOnTimeout: 100}", function() {
110110
window.setTimeout(function() { start(); }, 200 );
111111
});
112112

113-
test('{next: function() {return "TestItem"}}', function() {
113+
test('{nextItem: function() {return $("TestItem")}}', function() {
114114
expect(2);
115115
stop();
116116

117117
var nextCalled = false;
118118

119119
$("#ticker").ticker({
120120
initialTimeout: 0,
121-
slidingTime: 0,
121+
scrollTime: 0,
122122
fadeTime: 0,
123123
mouseOffTimeout: 10000,
124-
next: function(lastItem) {
125-
return "<li>TestItem</li>";
124+
nextItem: function(lastItem) {
125+
return $("<li>TestItem</li>");
126126
}
127127
});
128128

tests/visual/all.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
$("#sortable").sortable();
5252
$("#tabs").tabs();
5353
$("#ticker").ticker({
54-
next: function(lastItem) { return lastItem; }
54+
nextItem: function(lastItem) { return lastItem; }
5555
});
5656
});
5757
</script>

tests/visual/ticker/ticker.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$(function() {
1414
var i = 0;
1515
$("#ticker").ticker({
16-
next: function(lastItem) { return lastItem; }
16+
nextItem: function(lastItem) { return lastItem; }
1717
});
1818
})
1919
</script>

ui/jquery.ui.ticker.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ $.widget( "ui.ticker", {
2121
initialTimeout: 4000,
2222
mouseOnTimeout: 8000,
2323
mouseOffTimeout: 4000,
24-
slidingTime: 800,
24+
scrollTime: 800,
2525
fadeTime: 1000,
26-
next: null
26+
nextItem: null
2727
},
2828

2929
_create: function() {
@@ -121,24 +121,24 @@ $.widget( "ui.ticker", {
121121
newItem,
122122
lastItem;
123123

124-
if (false === self._trigger('beforeScroll')) {
125-
return;
126-
}
127-
128124
lastItem = self.element.children().last().clone();
129125
lastItem.removeClass(itemClasses + " ui-state-hover ui-state-focus");
130126

131127
if (self.options.next !== null) {
132-
newItem = $( self.options.next(lastItem.get()) );
128+
newItem = self.options.nextItem(lastItem);
133129

134-
if (newItem.length > 0) {
130+
if (newItem != null && newItem.length > 0) {
131+
if (false === self._trigger('beforeScroll')) {
132+
return;
133+
}
134+
135135
newItem.addClass(itemClasses);
136136
self._addItemBindings(newItem);
137137
newItem
138138
.hide()
139139
.prependTo(self.element)
140140
.css('visibility', 'hidden')
141-
.slideDown(options.slidingTime, function() {
141+
.slideDown(options.scrollTime, function() {
142142
$( this )
143143
.fadeTo(0, 0)
144144
.css('visibility', 'visible')
@@ -147,7 +147,7 @@ $.widget( "ui.ticker", {
147147
});
148148
});
149149

150-
self.element.children().last().slideUp(options.slidingTime, function() {
150+
self.element.children().last().slideUp(options.scrollTime, function() {
151151
$( this ).remove();
152152
self._trigger('afterScroll');
153153
});

0 commit comments

Comments
 (0)