Skip to content

Commit 7856b26

Browse files
committed
Menubar: Trigger select event after running all other methods. Allows the select-handler to destroy the widget without errors.
1 parent 06676f4 commit 7856b26

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

demos/menubar/default.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
<script src="../../ui/jquery.ui.menubar.js"></script>
1414
<script>
1515
$(function() {
16+
function select(event, ui) {
17+
$("<div/>").text("Selected: " + ui.item.text()).appendTo("#log");
18+
if (ui.item.text() == 'Quit') {
19+
$(this).menubar('destroy');
20+
}
21+
}
1622
$("#bar1").menubar({
1723
position: {
1824
within: $("#demo-frame").add(window).first()
1925
},
20-
select: function(event, ui) {
21-
$("<div/>").text("Selected: " + ui.item.text()).appendTo("#log");
22-
}
26+
select: select
2327
});
2428

2529
$(".menubar-icons").menubar({
@@ -29,9 +33,7 @@
2933
position: {
3034
within: $("#demo-frame").add(window).first()
3135
},
32-
select: function(event, ui) {
33-
$("<div/>").text("Selected: " + ui.item.text()).appendTo("#log");
34-
}
36+
select: select
3537
});
3638
});
3739
</script>

ui/jquery.ui.menubar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ $.widget( "ui.menubar", {
4949
},
5050
select: function( event, ui ) {
5151
ui.item.parents( "ul.ui-menu:last" ).hide();
52-
that._trigger( "select", event, ui );
5352
that._close();
5453
// TODO what is this targetting? there's probably a better way to access it
5554
$(event.target).prev().focus();
55+
that._trigger( "select", event, ui );
5656
}
5757
})
5858
.hide()
@@ -94,7 +94,7 @@ $.widget( "ui.menubar", {
9494
if( that.options.autoExpand ) {
9595
clearTimeout( that.timer );
9696
}
97-
97+
9898
that._open( event, menu );
9999
}
100100
})
@@ -120,7 +120,7 @@ $.widget( "ui.menubar", {
120120
.attr( "role", "menuitem" )
121121
.attr( "aria-haspopup", "true" )
122122
.wrapInner( "<span class='ui-button-text'></span>" );
123-
123+
124124
if ( that.options.autoExpand ) {
125125
input.bind( "mouseleave.menubar", function( event ) {
126126
that.timer = setTimeout( function() {

0 commit comments

Comments
 (0)