110 lines
6.2 KiB
JavaScript
110 lines
6.2 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('headerNavigationModule')
|
|
.directive('headerNavigation', ['events', '$window', '$timeout', '$modal', function (events, $window, $timeout, $modal) {
|
|
return {
|
|
restrict: 'E',
|
|
templateUrl: 'views/navigation/header-navigation.html',
|
|
replace: true,
|
|
controller: 'HeaderNavigationController',
|
|
link: function (scope) {
|
|
var navWidthsArray = [], navContainer = angular.element('.navigation-bar__items-container'), wrapperElementWidth, initNavElementsWidth = 0, resizePromise;
|
|
scope.toggleSearchBar = function () {
|
|
scope.showSearchBar = true;
|
|
if (scope.showSearchBar) {
|
|
angular.element(document.body).on('keydown click', closeSearchBar);
|
|
}
|
|
};
|
|
scope.openSurvey = function () {
|
|
return $modal.open({
|
|
templateUrl: 'views/common/feedback.html',
|
|
controller: 'feedbackController',
|
|
windowClass: 'action-blade',
|
|
backdrop: 'custom'
|
|
});
|
|
};
|
|
function closeSearchBar(evt) {
|
|
var $targetEl = $(evt.target);
|
|
var closeSearch = (evt.type === 'click' && !($targetEl.hasClass('header-search__bar') || $targetEl.parents().hasClass('search-criteria-box') || $targetEl.attr('id') === 'header-search_button'))
|
|
|| evt.keyCode === 27
|
|
|| (evt.keyCode === 13 && $targetEl.hasClass('search__close'));
|
|
if (closeSearch) {
|
|
scope.showSearchBar = false;
|
|
scope.$apply();
|
|
angular.element(document.body).off('keydown', closeSearchBar);
|
|
angular.element(document.body).off('click', closeSearchBar);
|
|
}
|
|
}
|
|
function measureNavBar() {
|
|
navWidthsArray.length = 0;
|
|
_.forEach(navContainer.children(), function (child) {
|
|
navWidthsArray.push(child.clientWidth);
|
|
});
|
|
wrapperElementWidth = navWidthsArray.pop();
|
|
initNavElementsWidth = 0;
|
|
_.forEach(navWidthsArray, function (itemWidth) { initNavElementsWidth += itemWidth; });
|
|
scope.navBarMeasured = true;
|
|
}
|
|
function recomposeNavBar() {
|
|
var wrapIndex = 1000, navContainerWidth, navElementsWidth = initNavElementsWidth;
|
|
navContainerWidth = navContainer[0].clientWidth;
|
|
if (navElementsWidth > navContainerWidth) {
|
|
wrapIndex = navWidthsArray.length - 1;
|
|
navElementsWidth = navElementsWidth - _.last(navWidthsArray) + wrapperElementWidth;
|
|
for (wrapIndex; wrapIndex > 0; wrapIndex--) {
|
|
if (navElementsWidth < navContainerWidth) {
|
|
break;
|
|
}
|
|
else {
|
|
navElementsWidth -= navWidthsArray[wrapIndex - 1];
|
|
}
|
|
}
|
|
}
|
|
scope.wrapIndex = wrapIndex;
|
|
}
|
|
scope.navBarMeasured = false;
|
|
scope.expandNavItem = function ($event, navItem) {
|
|
$event.preventDefault();
|
|
$event.stopPropagation();
|
|
if (navItem.expanded) {
|
|
navItem.expanded = false;
|
|
return;
|
|
}
|
|
_.forEach(scope.navigationItems, function (item) {
|
|
item.expanded = false;
|
|
});
|
|
navItem.expanded = true;
|
|
};
|
|
scope.setFocusToMyProfile = function () {
|
|
angular.element('[ux-id="user-menu-dropdown"]').focus();
|
|
};
|
|
scope.$on(events.LAST_REPEATER_ELEMENT, function () {
|
|
!scope.navBarMeasured && measureNavBar();
|
|
recomposeNavBar();
|
|
});
|
|
function resizeHandler() {
|
|
$timeout.cancel(resizePromise);
|
|
resizePromise = $timeout(function () {
|
|
recomposeNavBar();
|
|
}, 1000);
|
|
}
|
|
angular.element($window).on('resize', resizeHandler);
|
|
scope.$on('$destroy', function () {
|
|
angular.element(document.body).off('keydown', closeSearchBar);
|
|
angular.element(document.body).off('click', closeSearchBar);
|
|
angular.element($window).off('resize', resizeHandler);
|
|
});
|
|
}
|
|
};
|
|
}])
|
|
.controller('feedbackController', ['$scope', '$modalInstance', '$rootScope', '$sce', 'i18nService', function ($scope, $modalInstance, $rootScope, $sce, i18nService) {
|
|
var surveyURL = 'https://bmc.co1.qualtrics.com/jfe/form/SV_bkYhsabqPlJ4KKp', //'https://bmc.co1.qualtrics.com/jfe/form/SV_007Z3psfA6kaShv',
|
|
keys = $rootScope.licenseKeys && $rootScope.licenseKeys.length ? $rootScope.licenseKeys.join() : 'None', surveyLocalizationLangs = ['EN', 'ES', 'FR', 'ZH', 'IT', 'KO', 'DE', 'RU', 'JA', 'HE', 'PT', 'PL'], qlang = surveyLocalizationLangs.indexOf(i18nService.language.toUpperCase()) >= 0 ? i18nService.language.toUpperCase() : 'EN';
|
|
$scope.surveyURL = $sce.trustAsResourceUrl(surveyURL + '?Q_Language=' + qlang + '&product=Smart IT&productVersion=221&licenseKey=' + keys);
|
|
$scope.close = function () {
|
|
$modalInstance.close();
|
|
};
|
|
}]);
|
|
}());
|