Skip to content

Commit

Permalink
chore: Merging our changes with changes from upstream. Fixing some li…
Browse files Browse the repository at this point in the history
…ngering issues from the merge.
  • Loading branch information
priceld committed Oct 6, 2017
1 parent 14025fb commit 40d2dd8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 58 deletions.
78 changes: 37 additions & 41 deletions src/js/core/directives/ui-grid-menu-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,51 +363,47 @@ function ($compile, gridUtil, uiGridConstants, uiGridGridMenuService, i18nServic
return {
priority: 0,
scope: true,
require: ['?^uiGrid'],
require: ['^uiGrid'],
replace: true,
compile: function ($elm, $attrs) {
return {
pre: function($scope, $elm, $attrs, controllers) {
var uiGridCtrl = controllers[0];
var menuButtonTemplate = (uiGridCtrl.grid && uiGridCtrl.grid.options.menuButtonTemplate) ? uiGridCtrl.grid.options.menuButtonTemplate : defaultTemplate;
$scope.menuTemplate = uiGridCtrl.grid.options.menuTemplate;
gridUtil.getTemplate(menuButtonTemplate)
.then(function (contents) {
var template = angular.element(contents);
$elm.replaceWith(template);
$compile(template)($scope);
});
},
post: function($scope, $elm, $attrs, controllers) {
// For the aria label
$scope.i18n = {
aria: i18nService.getSafeText('gridMenu.aria')
};
var uiGridCtrl = controllers[0];
uiGridGridMenuService.initialize($scope, uiGridCtrl.grid);
$scope.shown = false;

$scope.toggleMenu = function () {
if ( $scope.shown ){
$scope.$broadcast('hide-menu');
$scope.shown = false;
} else {
$scope.menuItems = uiGridGridMenuService.getMenuItems( $scope );
$scope.$broadcast('show-menu');
$scope.shown = true;
}
};

$scope.$on('menu-hidden', function() {
$scope.shown = false;
gridUtil.focus.bySelector($elm, '.ui-grid-icon-container');
});
}
link: function ($scope, $elm, $attrs, controllers) {
var uiGridCtrl = controllers[0];
var menuButtonTemplate = (uiGridCtrl.grid && uiGridCtrl.grid.options.menuButtonTemplate) ? uiGridCtrl.grid.options.menuButtonTemplate : defaultTemplate;
gridUtil.getTemplate(menuButtonTemplate)
.then(function (contents) {
var template = angular.element(contents);
// Insert the template into the DOM first, so that when we compile it
// the ui-grid-menu will have the required uiGrid controller.
$elm.replaceWith(template);
$compile(template)($scope);
});

// For the aria label
$scope.i18n = {
aria: i18nService.getSafeText('gridMenu.aria')
};

uiGridGridMenuService.initialize($scope, uiGridCtrl.grid);

};
$scope.shown = false;

$scope.toggleMenu = function () {
if ( $scope.shown ){
$scope.$broadcast('hide-menu');
$scope.shown = false;
} else {
$scope.menuItems = uiGridGridMenuService.getMenuItems( $scope );
$scope.$broadcast('show-menu');
$scope.shown = true;
}
};

$scope.$on('menu-hidden', function() {
$scope.shown = false;
gridUtil.focus.bySelector($elm, '.ui-grid-icon-container');
});
}
};

}]);

})();
})();
6 changes: 5 additions & 1 deletion src/js/core/directives/ui-grid-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
var grid;
if ( uiGridCtrl ) {
grid = uiGridCtrl.grid;
$scope.grid = grid;
}
$scope.dynamicStyles = '';
if (uiGridCtrl && uiGridCtrl.grid && uiGridCtrl.grid.options && uiGridCtrl.grid.options.gridMenuTemplate) {
var gridMenuTemplate = uiGridCtrl.grid.options.gridMenuTemplate;
gridUtil.getTemplate(gridMenuTemplate).then(function (contents) {
var template = angular.element(contents);
var newElm = $compile(template)($scope);
$elm.replaceWith(newElm);
// Empty then append the new element rather than replacing (.replaceWith)
// so that appending to body with an ngIf works nicely.
$elm.empty();
$elm.append(newElm);
}).catch(angular.noop);
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ angular.module('ui.grid')

//gridUtil.logDebug('viewPortHeight', viewPortHeight);

return (viewPortHeight > 0) ? viewPortHeight : 0;
return Math.max(0, viewPortHeight);
};

Grid.prototype.getViewportWidth = function getViewportWidth() {
Expand Down
16 changes: 3 additions & 13 deletions src/js/core/factories/GridOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ angular.module('ui.grid')
* total items at the bottom of the grid, and the selected items if selection is enabled.
*/
baseOptions.gridFooterTemplate = baseOptions.gridFooterTemplate || 'ui-grid/ui-grid-grid-footer';

/**
* @ngdoc string
* @name menuButtonTemplate
Expand All @@ -490,17 +490,7 @@ angular.module('ui.grid')
* of a precompiled template (TBD how to use this). Refer to the custom footer tutorial for more information.
*/
baseOptions.menuButtonTemplate = baseOptions.menuButtonTemplate || null;
/**
* @ngdoc string
* @name menuTemplate
* @propertyOf ui.grid.class:GridOptions
* @description (optional) Null by default. When provided, this setting uses a custom grid menu
* template. Can be set to either the name of a template file 'menu_template.html', inline html
* <pre>'<div class="ui-grid-menu" style="text-align: left">Custom Menu Header <ul><li ng-repeat="item in menuItems" ui-grid-menu-item></li></ul></div>'</pre>, or the id
* of a precompiled template (TBD how to use this). Refer to the custom footer tutorial for more information.
*/
baseOptions.menuTemplate = baseOptions.menuTemplate || null;


/**
* @ngdoc string
* @name menuItemTemplate
Expand All @@ -511,7 +501,7 @@ angular.module('ui.grid')
* of a precompiled template (TBD how to use this). Refer to the custom footer tutorial for more information.
*/
baseOptions.menuItemTemplate = baseOptions.menuItemTemplate || null;

/**
* @ngdoc string
* @name rowTemplate
Expand Down
2 changes: 1 addition & 1 deletion src/js/core/factories/GridRenderContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ angular.module('ui.grid')

viewPortHeight = viewPortHeight + adjustment.height;

return (viewPortHeight > 0) ? viewPortHeight : 0;
return Math.max(0, viewPortHeight);
};

GridRenderContainer.prototype.getViewportWidth = function getViewportWidth() {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/ui-grid/ui-grid-menu-button.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<i class="ui-grid-icon-menu"
ui-grid-one-bind-aria-label="i18n.aria.buttonLabel">&nbsp;</i>
</div>
<div ui-grid-menu menu-items="menuItems" template-url="menuTemplate"></div>
<div ui-grid-menu menu-items="menuItems"></div>
</div>

0 comments on commit 40d2dd8

Please sign in to comment.