1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-07-21 14:46:41 +02:00

moved popup utils to utilsService

This commit is contained in:
Kyle Spearrin 2016-09-26 18:41:20 -04:00
parent 107c480913
commit a59f7a4afc
12 changed files with 64 additions and 64 deletions

View File

@ -1,10 +1,10 @@
angular angular
.module('bit.accounts') .module('bit.accounts')
.controller('accountsHintController', function ($scope, $state, apiService, toastr, $q) { .controller('accountsHintController', function ($scope, $state, apiService, toastr, $q, utilsService) {
$scope.model = {}; $scope.model = {};
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$('#email').focus(); $('#email').focus();
$scope.submitPromise = null; $scope.submitPromise = null;

View File

@ -1,8 +1,9 @@
angular angular
.module('bit.accounts') .module('bit.accounts')
.controller('accountsLoginController', function ($scope, $state, $stateParams, loginService, userService, toastr) { .controller('accountsLoginController', function ($scope, $state, $stateParams, loginService, userService, toastr,
popupUtils.initListSectionItemListeners(); utilsService) {
utilsService.initListSectionItemListeners($(document));
if ($stateParams.email) { if ($stateParams.email) {
$('#master-password').focus(); $('#master-password').focus();

View File

@ -1,9 +1,9 @@
angular angular
.module('bit.accounts') .module('bit.accounts')
.controller('accountsLoginTwoFactorController', function ($scope, $state, loginService, toastr) { .controller('accountsLoginTwoFactorController', function ($scope, $state, loginService, toastr, utilsService) {
$scope.model = {}; $scope.model = {};
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$('#code').focus(); $('#code').focus();
$scope.loginPromise = null; $scope.loginPromise = null;

View File

@ -1,9 +1,9 @@
angular angular
.module('bit.accounts') .module('bit.accounts')
.controller('accountsRegisterController', function ($scope, $state, cryptoService, toastr, $q, apiService) { .controller('accountsRegisterController', function ($scope, $state, cryptoService, toastr, $q, apiService, utilsService) {
$scope.model = {}; $scope.model = {};
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$('#email').focus(); $('#email').focus();
$scope.submitPromise = null; $scope.submitPromise = null;

View File

@ -1,9 +1,9 @@
angular angular
.module('bit.settings') .module('bit.settings')
.controller('settingsAddFolderController', function ($scope, $q, folderService, $state, toastr) { .controller('settingsAddFolderController', function ($scope, $q, folderService, $state, toastr, utilsService) {
$scope.folder = {}; $scope.folder = {};
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$('#name').focus(); $('#name').focus();
$scope.savePromise = null; $scope.savePromise = null;

View File

@ -1,7 +1,8 @@
angular angular
.module('bit.settings') .module('bit.settings')
.controller('settingsEditFolderController', function ($scope, $stateParams, folderService, toastr, $q, $state, SweetAlert) { .controller('settingsEditFolderController', function ($scope, $stateParams, folderService, toastr, $q, $state, SweetAlert,
utilsService) {
$scope.folder = {}; $scope.folder = {};
var folderId = $stateParams.folderId; var folderId = $stateParams.folderId;
@ -11,7 +12,7 @@
}); });
}); });
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$scope.savePromise = null; $scope.savePromise = null;
$scope.save = function (model) { $scope.save = function (model) {

View File

@ -2,13 +2,13 @@
.module('bit.tools') .module('bit.tools')
.controller('toolsPasswordGeneratorController', function ($scope, $state, $stateParams, passwordGenerationService, .controller('toolsPasswordGeneratorController', function ($scope, $state, $stateParams, passwordGenerationService,
toastr, $q) { toastr, $q, utilsService) {
var addState = $stateParams.addState, var addState = $stateParams.addState,
editState = $stateParams.editState; editState = $stateParams.editState;
$scope.showSelect = $stateParams.addState || $stateParams.editState; $scope.showSelect = $stateParams.addState || $stateParams.editState;
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$scope.password = '-'; $scope.password = '-';
$scope.slider = { $scope.slider = {

View File

@ -2,7 +2,7 @@
.module('bit.vault') .module('bit.vault')
.controller('vaultAddSiteController', function ($scope, $state, $stateParams, siteService, folderService, .controller('vaultAddSiteController', function ($scope, $state, $stateParams, siteService, folderService,
cryptoService, $q, toastr) { cryptoService, $q, toastr, utilsService) {
var returnScrollY = $stateParams.returnScrollY; var returnScrollY = $stateParams.returnScrollY;
var returnSearchText = $stateParams.returnSearchText; var returnSearchText = $stateParams.returnSearchText;
var fromCurrent = $stateParams.fromCurrent || $stateParams.uri !== null; var fromCurrent = $stateParams.fromCurrent || $stateParams.uri !== null;
@ -23,7 +23,7 @@
else { else {
$('#name').focus(); $('#name').focus();
} }
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$q.when(folderService.getAllDecrypted()).then(function (folders) { $q.when(folderService.getAllDecrypted()).then(function (folders) {
$scope.folders = folders; $scope.folders = folders;

View File

@ -2,7 +2,7 @@ angular
.module('bit.vault') .module('bit.vault')
.controller('vaultEditSiteController', function ($scope, $state, $stateParams, siteService, folderService, .controller('vaultEditSiteController', function ($scope, $state, $stateParams, siteService, folderService,
cryptoService, $q, toastr, SweetAlert) { cryptoService, $q, toastr, SweetAlert, utilsService) {
var returnScrollY = $stateParams.returnScrollY; var returnScrollY = $stateParams.returnScrollY;
var returnSearchText = $stateParams.returnSearchText; var returnSearchText = $stateParams.returnSearchText;
var siteId = $stateParams.siteId; var siteId = $stateParams.siteId;
@ -27,7 +27,7 @@ angular
$scope.folders = folders; $scope.folders = folders;
}); });
popupUtils.initListSectionItemListeners(); utilsService.initListSectionItemListeners($(document));
$scope.savePromise = null; $scope.savePromise = null;
$scope.save = function (model) { $scope.save = function (model) {

View File

@ -13,8 +13,6 @@
<script src="../lib/jquery/jquery.js"></script> <script src="../lib/jquery/jquery.js"></script>
<script src="../lib/bootstrap/js/bootstrap.js"></script> <script src="../lib/bootstrap/js/bootstrap.js"></script>
<script src="scripts/popup.js"></script>
<script src="../lib/clipboard/clipboard.js"></script> <script src="../lib/clipboard/clipboard.js"></script>
<script src="../lib/angular/angular.js"></script> <script src="../lib/angular/angular.js"></script>

View File

@ -1,44 +0,0 @@
var popupUtils = function () {
var self = this;
self.initListSectionItemListeners = function () {
$('.list-section-item').click(function (e) {
var text = $(this).find('input, textarea').not('input[type="checkbox"], input[type="radio"], input[type="hidden"]');
var checkbox = $(this).find('input[type="checkbox"]');
var select = $(this).find('select');
if (text.length > 0 && e.target === text[0]) {
return;
}
if (checkbox.length > 0 && e.target === checkbox[0]) {
return;
}
if (select.length > 0 && e.target === select[0]) {
return;
}
e.preventDefault();
if (text.length > 0) {
text.focus();
}
else if (checkbox.length > 0) {
checkbox.prop('checked', !checkbox.is(':checked'));
if (angular) {
angular.element(checkbox[0]).triggerHandler('click');
}
}
else if (select.length > 0) {
select.focus();
}
});
$('.list-section-item input, .list-section-item select, .list-section-item textarea').focus(function (e) {
$(this).parent().addClass('active');
}).blur(function (e) {
$(this).parent().removeClass('active');
});
}
return self;
}();

View File

@ -41,4 +41,48 @@ function initUtilsService() {
UtilsService.prototype.isOpera = function () { UtilsService.prototype.isOpera = function () {
return this.getBrowser() === 'opera'; return this.getBrowser() === 'opera';
} }
UtilsService.prototype.initListSectionItemListeners = function (doc) {
if (!doc) {
throw 'doc parameter required';
}
doc.on('click', '.list-section-item', function (e) {
var text = $(this).find('input, textarea').not('input[type="checkbox"], input[type="radio"], input[type="hidden"]');
var checkbox = $(this).find('input[type="checkbox"]');
var select = $(this).find('select');
if (text.length > 0 && e.target === text[0]) {
return;
}
if (checkbox.length > 0 && e.target === checkbox[0]) {
return;
}
if (select.length > 0 && e.target === select[0]) {
return;
}
e.preventDefault();
if (text.length > 0) {
text.focus();
}
else if (checkbox.length > 0) {
checkbox.prop('checked', !checkbox.is(':checked'));
if (angular) {
angular.element(checkbox[0]).triggerHandler('click');
}
}
else if (select.length > 0) {
select.focus();
}
});
doc.on('focus', '.list-section-item input, .list-section-item select, .list-section-item textarea', function (e) {
$(this).parent().addClass('active');
});
doc.on('blur', '.list-section-item input, .list-section-item select, .list-section-item textarea', function (e) {
$(this).parent().removeClass('active');
});
}
}; };