Skip to content

Commit 1d16799

Browse files
SteveTheTechiemlh758
authored andcommitted
Update animation support (#768)
Update animation support Aligns animation options with current .show() & .hide() signatures.
1 parent f63bc70 commit 1d16799

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

demos/animations.htm

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,29 @@
1414
<script type="text/javascript">
1515
$(function(){
1616

17-
$("#test-1").multiselect({
18-
show: ["bounce", 200],
19-
hide: ["explode", 1000]
20-
});
21-
22-
$("#test-2").multiselect({
23-
show: "bounce",
24-
hide: "explode"
25-
});
17+
$("#test-1").multiselect({
18+
openEffect: ["bounce", 200],
19+
closeEffect: ["explode", 1000]
20+
});
21+
22+
$("#test-2").multiselect({
23+
openEffect: "bounce",
24+
closeEffect: "explode"
25+
});
2626

2727
});
2828
</script>
2929
</head>
3030
<body onload="prettyPrint();">
3131

3232
<h2>Show/hide with Animation</h2>
33-
<p>Using animations with the show and hide parameters. Either pass an array with the effect name and the speed, or just specify the name of an effect. If you don't
34-
specify a speed, the default of 400ms will be used.</p>
33+
<p>Using animations with the openEffect and closeEffect parameters. Either pass an array with the effect name and the speed, an object of animation parameters, or just specify the name of an effect. If you don't specify a speed, the default of 400ms will be used.</p>
3534

3635
<h3>Specifying different show and hide speeds</h3>
3736
<pre class="prettyprint">
3837
$("#test-1").multiselect({
39-
show: ["bounce", 200],
40-
hide: ["explode", 1000]
38+
openEffect: ["bounce", 200],
39+
closeEffect: ["explode", 1000]
4140
});
4241
</pre>
4342
<select id="test-1" multiple="multiple" size="5">
@@ -51,8 +50,8 @@ <h3>Specifying different show and hide speeds</h3>
5150
<h3>Only passing the name of an effect</h3>
5251
<pre class="prettyprint">
5352
$("#test-2").multiselect({
54-
show: "bounce",
55-
hide: "explode"
53+
openEffect: "bounce",
54+
closeEffect: "explode"
5655
});
5756
</pre>
5857
<select id="test-2" multiple="multiple" size="5">

src/jquery.multiselect.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,25 +1371,25 @@
13711371
var $header = this.$header;
13721372
var $labels = this.$labels;
13731373
var $inputs = this.$inputs.filter(':checked:not(.ui-state-disabled)');
1374-
var speed = this.speed;
13751374
var options = this.options;
13761375
var effect = options.openEffect;
13771376
var scrollX = window.scrollX;
13781377
var scrollY = window.scrollY;
13791378

1380-
// figure out opening effects/speeds
1381-
if (effect && effect.constructor == Array) {
1382-
speed = effect[1] || speed;
1383-
effect = effect[0];
1384-
}
1385-
13861379
// set the scroll of the checkbox container
13871380
this.$checkboxes.scrollTop(0);
13881381

13891382
// show the menu, maybe with a speed/effect combo
1390-
// if there's an effect, assume jQuery UI is in use
1391-
if (effect) {
1392-
$.fn.show.apply($menu, effect ? [ effect, speed ] : []);
1383+
if (!!effect) {
1384+
if (typeof effect == 'string') {
1385+
$.fn.show.call($menu, effect, this.speed);
1386+
}
1387+
else if (typeof effect == 'object' && effect.constructor == Array) {
1388+
$.fn.show.call($menu, effect[0], effect[1] || this.speed);
1389+
}
1390+
else if (typeof effect == 'object' && effect.constructor == Object) {
1391+
$.fn.show.call($menu, effect);
1392+
}
13931393
}
13941394
else {
13951395
$menu.css('display','block');
@@ -1424,31 +1424,30 @@
14241424

14251425
// Close the menu
14261426
close: function() {
1427-
var self = this;
1428-
14291427
// bail if the multiselect close event returns false
14301428
if (this._trigger('beforeclose') === false || !!this.options.listbox) {
14311429
return;
14321430
}
14331431

1432+
var $menu = this.$menu;
14341433
var options = this.options;
14351434
var effect = options.closeEffect;
1436-
var speed = this.speed;
14371435
var $button = this.$button;
14381436

1439-
// figure out closing effects/speeds
1440-
if (effect && effect.constructor == Array) {
1441-
speed = effect[1] || speed;
1442-
effect = effect[0];
1443-
}
1444-
14451437
// hide the menu, maybe with a speed/effect combo
1446-
// if there's an effect, assume jQuery UI is in use
1447-
if (effect) {
1448-
$.fn.hide.apply(this.$menu, effect ? [ effect, speed ] : []);
1438+
if (!!effect) {
1439+
if (typeof effect == 'string') {
1440+
$.fn.hide.call($menu, effect, this.speed);
1441+
}
1442+
else if (typeof effect == 'object' && effect.constructor == Array) {
1443+
$.fn.hide.call($menu, effect[0], effect[1] || this.speed);
1444+
}
1445+
else if (typeof effect == 'object' && effect.constructor == Object) {
1446+
$.fn.hide.call($menu, effect);
1447+
}
14491448
}
14501449
else {
1451-
this.$menu.css('display','none');
1450+
$menu.css('display','none');
14521451
}
14531452

14541453
$button.removeClass('ui-state-active').trigger('blur').trigger('mouseleave');

0 commit comments

Comments
 (0)