Skip to content

Commit

Permalink
fixing menu and submenu width calculation - Issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Dec 5, 2012
1 parent fa4e281 commit 32c949d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ $.contextMenu is published under the [MIT license](http://www.opensource.org/lic

* adding [DOM Element bound context menus](http://medialize.github.com/jQuery-contextMenu/demo/on-dom-element.html) - ([Issue 88](https://github.com/medialize/jQuery-contextMenu/issues/88))
* fixing key "watch" might translate to Object.prototype.watch in callbacks map - ([Issue 93](https://github.com/medialize/jQuery-contextMenu/issues/93))
* fixing menu and submenu width calculation - ([Issue 18](https://github.com/medialize/jQuery-contextMenu/issues/18))

### 1.5.25 ###

Expand Down
41 changes: 33 additions & 8 deletions src/jquery.contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,18 +1065,43 @@ var // currently active contextMenu trigger
}
opt.$menu.appendTo(opt.appendTo || document.body);
},
resize: function($menu, nested) {
// determine widths of submenus, as CSS won't grow them automatically
// position:absolute within position:absolute; min-width:100; max-width:200; results in width: 100;
// kinda sucks hard...

// determine width of absolutely positioned element
$menu.css({position: 'absolute', display: 'block'});
// don't apply yet, because that would break nested elements' widths
$menu.data('width', $menu.width());
// reset styles so they allow nested elements to grow/shrink naturally
$menu.css({
position: 'static',
minWidth: '0px',
maxWidth: '100000px'
});
// identify width of nested menus
$menu.find('> li > ul').each(function() {
op.resize($(this), true);
});
// reset and apply changes in the end because nested
// elements' widths wouldn't be calculatable otherwise
if (!nested) {
$menu.find('ul').andSelf().css({
position: '',
display: '',
minWidth: '',
maxWidth: ''
}).width(function() {
return $(this).data('width');
});
}
},
update: function(opt, root) {
var $this = this;
if (root === undefined) {
root = opt;
// determine widths of submenus, as CSS won't grow them automatically
// position:absolute > position:absolute; min-width:100; max-width:200; results in width: 100;
// kinda sucks hard...
opt.$menu.find('ul').andSelf().css({position: 'static', display: 'block'}).each(function(){
var $this = $(this);
$this.width($this.css('position', 'absolute').width())
.css('position', 'static');
}).css({position: '', display: ''});
op.resize(opt.$menu);
}
// re-check disabled for each item
opt.$menu.children().each(function(){
Expand Down

0 comments on commit 32c949d

Please # to comment.