harbor/static/ng/resources/js/layout/navigation-tab.directive.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
angular
.module('harbor.app')
.directive('navigationTab', navigationTab);
NavigationTabController.$inject = ['$window'];
function NavigationTabController($window) {
var vm = this;
vm.location = $window.location.pathname;
vm.closePane = closePane;
function closePane() {
vm.visible = false;
}
}
function navigationTab() {
var directive = {
2016-04-14 19:50:10 +02:00
restrict: 'E',
templateUrl: getTemplateUrl,
link: link,
scope: {
templateUrl: "@",
visible: "="
},
replace: true,
controller: NavigationTabController,
controllerAs: 'vm',
bindToController: true
}
return directive;
2016-04-14 19:50:10 +02:00
function getTemplateUrl(element, attrs) {
return '/static/ng/resources/js/layout/'+ attrs.templateUrl;
2016-04-14 19:50:10 +02:00
}
function link(scope, element, attrs, ctrl) {
if (attrs.templateUrl.indexOf("navigation-tab") >= 0) {
element.find('a[href$="' + ctrl.location + '"]').addClass('active');
}
if (attrs.templateUrl.indexOf("navigation-details") >= 0) {
element.find('a:first').addClass('active');
}
2016-04-14 19:50:10 +02:00
element.on('click', click);
function click(event) {
element.find('a').removeClass('active');
$(event.target).not('span').addClass('active');
}
2016-04-14 19:50:10 +02:00
}
}
})();