Skip to content

Commit

Permalink
Fix angular-ui#2141(header): no click handler if no sort or column menu
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulL1 authored and Jyoti Puri committed Dec 2, 2014
1 parent 7c4a221 commit 8b0bec4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 47 deletions.
70 changes: 40 additions & 30 deletions src/js/core/directives/ui-grid-header-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,21 @@
$scope.sortable = false;
}

// Figure out whether this column is filterable or not
if (uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering) {
$scope.filterable = true;
}
else {
$scope.filterable = false;
}

// figure out whether we support column menus
if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false &&
$scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false){
$scope.colMenu = true;
} else {
$scope.colMenu = false;
}

function handleClick(evt) {
// If the shift key is being held down, add this column to the sort
Expand Down Expand Up @@ -127,38 +136,39 @@
*
*/

// Long-click (for mobile)
var cancelMousedownTimeout;
var mousedownStartTime = 0;
$contentsElm.on('mousedown touchstart', function(event) {
if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) {
event = event.originalEvent;
}

// Don't show the menu if it's not the left button
if (event.button && event.button !== 0) {
return;
}

mousedownStartTime = (new Date()).getTime();

cancelMousedownTimeout = $timeout(function() { }, mousedownTimeout);

cancelMousedownTimeout.then(function () {
if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false &&
$scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false) {
uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event);
if ( $scope.sortable || $scope.colMenu ){
// Long-click (for mobile)
var cancelMousedownTimeout;
var mousedownStartTime = 0;
$contentsElm.on('mousedown touchstart', function(event) {
if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) {
event = event.originalEvent;
}

// Don't show the menu if it's not the left button
if (event.button && event.button !== 0) {
return;
}

mousedownStartTime = (new Date()).getTime();

cancelMousedownTimeout = $timeout(function() { }, mousedownTimeout);

cancelMousedownTimeout.then(function () {
if ( $scope.colMenu ) {
uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event);
}
});
});
});

$contentsElm.on('mouseup touchend', function () {
$timeout.cancel(cancelMousedownTimeout);
});

$scope.$on('$destroy', function () {
$contentsElm.off('mousedown touchstart');
});

$contentsElm.on('mouseup touchend', function () {
$timeout.cancel(cancelMousedownTimeout);
});

$scope.$on('$destroy', function () {
$contentsElm.off('mousedown touchstart');
});
}


$scope.toggleMenu = function($event) {
Expand Down
32 changes: 15 additions & 17 deletions test/unit/core/directives/ui-grid-header-cell.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ describe('uiGridHeaderCell', function () {
}));
});

describe('when window is resized', function () {
it('should hide an open menu', function () {
openMenu();
expect(menu.find('.ui-grid-menu-inner').length).toEqual(1, 'column menu is visible');

$(window).trigger('resize');
$scope.$digest();

$timeout.flush();
$scope.$digest();

expect(menu.find('.ui-grid-menu-inner').length).toEqual(0, 'column menu is not visible');
});
});

describe('with enableColumnMenu off', function() {
it('should not be present', function () {
$scope.gridOpts.enableColumnMenus = false;
Expand All @@ -133,23 +148,6 @@ describe('uiGridHeaderCell', function () {
expect(headers.length).toEqual(2);
});
});

describe('when window is resized', function () {
it('should hide an open menu', function () {
delete $scope.gridOpts.columnDefs[0].enableColumnMenu;
openMenu();
expect(menu.find('.ui-grid-menu-inner').length).toEqual(1, 'column menu is visible');

$(window).trigger('resize');
$scope.$digest();

$timeout.flush();
$scope.$digest();

expect(menu.find('.ui-grid-menu-inner').length).toEqual(0, 'column menu is not visible');
});
});

// TODO(c0bra): Allow extra items to be added to a column menu through columnDefs
});

Expand Down

0 comments on commit 8b0bec4

Please sign in to comment.