Merge pull request #1781 from mabashian/944-limit-panels

Tweaked limit-panels so that it doesn't use $transitions
This commit is contained in:
Michael Abashian 2018-05-14 16:07:01 -04:00 committed by GitHub
commit eb8140284a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
export default ['$rootScope', '$transitions', function($rootScope, $transitions) {
export default [function() {
return {
restrict: 'E',
scope: {
@ -7,27 +7,28 @@ export default ['$rootScope', '$transitions', function($rootScope, $transitions)
},
link: function(scope) {
scope.maxPanels = parseInt(scope.maxPanels);
const maxPanels = parseInt(scope.maxPanels);
$transitions.onSuccess({}, function() {
let panels = angular.element('#' + scope.panelContainer).find('.Panel');
if(panels.length > scope.maxPanels) {
// hide the excess panels
$(panels).each(function( index ) {
if(index+1 > scope.maxPanels) {
$(this).addClass('Panel-hidden');
}
else {
$(this).removeClass('Panel-hidden');
}
});
scope.$watch(
() => angular.element('#' + scope.panelContainer).find('.Panel').length,
() => {
const panels = angular.element('#' + scope.panelContainer).find('.Panel');
if(panels.length > maxPanels) {
// hide the excess panels
$(panels).each(function( index ) {
if(index+1 > maxPanels) {
$(this).addClass('Panel-hidden');
}
else {
$(this).removeClass('Panel-hidden');
}
});
} else {
// show all the panels
$(panels).removeClass('Panel-hidden');
}
}
else {
// show all the panels
$(panels).removeClass('Panel-hidden');
}
});
);
}
};
}];