@@ -285,16 +285,20 @@ function ( i18nService, uiGridConstants, gridUtil ) {
285
285
// default value the last width for _this_ column, otherwise last width for _any_ column, otherwise default to 170
286
286
var myWidth = column . lastMenuWidth ? column . lastMenuWidth : ( $scope . lastMenuWidth ? $scope . lastMenuWidth : 170 ) ;
287
287
var paddingRight = column . lastMenuPaddingRight ? column . lastMenuPaddingRight : ( $scope . lastMenuPaddingRight ? $scope . lastMenuPaddingRight : 10 ) ;
288
- if ( menu . length !== 0 ) {
289
- myWidth = gridUtil . elementWidth ( menu , true ) ;
290
- $scope . lastMenuWidth = myWidth ;
291
- column . lastMenuWidth = myWidth ;
292
-
293
- // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side
294
- // Get the column menu right padding
295
- paddingRight = parseInt ( gridUtil . getStyles ( angular . element ( menu ) [ 0 ] ) [ 'paddingRight' ] , 10 ) ;
296
- $scope . lastMenuPaddingRight = paddingRight ;
297
- column . lastMenuPaddingRight = paddingRight ;
288
+
289
+ if ( menu . length !== 0 ) {
290
+ var mid = menu [ 0 ] . querySelectorAll ( '.ui-grid-menu-mid' ) ;
291
+ if ( mid . length !== 0 && ! mid [ 0 ] . classList . contains ( 'ng-hide' ) ) {
292
+ myWidth = gridUtil . elementWidth ( menu , true ) ;
293
+ $scope . lastMenuWidth = myWidth ;
294
+ column . lastMenuWidth = myWidth ;
295
+
296
+ // TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side
297
+ // Get the column menu right padding
298
+ paddingRight = parseInt ( gridUtil . getStyles ( angular . element ( menu ) [ 0 ] ) [ 'paddingRight' ] , 10 ) ;
299
+ $scope . lastMenuPaddingRight = paddingRight ;
300
+ column . lastMenuPaddingRight = paddingRight ;
301
+ }
298
302
}
299
303
300
304
var left = positionData . left + renderContainerOffset - containerScrollLeft + positionData . width - myWidth + paddingRight ;
@@ -355,37 +359,37 @@ function ($log, $timeout, gridUtil, uiGridConstants, uiGridColumnMenuService) {
355
359
// Swap to this column
356
360
$scope . col = column ;
357
361
358
- // Remove an existing document click handler
359
- // $document.off('click', documentClick);
360
-
361
362
// Get the position information for the column element
362
363
var colElementPosition = uiGridColumnMenuService . getColumnElementPosition ( $scope , column , $columnElement ) ;
363
364
364
- var repositionMenuClosure = function ( $scope , column , colElementPosition , $elm , $columnElement ) {
365
- return function ( ) {
366
- uiGridColumnMenuService . repositionMenu ( $scope , column , colElementPosition , $elm , $columnElement ) ;
367
- } ;
368
- } ;
369
-
370
365
if ( $scope . menuShown ) {
371
- $scope . $broadcast ( 'hide-menu' ) ;
366
+ // we want to hide, then reposition, then show, but we want to wait for animations
367
+ // we set a variable, and then rely on the menu-hidden event to call the reposition and show
372
368
$scope . col = column ;
373
-
374
- uiGridColumnMenuService . repositionMenu ( $scope , column , colElementPosition , $elm , $columnElement ) ;
375
- $scope . $broadcast ( 'show-menu' ) ;
376
- $timeout ( repositionMenuClosure ( $scope , column , colElementPosition , $elm , $columnElement ) ) ;
369
+ $scope . colElement = $columnElement ;
370
+ $scope . colElementPosition = colElementPosition ;
371
+ $scope . hideThenShow = true ;
372
+
373
+ $scope . $broadcast ( 'hide-menu' ) ;
377
374
} else {
378
375
self . shown = $scope . menuShown = true ;
379
376
uiGridColumnMenuService . repositionMenu ( $scope , column , colElementPosition , $elm , $columnElement ) ;
380
377
$scope . $broadcast ( 'show-menu' ) ;
381
- $timeout ( repositionMenuClosure ( $scope , column , colElementPosition , $elm , $columnElement ) ) ;
382
- }
378
+ $timeout ( $scope . repositionMenuClosure ( $scope , column , colElementPosition , $elm , $columnElement ) ) ;
379
+ }
383
380
384
- // Hide the menu on a click on the document
385
- // $document.on('click', documentClick);
386
381
} ;
387
382
388
383
384
+ $scope . repositionMenuClosure = function ( $scope , column , colElementPosition , $elm , $columnElement ) {
385
+ return function ( ) {
386
+ uiGridColumnMenuService . repositionMenu ( $scope , column , colElementPosition , $elm , $columnElement ) ;
387
+ delete $scope . colElementPosition ;
388
+ delete $scope . columnElement ;
389
+ } ;
390
+ } ;
391
+
392
+
389
393
/**
390
394
* @ngdoc method
391
395
* @methodOf ui.grid.directive:uiGridColumnMenu
@@ -404,32 +408,19 @@ function ($log, $timeout, gridUtil, uiGridConstants, uiGridColumnMenuService) {
404
408
}
405
409
} ;
406
410
407
- /*
408
- function documentClick() {
409
- $scope.$apply($scope.hideMenu);
410
- $document.off('click', documentClick);
411
- }
412
411
413
- function resizeHandler() {
414
- $scope.$apply($scope.hideMenu);
415
- }
416
- angular.element($window).bind('resize', resizeHandler);
417
-
418
- $scope.$on('$destroy', $scope.$on(uiGridConstants.events.GRID_SCROLL, function(evt, args) {
419
- $scope.hideMenu();
420
- }));
412
+ $scope . $on ( 'menu-hidden' , function ( ) {
413
+ if ( $scope . hideThenShow ) {
414
+ delete $scope . hideThenShow ;
421
415
422
- $scope.$on('$destroy' , $scope.$on(uiGridConstants.events.ITEM_DRAGGING, function(evt, args) {
423
- $scope.hideMenu( );
424
- } ));
416
+ uiGridColumnMenuService . repositionMenu ( $scope , $scope . col , $scope . colElementPosition , $elm , $scope . colElement ) ;
417
+ $scope . $broadcast ( 'show-menu' ) ;
418
+ $timeout ( $scope . repositionMenuClosure ( $scope , $scope . col , $scope . colElementPosition , $elm , $scope . colElement ) ) ;
425
419
426
- $scope.$on('$destroy', function() {
427
- angular.element($window).off('resize', resizeHandler);
428
- $document.off('click', documentClick);
429
- });
430
- */
431
- $scope . $on ( 'menu-hidden' , function ( ) {
432
- $scope . hideMenu ( true ) ;
420
+ $scope . menuShown = true ;
421
+ } else {
422
+ $scope . hideMenu ( true ) ;
423
+ }
433
424
} ) ;
434
425
435
426
0 commit comments