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

50 lines
1.1 KiB
JavaScript
Raw Normal View History

(function() {
'use strict';
angular
.module('harbor.app')
.directive('navigationTab', navigationTab);
function navigationTab() {
var directive = {
2016-04-14 19:50:10 +02:00
restrict: 'E',
templateUrl: getTemplateUrl,
link: link,
controller: controller
}
return directive;
2016-04-14 19:50:10 +02:00
function getTemplateUrl(element, attrs) {
return '/static/ng/resources/js/components/'+ attrs.templateUrl;
}
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).addClass('active');
}
2016-04-14 19:50:10 +02:00
}
controller.$inject = ['$window'];
function controller($window) {
var vm = this;
vm.location = $window.location.pathname;
}
}
})();