1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/global/mainController.js

138 lines
4.5 KiB
JavaScript
Raw Normal View History

2015-12-09 04:35:05 +01:00
angular
.module('bit.global')
2017-04-15 05:30:58 +02:00
.controller('mainController', function ($scope, $state, authService, appSettings, toastr, $window, $document) {
2015-12-09 04:35:05 +01:00
var vm = this;
vm.bodyClass = '';
vm.searchVaultText = null;
vm.version = appSettings.version;
$scope.currentYear = new Date().getFullYear();
$scope.$on('$viewContentLoaded', function () {
authService.getUserProfile().then(function (profile) {
vm.userProfile = profile;
});
2017-03-07 06:36:27 +01:00
2015-12-09 04:35:05 +01:00
if ($.AdminLTE) {
if ($.AdminLTE.layout) {
$.AdminLTE.layout.fix();
$.AdminLTE.layout.fixSidebar();
}
if ($.AdminLTE.pushMenu) {
$.AdminLTE.pushMenu.expandOnHover();
}
2017-02-23 06:45:54 +01:00
$(document).off('click', '.sidebar li a');
2015-12-09 04:35:05 +01:00
}
});
$scope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
vm.searchVaultText = null;
if (toState.data.bodyClass) {
vm.bodyClass = toState.data.bodyClass;
return;
}
else {
vm.bodyClass = '';
}
});
$scope.searchVault = function () {
$state.go('backend.user.vault');
2015-12-09 04:35:05 +01:00
};
2017-01-03 04:26:32 +01:00
$scope.addLogin = function () {
$scope.$broadcast('vaultAddLogin');
2015-12-09 04:35:05 +01:00
};
$scope.addFolder = function () {
$scope.$broadcast('vaultAddFolder');
};
2017-04-15 04:49:51 +02:00
2017-04-18 16:19:42 +02:00
// Append dropdown menu somewhere else
2017-04-15 05:30:58 +02:00
var bodyScrollbarWidth,
2017-04-18 16:19:42 +02:00
appendedDropdownMenu,
appendedDropdownMenuParent;
2017-04-15 04:49:51 +02:00
var dropdownHelpers = {
scrollbarWidth: function () {
if (!bodyScrollbarWidth) {
var bodyElem = $('body');
bodyElem.addClass('bit-position-body-scrollbar-measure');
2017-04-15 05:30:58 +02:00
bodyScrollbarWidth = $window.innerWidth - bodyElem[0].clientWidth;
2017-04-15 04:49:51 +02:00
bodyScrollbarWidth = isFinite(bodyScrollbarWidth) ? bodyScrollbarWidth : 0;
bodyElem.removeClass('bit-position-body-scrollbar-measure');
}
return bodyScrollbarWidth;
},
2017-04-15 05:30:58 +02:00
scrollbarInfo: function () {
2017-04-15 04:49:51 +02:00
return {
2017-04-15 05:30:58 +02:00
width: dropdownHelpers.scrollbarWidth(),
visible: $document.height() > $($window).height()
2017-04-15 04:49:51 +02:00
};
}
};
2017-04-15 05:30:58 +02:00
$(window).on('show.bs.dropdown', function (e) {
2017-04-18 16:19:42 +02:00
var target = appendedDropdownMenuParent = $(e.target);
var appendTo = target.data('appendTo');
if (!appendTo) {
2017-04-15 05:30:58 +02:00
return true;
}
2017-04-18 16:19:42 +02:00
appendedDropdownMenu = target.find('.dropdown-menu');
var appendToEl = $(appendTo);
appendToEl.append(appendedDropdownMenu.detach());
2017-04-15 04:49:51 +02:00
2017-04-18 16:19:42 +02:00
var offset = target.offset();
2017-04-15 04:49:51 +02:00
var css = {
display: 'block',
2017-04-18 16:19:42 +02:00
top: offset.top + target.outerHeight()
2017-04-15 04:49:51 +02:00
};
2017-04-18 16:19:42 +02:00
if (appendedDropdownMenu.hasClass('dropdown-menu-right')) {
2017-04-15 05:30:58 +02:00
var scrollbarInfo = dropdownHelpers.scrollbarInfo();
2017-04-15 04:49:51 +02:00
var scrollbarWidth = 0;
2017-04-15 05:30:58 +02:00
if (scrollbarInfo.visible && scrollbarInfo.width) {
scrollbarWidth = scrollbarInfo.width;
2017-04-15 04:49:51 +02:00
}
2017-04-18 16:19:42 +02:00
css.right = $window.innerWidth - scrollbarWidth - (offset.left + target.prop('offsetWidth')) + 'px';
2017-04-15 04:49:51 +02:00
css.left = 'auto';
}
else {
2017-04-18 16:19:42 +02:00
css.left = offset.left + 'px';
2017-04-15 04:49:51 +02:00
css.right = 'auto';
}
2017-04-18 16:19:42 +02:00
appendedDropdownMenu.css(css);
2017-04-15 04:49:51 +02:00
});
2017-04-15 05:30:58 +02:00
$(window).on('hide.bs.dropdown', function (e) {
2017-04-18 16:19:42 +02:00
if (!appendedDropdownMenu) {
2017-04-15 07:00:25 +02:00
return true;
}
2017-04-18 16:19:42 +02:00
$(e.target).append(appendedDropdownMenu.detach());
appendedDropdownMenu.hide();
appendedDropdownMenu = null;
appendedDropdownMenuParent = null;
2017-04-15 07:00:25 +02:00
});
2017-04-18 16:19:42 +02:00
$scope.$on('removeAppendedDropdownMenu', function (event, args) {
if (!appendedDropdownMenu && !appendedDropdownMenuParent) {
2017-04-15 05:30:58 +02:00
return true;
}
2017-04-18 16:19:42 +02:00
appendedDropdownMenuParent.append(appendedDropdownMenu.detach());
appendedDropdownMenu.hide();
appendedDropdownMenu = null;
appendedDropdownMenuParent = null;
2017-04-15 04:49:51 +02:00
});
2015-12-09 04:35:05 +01:00
});