Skip to content

Commit

Permalink
fix(sidebar): validate size of box name if sidebar is minimized
Browse files Browse the repository at this point in the history
  • Loading branch information
mpfeil committed Dec 7, 2017
1 parent 9012f7a commit aee118d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
6 changes: 4 additions & 2 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ angular
})
.state('explore.map.sidebar', {
url: 'explore',
resolve: {
Sidebar: function () {
resolve: { /* @ngInject */
Sidebar: function ($rootScope, $window) {
var vm = this;
vm.title = '';
vm.translationId = '';
vm.actions = [];

return {
getTitle: function () {
return vm.title;
},
setTitle: function (title) {
vm.title = title;
$rootScope.$broadcast('sidebar:titleChanged', {});
},
setTranslationId: function (id) {
vm.translationId = id;
Expand Down
26 changes: 24 additions & 2 deletions app/scripts/controllers/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
.module('openSenseMapApp')
.controller('SidebarController', SidebarController);

SidebarController.$inject = ['Sidebar'];
SidebarController.$inject = ['$scope', '$timeout', '$window', 'Sidebar'];

function SidebarController (Sidebar) {
function SidebarController ($scope, $timeout, $window, Sidebar) {
var vm = this;
vm.minimized = false;
vm.Sidebar = Sidebar;
vm.top = 100;
vm.height = 50;

vm.minimize = minimize;

Expand All @@ -24,6 +26,26 @@
function minimize () {
vm.minimized = !vm.minimized;
Sidebar.minimized = vm.minimized;
invalidateSize();
}

function invalidateSize () {
var elem = $window.document.querySelector('#sidebar-title');
var elemHeight = angular.element(elem)[0].clientHeight;

if (elemHeight > 50) {
vm.height = elemHeight + 5;
} else {
vm.height = 50;
}
}

////

$scope.$on('sidebar:titleChanged', function () {
$timeout(function () {
invalidateSize();
});
});
}
})();
4 changes: 0 additions & 4 deletions app/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,11 @@ a:hover {
}

.maximized {
height: calc(100% - 100px);
top: 100px;
overflow: auto;
}

.minimized {
top: calc(100% - 50px);
overflow: hidden;
height: 50px;
}

#sidebar .row {
Expand Down
10 changes: 7 additions & 3 deletions app/views/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<div id="sidebar" style="background-position: 0px -5px;" ng-class="{'maximized': !sidebar.minimized, 'minimized': sidebar.minimized}" ng-cloak>
<div class="row">
<div id="sidebar"
style="background-position: 0px -5px;"
ng-style="{'top': {true: 'calc(100% - '+sidebar.height+'px)',false:sidebar.top + 'px'}[sidebar.minimized] , 'height': {true: 'calc(100% - '+sidebar.top+'px)',false:sidebar.height + 'px'}[!sidebar.minimized]}"
ng-class="{'maximized': !sidebar.minimized, 'minimized': sidebar.minimized}"
ng-cloak>
<div class="row" id="sidebar-title">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="col-xs-8 col-sm-8 col-md-8" style="padding-left: 0px;" ng-click="sidebar.minimize()">
<h4>{{sidebar.Sidebar.getTranslationId() | translate}}{{sidebar.Sidebar.getTitle()}}</h4>
<h4 class="sidebar-title-text">{{sidebar.Sidebar.getTranslationId() | translate}}{{sidebar.Sidebar.getTitle()}}</h4>
</div>
<div class="col-xs-4 col-sm-4 col-md-4" style="padding-right: 0px;">
<h5>
Expand Down

0 comments on commit aee118d

Please sign in to comment.