Skip to content

Commit

Permalink
Menu: Introducing position option into flyout menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaefferer committed Feb 23, 2011
1 parent faa4b97 commit ddfd5e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 13 additions & 3 deletions tests/visual/menu/flyoutmenu.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
// TODO required to prevent the click handler below from handling this event // TODO required to prevent the click handler below from handling this event
event.stopPropagation(); event.stopPropagation();
menu.flyoutmenu("show") menu.flyoutmenu("show")
//.attr("tabIndex", 0)
.focus() .focus()
.css({ .css({
top: 0, top: 0,
Expand All @@ -45,17 +44,28 @@
}); });


menu.flyoutmenu({ menu.flyoutmenu({
//input: button, /* top-alignment
position: function(item) {
return {
my: "left top",
at: "right top",
of: item.parent()
}
},
*/
select: function(event, ui) { select: function(event, ui) {
$("#log").append("<div>Selected " + ui.item.children("a").text() + "</div>"); $("#log").append("<div>Selected " + ui.item.children("a").text() + "</div>");
button.focus(); button.focus();
} }
}).hide(); }).hide();

// equal height
//menu.find("ul").height(menu.height());
}); });
</script> </script>
<style> <style>
body { font-size:62.5%; } body { font-size:62.5%; }
.ui-menu { width: 200px; position: absolute; } .ui-menu { width: 200px; position: absolute; outline: none; }
.ui-menu .ui-icon { float: right; } .ui-menu .ui-icon { float: right; }
</style> </style>
</head> </head>
Expand Down
22 changes: 17 additions & 5 deletions tests/visual/menu/flyoutmenu.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
(function($) { (function($) {


$.widget("ui.flyoutmenu", { $.widget("ui.flyoutmenu", {

options: {
position: {
my: "left top",
at: "right top"
}
},

_create: function() { _create: function() {
var self = this; var self = this;
this.active = this.element; this.active = this.element;
Expand Down Expand Up @@ -90,14 +98,18 @@ $.widget("ui.flyoutmenu", {
// TODO restrict to widget // TODO restrict to widget
//only one menu can have items open at a time. //only one menu can have items open at a time.
$(document).find(".ui-menu-flyout").not(submenu.parents()).hide(); $(document).find(".ui-menu-flyout").not(submenu.parents()).hide();

var position = $.extend({}, {
of: this.activeItem
}, $.type(this.options.position) == "function"
? this.options.position(this.activeItem)
: this.options.position
);

submenu.show().css({ submenu.show().css({
top: 0, top: 0,
left: 0 left: 0
}).position({ }).position(position);
my: "left top",
at: "right top",
of: this.activeItem
});
}, },
_select: function(event) { _select: function(event) {
event.stopPropagation(); event.stopPropagation();
Expand Down

0 comments on commit ddfd5e6

Please sign in to comment.