harbor/static/resources/js/layout/navigation/navigation-header.directive.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
angular
.module('harbor.layout.navigation')
.directive('navigationHeader', navigationHeader);
NavigationHeaderController.$inject = ['$window', '$scope', 'currentUser', '$timeout'];
function NavigationHeaderController($window, $scope, currentUser, $timeout) {
var vm = this;
vm.url = $window.location.pathname;
}
function navigationHeader() {
var directive = {
restrict: 'E',
templateUrl: '/navigation_header?timestamp=' + new Date().getTime(),
link: link,
scope: true,
controller: NavigationHeaderController,
controllerAs: 'vm',
bindToController: true
2016-05-23 12:29:17 +02:00
};
return directive;
2016-05-13 12:48:06 +02:00
function link(scope, element, attrs, ctrl) {
var visited = ctrl.url;
console.log('visited:' + visited);
if (visited !== '' && visited !== '/') {
2016-05-13 12:48:06 +02:00
element.find('a[href*="' + visited + '"]').addClass('active');
}
element.find('a').on('click', click);
function click(event) {
element.find('a').removeClass('active');
$(event.target).not('span').addClass('active');
2016-05-13 12:48:06 +02:00
}
}
}
})();