Skip to content

Commit 1b52cef

Browse files
committed
Widget: Fixed _show() and _hide() implementation and added tests.
1 parent e5186dc commit 1b52cef

File tree

5 files changed

+285
-5
lines changed

5 files changed

+285
-5
lines changed

tests/unit/tooltip/tooltip_defaults.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ commonWidgetTests( "tooltip", {
22
defaults: {
33
content: function() {},
44
disabled: false,
5+
hide: true,
56
items: "[title]",
67
position: {
78
my: "left+15 center",
89
at: "right center",
910
collision: "flip fit"
1011
},
12+
show: true,
1113
tooltipClass: null,
1214

1315
// callbacks
14-
create: null
16+
close: null,
17+
create: null,
18+
open: null
1519
}
1620
});

tests/unit/widget/widget.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<script src="widget_core.js"></script>
1717
<script src="widget_extend.js"></script>
18+
<script src="widget_animation.js"></script>
1819

1920
<script src="../swarminject.js"></script>
2021
</head>

tests/unit/widget/widget_animation.js

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
2+
module( "widget animation", (function() {
3+
var show = $.fn.show,
4+
fadeIn = $.fn.fadeIn,
5+
slideDown = $.fn.slideDown;
6+
return {
7+
setup: function() {
8+
$.widget( "ui.testWidget", {
9+
_create: function() {
10+
this.element.hide();
11+
},
12+
show: function( fn ) {
13+
this._show( this.element, this.options.show, fn );
14+
}
15+
});
16+
$.effects = { effect: { testEffect: $.noop } };
17+
},
18+
teardown: function() {
19+
delete $.ui.testWidget;
20+
delete $.effects.effect.testEffect;
21+
$.fn.show = show;
22+
$.fn.fadeIn = fadeIn;
23+
$.fn.slideDown = slideDown;
24+
}
25+
};
26+
}()));
27+
28+
asyncTest( "show: null", function() {
29+
expect( 4 );
30+
31+
var element = $( "#widget" ).testWidget(),
32+
hasRun = false;
33+
$.fn.show = function() {
34+
ok( true, "show called" );
35+
equal( arguments.length, 0, "no args passed to show" );
36+
};
37+
38+
element
39+
.delay( 50 )
40+
.queue(function( next ) {
41+
ok( !hasRun, "queue before show" );
42+
next();
43+
})
44+
.testWidget( "show", function() {
45+
hasRun = true;
46+
})
47+
.queue(function( next ) {
48+
ok( hasRun, "queue after show" );
49+
start();
50+
next();
51+
});
52+
});
53+
54+
asyncTest( "show: true", function() {
55+
expect( 4 );
56+
57+
var element = $( "#widget" ).testWidget({
58+
show: true
59+
}),
60+
hasRun = false;
61+
$.fn.fadeIn = function( duration, easing, complete ) {
62+
return this.queue(function( next ) {
63+
strictEqual( duration, undefined, "duration" );
64+
strictEqual( easing, undefined, "easing" );
65+
complete();
66+
next();
67+
});
68+
};
69+
70+
element
71+
.delay( 50 )
72+
.queue(function( next ) {
73+
ok( !hasRun, "queue before show" );
74+
next();
75+
})
76+
.testWidget( "show", function() {
77+
hasRun = true;
78+
})
79+
.queue(function( next ) {
80+
ok( hasRun, "queue after show" );
81+
start();
82+
next();
83+
});
84+
});
85+
86+
asyncTest( "show: number", function() {
87+
expect( 4 );
88+
89+
var element = $( "#widget" ).testWidget({
90+
show: 123
91+
}),
92+
hasRun = false;
93+
$.fn.fadeIn = function( duration, easing, complete ) {
94+
return this.queue(function( next ) {
95+
strictEqual( duration, 123, "duration" );
96+
strictEqual( easing, undefined, "easing" );
97+
complete();
98+
next();
99+
});
100+
};
101+
102+
element
103+
.delay( 50 )
104+
.queue(function( next ) {
105+
ok( !hasRun, "queue before show" );
106+
next();
107+
})
108+
.testWidget( "show", function() {
109+
hasRun = true;
110+
})
111+
.queue(function( next ) {
112+
ok( hasRun, "queue after show" );
113+
start();
114+
next();
115+
});
116+
});
117+
118+
asyncTest( "show: core animation", function() {
119+
expect( 4 );
120+
121+
var element = $( "#widget" ).testWidget({
122+
show: "slideDown"
123+
}),
124+
hasRun = false;
125+
$.fn.slideDown = function( duration, easing, complete ) {
126+
return this.queue(function( next ) {
127+
strictEqual( duration, undefined, "duration" );
128+
strictEqual( easing, undefined, "easing" );
129+
complete();
130+
next();
131+
});
132+
};
133+
134+
element
135+
.delay( 50 )
136+
.queue(function( next ) {
137+
ok( !hasRun, "queue before show" );
138+
next();
139+
})
140+
.testWidget( "show", function() {
141+
hasRun = true;
142+
})
143+
.queue(function( next ) {
144+
ok( hasRun, "queue after show" );
145+
start();
146+
next();
147+
});
148+
});
149+
150+
asyncTest( "show: effect", function() {
151+
expect( 5 );
152+
153+
var element = $( "#widget" ).testWidget({
154+
show: "testEffect"
155+
}),
156+
hasRun = false;
157+
$.fn.show = function( options ) {
158+
return this.queue(function( next ) {
159+
equal( options.effect, "testEffect", "effect" );
160+
ok( !("duration" in options), "duration" );
161+
ok( !("easing" in options), "easing" );
162+
options.complete();
163+
next();
164+
});
165+
};
166+
167+
element
168+
.delay( 50 )
169+
.queue(function( next ) {
170+
ok( !hasRun, "queue before show" );
171+
next();
172+
})
173+
.testWidget( "show", function() {
174+
hasRun = true;
175+
})
176+
.queue(function( next ) {
177+
ok( hasRun, "queue after show" );
178+
start();
179+
next();
180+
});
181+
});
182+
183+
asyncTest( "show: object(core animation)", function() {
184+
expect( 4 );
185+
186+
var element = $( "#widget" ).testWidget({
187+
show: {
188+
effect: "slideDown",
189+
duration: 123,
190+
easing: "testEasing"
191+
}
192+
}),
193+
hasRun = false;
194+
$.fn.slideDown = function( duration, easing, complete ) {
195+
return this.queue(function( next ) {
196+
equal( duration, 123, "duration" );
197+
equal( easing, "testEasing", "easing" );
198+
complete();
199+
next();
200+
});
201+
};
202+
203+
element
204+
.delay( 50 )
205+
.queue(function( next ) {
206+
ok( !hasRun, "queue before show" );
207+
next();
208+
})
209+
.testWidget( "show", function() {
210+
hasRun = true;
211+
})
212+
.queue(function( next ) {
213+
ok( hasRun, "queue after show" );
214+
start();
215+
next();
216+
});
217+
});
218+
219+
asyncTest( "show: object(effect)", function() {
220+
expect( 3 );
221+
222+
var element = $( "#widget" ).testWidget({
223+
show: {
224+
effect: "testEffect",
225+
duration: 123,
226+
easing: "testEasing"
227+
}
228+
}),
229+
hasRun = false;
230+
$.fn.show = function( options ) {
231+
return this.queue(function( next ) {
232+
deepEqual( options, {
233+
effect: "testEffect",
234+
duration: 123,
235+
easing: "testEasing",
236+
complete: options.complete
237+
});
238+
options.complete();
239+
next();
240+
});
241+
};
242+
243+
element
244+
.delay( 50 )
245+
.queue(function( next ) {
246+
ok( !hasRun, "queue before show" );
247+
next();
248+
})
249+
.testWidget( "show", function() {
250+
hasRun = true;
251+
})
252+
.queue(function( next ) {
253+
ok( hasRun, "queue after show" );
254+
start();
255+
next();
256+
});
257+
});

ui/jquery.ui.tooltip.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,19 @@ $.widget( "ui.tooltip", {
2222
content: function() {
2323
return $( this ).attr( "title" );
2424
},
25+
hide: true,
2526
items: "[title]",
2627
position: {
2728
my: "left+15 center",
2829
at: "right center",
2930
collision: "flip fit"
3031
},
31-
tooltipClass: null
32+
show: true,
33+
tooltipClass: null,
34+
35+
// callbacks
36+
close: null,
37+
open: null
3238
},
3339

3440
_create: function() {

ui/jquery.ui.widget.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,20 @@ $.Widget.prototype = {
375375

376376
$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
377377
$.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
378+
if ( typeof options === "string" ) {
379+
options = { effect: options };
380+
}
381+
var hasOptions,
382+
effectName = !options ?
383+
method :
384+
options === true || typeof options === "number" ?
385+
defaultEffect :
386+
options.effect || defaultEffect;
378387
options = options || {};
379-
var hasOptions = !$.isEmptyObject( options ),
380-
effectName = options.effect || defaultEffect;
388+
if ( typeof options === "number" ) {
389+
options = { duration: options };
390+
}
391+
hasOptions = !$.isEmptyObject( options );
381392
options.complete = callback;
382393
if ( options.delay ) {
383394
element.delay( options.delay );
@@ -387,11 +398,12 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
387398
} else if ( effectName !== method && element[ effectName ] ) {
388399
element[ effectName ]( options.duration, options.easing, callback );
389400
} else {
390-
element.queue( function() {
401+
element.queue(function( next ) {
391402
$( this )[ method ]();
392403
if ( callback ) {
393404
callback.call( element[ 0 ] );
394405
}
406+
next();
395407
});
396408
}
397409
};

0 commit comments

Comments
 (0)