mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
convert initListSectionItemListeners to js
Removed jQuery from background
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
window.$ = window.jQuery = require('jquery');
|
|
||||||
window.forge = require('node-forge');
|
window.forge = require('node-forge');
|
||||||
window.tldjs = require('tldjs');
|
window.tldjs = require('tldjs');
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ angular
|
|||||||
.module('bit.accounts')
|
.module('bit.accounts')
|
||||||
|
|
||||||
.controller('accountsHintController', function ($scope, $state, apiService, toastr, $q, utilsService,
|
.controller('accountsHintController', function ($scope, $state, apiService, toastr, $q, utilsService,
|
||||||
$analytics, i18nService) {
|
$analytics, i18nService, $timeout) {
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
document.getElementById('email').focus();
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
$scope.model = {};
|
$scope.model = {};
|
||||||
|
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
|
||||||
$('#email').focus();
|
|
||||||
|
|
||||||
$scope.submitPromise = null;
|
$scope.submitPromise = null;
|
||||||
$scope.submit = function (model) {
|
$scope.submit = function (model) {
|
||||||
if (!model.email) {
|
if (!model.email) {
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
angular
|
angular
|
||||||
.module('bit.accounts')
|
.module('bit.accounts')
|
||||||
|
|
||||||
.controller('accountsLoginController', function ($scope, $state, $stateParams, authService, userService, toastr,
|
.controller('accountsLoginController', function ($scope, $state, $stateParams, authService, userService, toastr,
|
||||||
utilsService, $analytics, i18nService) {
|
utilsService, $analytics, i18nService, $timeout) {
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
$timeout(function () {
|
||||||
$scope.i18n = i18nService;
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
|
||||||
if ($stateParams.email) {
|
if ($stateParams.email) {
|
||||||
$('#master-password').focus();
|
document.getElementById('master-password').focus();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('#email').focus();
|
document.getElementById('email').focus();
|
||||||
}
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
$scope.i18n = i18nService;
|
||||||
$scope.model = {
|
$scope.model = {
|
||||||
email: $stateParams.email
|
email: $stateParams.email
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ angular
|
|||||||
.controller('accountsLoginTwoFactorController', function ($scope, $state, authService, toastr, utilsService, SweetAlert,
|
.controller('accountsLoginTwoFactorController', function ($scope, $state, authService, toastr, utilsService, SweetAlert,
|
||||||
$analytics, i18nService, $stateParams, $filter, constantsService, $timeout, $window, cryptoService, apiService,
|
$analytics, i18nService, $stateParams, $filter, constantsService, $timeout, $window, cryptoService, apiService,
|
||||||
environmentService) {
|
environmentService) {
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
|
||||||
|
|
||||||
var customWebVaultUrl = null;
|
var customWebVaultUrl = null;
|
||||||
if (environmentService.baseUrl) {
|
if (environmentService.baseUrl) {
|
||||||
|
|||||||
@@ -3,13 +3,14 @@ angular
|
|||||||
|
|
||||||
.controller(
|
.controller(
|
||||||
'accountsRegisterController',
|
'accountsRegisterController',
|
||||||
function ($scope, $state, cryptoService, toastr, $q, apiService, utilsService, $analytics, i18nService) {
|
function ($scope, $state, cryptoService, toastr, $q, apiService, utilsService, $analytics, i18nService, $timeout) {
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
document.getElementById('email').focus();
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
|
|
||||||
$scope.model = {};
|
$scope.model = {};
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
|
||||||
$('#email').focus();
|
|
||||||
|
|
||||||
$scope.submitPromise = null;
|
$scope.submitPromise = null;
|
||||||
$scope.submit = function (model) {
|
$scope.submit = function (model) {
|
||||||
if (!model.email) {
|
if (!model.email) {
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ angular
|
|||||||
.module('bit.settings')
|
.module('bit.settings')
|
||||||
|
|
||||||
.controller('settingsAddFolderController', function ($scope, $q, folderService, $state, toastr, utilsService,
|
.controller('settingsAddFolderController', function ($scope, $q, folderService, $state, toastr, utilsService,
|
||||||
$analytics, i18nService) {
|
$analytics, i18nService, $timeout) {
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
document.getElementById('name').focus();
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
$scope.folder = {};
|
$scope.folder = {};
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
|
||||||
$('#name').focus();
|
|
||||||
|
|
||||||
$scope.savePromise = null;
|
$scope.savePromise = null;
|
||||||
$scope.save = function (model) {
|
$scope.save = function (model) {
|
||||||
if (!model.name) {
|
if (!model.name) {
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ angular
|
|||||||
.module('bit.settings')
|
.module('bit.settings')
|
||||||
|
|
||||||
.controller('settingsController', function ($scope, $state, SweetAlert, utilsService, $analytics,
|
.controller('settingsController', function ($scope, $state, SweetAlert, utilsService, $analytics,
|
||||||
i18nService, constantsService, cryptoService, lockService) {
|
i18nService, constantsService, cryptoService, lockService, $timeout) {
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.showOnLocked = !utilsService.isFirefox() && !utilsService.isEdge();
|
$scope.showOnLocked = !utilsService.isFirefox() && !utilsService.isEdge();
|
||||||
$scope.lockOption = '';
|
$scope.lockOption = '';
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
angular
|
angular
|
||||||
.module('bit.settings')
|
.module('bit.settings')
|
||||||
|
|
||||||
.controller('settingsEditFolderController', function ($scope, $stateParams, folderService, toastr, $state, SweetAlert,
|
.controller('settingsEditFolderController', function ($scope, $stateParams, folderService, toastr, $state, SweetAlert,
|
||||||
utilsService, $analytics, i18nService) {
|
utilsService, $analytics, i18nService, $timeout) {
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
document.getElementById('name').focus();
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
$scope.folder = {};
|
$scope.folder = {};
|
||||||
var folderId = $stateParams.folderId;
|
var folderId = $stateParams.folderId;
|
||||||
$('#name').focus();
|
|
||||||
|
|
||||||
folderService.get(folderId).then(function (folder) {
|
folderService.get(folderId).then(function (folder) {
|
||||||
return folder.decrypt();
|
return folder.decrypt();
|
||||||
@@ -14,8 +18,6 @@
|
|||||||
$scope.folder = model;
|
$scope.folder = model;
|
||||||
});
|
});
|
||||||
|
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
|
||||||
|
|
||||||
$scope.savePromise = null;
|
$scope.savePromise = null;
|
||||||
$scope.save = function (model) {
|
$scope.save = function (model) {
|
||||||
if (!model.name) {
|
if (!model.name) {
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ angular
|
|||||||
|
|
||||||
.controller('settingsEnvironmentController', function ($scope, i18nService, $analytics, utilsService,
|
.controller('settingsEnvironmentController', function ($scope, i18nService, $analytics, utilsService,
|
||||||
environmentService, toastr, $timeout) {
|
environmentService, toastr, $timeout) {
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
|
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
|
||||||
|
|
||||||
$scope.baseUrl = environmentService.baseUrl || '';
|
$scope.baseUrl = environmentService.baseUrl || '';
|
||||||
$scope.webVaultUrl = environmentService.webVaultUrl || '';
|
$scope.webVaultUrl = environmentService.webVaultUrl || '';
|
||||||
$scope.apiUrl = environmentService.apiUrl || '';
|
$scope.apiUrl = environmentService.apiUrl || '';
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
angular
|
angular
|
||||||
.module('bit.vault')
|
.module('bit.vault')
|
||||||
|
|
||||||
.controller('vaultAddCipherController', function ($scope, $state, $stateParams, cipherService, folderService,
|
.controller('vaultAddCipherController', function ($scope, $state, $stateParams, cipherService, folderService,
|
||||||
cryptoService, toastr, utilsService, $analytics, i18nService, constantsService) {
|
cryptoService, toastr, utilsService, $analytics, i18nService, constantsService, $timeout) {
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
$scope.constants = constantsService;
|
$scope.constants = constantsService;
|
||||||
$scope.addFieldType = constantsService.fieldType.text.toString();
|
$scope.addFieldType = constantsService.fieldType.text.toString();
|
||||||
@@ -30,13 +30,16 @@
|
|||||||
angular.extend($scope.cipher, $stateParams.cipher);
|
angular.extend($scope.cipher, $stateParams.cipher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
|
||||||
if (!$stateParams.cipher && $scope.cipher.name && $scope.cipher.login && $scope.cipher.login.uri) {
|
if (!$stateParams.cipher && $scope.cipher.name && $scope.cipher.login && $scope.cipher.login.uri) {
|
||||||
$('#username').focus();
|
document.getElementById('loginUsername').focus();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$('#name').focus();
|
document.getElementById('name').focus();
|
||||||
}
|
}
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
}, 500);
|
||||||
|
|
||||||
folderService.getAllDecrypted().then(function (folders) {
|
folderService.getAllDecrypted().then(function (folders) {
|
||||||
$scope.folders = folders;
|
$scope.folders = folders;
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ angular
|
|||||||
.module('bit.vault')
|
.module('bit.vault')
|
||||||
|
|
||||||
.controller('vaultAttachmentsController', function ($scope, $state, $stateParams, cipherService, toastr,
|
.controller('vaultAttachmentsController', function ($scope, $state, $stateParams, cipherService, toastr,
|
||||||
SweetAlert, utilsService, $analytics, i18nService, cryptoService, tokenService) {
|
SweetAlert, utilsService, $analytics, i18nService, cryptoService, tokenService, $timeout) {
|
||||||
$scope.i18n = i18nService;
|
$timeout(function () {
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
$scope.i18n = i18nService;
|
||||||
$scope.isPremium = tokenService.getPremium();
|
$scope.isPremium = tokenService.getPremium();
|
||||||
$scope.canAccessAttachments = $scope.isPremium;
|
$scope.canAccessAttachments = $scope.isPremium;
|
||||||
$scope.hasUpdatedKey = false;
|
$scope.hasUpdatedKey = false;
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ angular
|
|||||||
.module('bit.vault')
|
.module('bit.vault')
|
||||||
|
|
||||||
.controller('vaultEditCipherController', function ($scope, $state, $stateParams, cipherService, folderService,
|
.controller('vaultEditCipherController', function ($scope, $state, $stateParams, cipherService, folderService,
|
||||||
cryptoService, toastr, SweetAlert, utilsService, $analytics, i18nService, constantsService) {
|
cryptoService, toastr, SweetAlert, utilsService, $analytics, i18nService, constantsService, $timeout) {
|
||||||
|
$timeout(function () {
|
||||||
|
utilsService.initListSectionItemListeners(document, angular);
|
||||||
|
document.getElementById('name').focus();
|
||||||
|
}, 500);
|
||||||
|
|
||||||
$scope.i18n = i18nService;
|
$scope.i18n = i18nService;
|
||||||
$scope.constants = constantsService;
|
$scope.constants = constantsService;
|
||||||
$scope.showAttachments = !utilsService.isEdge();
|
$scope.showAttachments = !utilsService.isEdge();
|
||||||
@@ -16,8 +21,6 @@ angular
|
|||||||
folderId: null
|
folderId: null
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#name').focus();
|
|
||||||
|
|
||||||
if ($stateParams.cipher) {
|
if ($stateParams.cipher) {
|
||||||
angular.extend($scope.cipher, $stateParams.cipher);
|
angular.extend($scope.cipher, $stateParams.cipher);
|
||||||
}
|
}
|
||||||
@@ -33,8 +36,6 @@ angular
|
|||||||
$scope.folders = folders;
|
$scope.folders = folders;
|
||||||
});
|
});
|
||||||
|
|
||||||
utilsService.initListSectionItemListeners($(document), angular);
|
|
||||||
|
|
||||||
$scope.typeChanged = function () {
|
$scope.typeChanged = function () {
|
||||||
$scope.cipher.type = parseInt($scope.selectedType);
|
$scope.cipher.type = parseInt($scope.selectedType);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -293,53 +293,70 @@ export default class UtilsService {
|
|||||||
return this.analyticsIdCache;
|
return this.analyticsIdCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
initListSectionItemListeners(doc: any, angular: any) {
|
initListSectionItemListeners(doc: Document, angular: any) {
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
throw new Error('doc parameter required');
|
throw new Error('theDoc parameter required');
|
||||||
}
|
}
|
||||||
|
|
||||||
doc.on('click', '.list-section-item', function(e: JQuery.Event) {
|
const sectionItems = doc.querySelectorAll('.list-section-item');
|
||||||
if (e.isDefaultPrevented && e.isDefaultPrevented.name === 'returnTrue') {
|
for (const item of sectionItems) {
|
||||||
|
item.addEventListener('click', (e) => {
|
||||||
|
if (e.defaultPrevented) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = $(this).find('input, textarea')
|
const el = e.target as HTMLElement;
|
||||||
.not('input[type="checkbox"], input[type="radio"], input[type="hidden"]');
|
|
||||||
const checkbox = $(this).find('input[type="checkbox"]');
|
|
||||||
const select = $(this).find('select');
|
|
||||||
|
|
||||||
if (text.length > 0 && e.target === text[0]) {
|
// Labels will already focus the input
|
||||||
|
if (el.tagName != null && el.tagName.toLowerCase() === 'label') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (checkbox.length > 0 && e.target === checkbox[0]) {
|
|
||||||
|
const textFilter = 'input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"])';
|
||||||
|
const text = el.querySelectorAll(textFilter + ',textarea');
|
||||||
|
const checkbox = el.querySelectorAll('input[type="checkbox"]');
|
||||||
|
const select = el.querySelectorAll('select');
|
||||||
|
|
||||||
|
// Return if they click the actual element
|
||||||
|
if (text.length > 0 && el === text[0]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (select.length > 0 && e.target === select[0]) {
|
if (checkbox.length > 0 && el === checkbox[0]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (select.length > 0 && el === select[0]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (text.length > 0) {
|
if (text.length > 0) {
|
||||||
text.focus();
|
(text[0] as HTMLElement).focus();
|
||||||
|
} else if (select.length > 0) {
|
||||||
|
(select[0] as HTMLElement).focus();
|
||||||
} else if (checkbox.length > 0) {
|
} else if (checkbox.length > 0) {
|
||||||
checkbox.prop('checked', !checkbox.is(':checked'));
|
const cb = checkbox[0] as HTMLInputElement;
|
||||||
|
cb.checked = !cb.checked;
|
||||||
if (angular) {
|
if (angular) {
|
||||||
angular.element(checkbox[0]).triggerHandler('click');
|
angular.element(checkbox[0]).triggerHandler('click');
|
||||||
}
|
}
|
||||||
} else if (select.length > 0) {
|
|
||||||
select.focus();
|
|
||||||
}
|
}
|
||||||
});
|
}, false);
|
||||||
|
}
|
||||||
|
|
||||||
doc.on('focus', '.list-section-item input, .list-section-item select, .list-section-item textarea',
|
const sectionFormItems = doc.querySelectorAll(
|
||||||
function(e: Event) {
|
'.list-section-item input, .list-section-item select, .list-section-item textarea');
|
||||||
$(this).parent().addClass('active');
|
for (const item of sectionFormItems) {
|
||||||
});
|
item.addEventListener('focus', (e: Event) => {
|
||||||
doc.on('blur', '.list-section-item input, .list-section-item select, .list-section-item textarea',
|
const el = e.target as HTMLElement;
|
||||||
function(e: Event) {
|
el.parentElement.classList.add('active');
|
||||||
$(this).parent().removeClass('active');
|
}, false);
|
||||||
});
|
|
||||||
|
item.addEventListener('blur', (e: Event) => {
|
||||||
|
const el = e.target as HTMLElement;
|
||||||
|
el.parentElement.classList.remove('active');
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getDomain(uriString: string): string {
|
getDomain(uriString: string): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user