@@ -1065,18 +1065,43 @@ var // currently active contextMenu trigger
1065
1065
}
1066
1066
opt . $menu . appendTo ( opt . appendTo || document . body ) ;
1067
1067
} ,
1068
+ resize : function ( $menu , nested ) {
1069
+ // determine widths of submenus, as CSS won't grow them automatically
1070
+ // position:absolute within position:absolute; min-width:100; max-width:200; results in width: 100;
1071
+ // kinda sucks hard...
1072
+
1073
+ // determine width of absolutely positioned element
1074
+ $menu . css ( { position : 'absolute' , display : 'block' } ) ;
1075
+ // don't apply yet, because that would break nested elements' widths
1076
+ $menu . data ( 'width' , $menu . width ( ) ) ;
1077
+ // reset styles so they allow nested elements to grow/shrink naturally
1078
+ $menu . css ( {
1079
+ position : 'static' ,
1080
+ minWidth : '0px' ,
1081
+ maxWidth : '100000px'
1082
+ } ) ;
1083
+ // identify width of nested menus
1084
+ $menu . find ( '> li > ul' ) . each ( function ( ) {
1085
+ op . resize ( $ ( this ) , true ) ;
1086
+ } ) ;
1087
+ // reset and apply changes in the end because nested
1088
+ // elements' widths wouldn't be calculatable otherwise
1089
+ if ( ! nested ) {
1090
+ $menu . find ( 'ul' ) . andSelf ( ) . css ( {
1091
+ position : '' ,
1092
+ display : '' ,
1093
+ minWidth : '' ,
1094
+ maxWidth : ''
1095
+ } ) . width ( function ( ) {
1096
+ return $ ( this ) . data ( 'width' ) ;
1097
+ } ) ;
1098
+ }
1099
+ } ,
1068
1100
update : function ( opt , root ) {
1069
1101
var $this = this ;
1070
1102
if ( root === undefined ) {
1071
1103
root = opt ;
1072
- // determine widths of submenus, as CSS won't grow them automatically
1073
- // position:absolute > position:absolute; min-width:100; max-width:200; results in width: 100;
1074
- // kinda sucks hard...
1075
- opt . $menu . find ( 'ul' ) . andSelf ( ) . css ( { position : 'static' , display : 'block' } ) . each ( function ( ) {
1076
- var $this = $ ( this ) ;
1077
- $this . width ( $this . css ( 'position' , 'absolute' ) . width ( ) )
1078
- . css ( 'position' , 'static' ) ;
1079
- } ) . css ( { position : '' , display : '' } ) ;
1104
+ op . resize ( opt . $menu ) ;
1080
1105
}
1081
1106
// re-check disabled for each item
1082
1107
opt . $menu . children ( ) . each ( function ( ) {
0 commit comments