Skip to content

Commit

Permalink
set height of the sidebar dynamic
Browse files Browse the repository at this point in the history
* height of sidebar is set dynamic through dynamicElementHeightComponent Directive
* styled out layout dynamicly through ng-class="{'sidebar-active': sidebarEnabled == 'true'}"
  • Loading branch information
JanQuery committed Apr 11, 2018
1 parent 7fa7cab commit 0d8ecca
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/app.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ angular.module('MainApp', [
'appRoutes',
'config',
'mainDirective',
'uxDirectives',
'mainFilter',
'navController',
'navService',
Expand Down
50 changes: 50 additions & 0 deletions app/shared/directives/uxDirectives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
angular.module('uxDirectives', ['config'])

.directive('dynamicElementHeightComponent', [ '$rootScope', function( $rootScope ) {
return {
restrict: 'EA',
scope: {},
link: function(scope, element, attributes) {
angular.element(document).ready( function () {

function changeSidebarHeigthDynamicly() {
element.height(Math.max($("body").height(), $("aside").height()));
}

function ifBigScreenAdaptedSidebarHeightElseSetToAuto () {
if ( window.innerWidth > 800 ) {
changeSidebarHeigthDynamicly();
}
else {
element.css('height','auto');
}
}

// on init
setTimeout( function () {
ifBigScreenAdaptedSidebarHeightElseSetToAuto();
}, 200 );

// if window become resized reset height of sidebar
var lastWidth = $(window).width();

$(window).resize(function() {
if ( window.innerWidth != lastWidth) {
lastWidth = window.innerWidth;
setTimeout( function () {
ifBigScreenAdaptedSidebarHeightElseSetToAuto();
}, 200 );
}
})


$rootScope.$on('$locationChangeStart', function (event, next, current) {
setTimeout( function () {
ifBigScreenAdaptedSidebarHeightElseSetToAuto();
}, 300 );
});

})
}
}
}])
2 changes: 1 addition & 1 deletion app/templates/content.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<main class="container">
<main ng-class="{'sidebar-active': sidebarEnabled == 'true'}">
<div ng-view></div>
</main>
2 changes: 1 addition & 1 deletion app/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
<div ng-include="sidebarTemplate"></div>
</div>

<div ng-if="carouselEnabled == 'true'">
<div ng-if="carouselEnabled == 'true'" ng-class="{'sidebar-active': sidebarEnabled == 'true'}">
<div ng-include="carouselTemplate"></div>
</div>
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

<!-- directives -->
<script src="app/shared/directives/mainDirective.js"></script>
<script src="app/shared/directives/uxDirectives.js"></script>

<!-- filters -->
<script src="app/shared/filters/mainFilter.js"></script>
Expand Down Expand Up @@ -96,7 +97,7 @@

</head>

<body ng-controller="MainController">
<body ng-controller="MainController" class="container-fluid">

<div ng-include="layout.header"></div>

Expand Down

0 comments on commit 0d8ecca

Please sign in to comment.