mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-23 11:56:00 +01:00
move initListSectionItemListeners to popup utils
This commit is contained in:
parent
680c937624
commit
9921d6dba3
@ -1,10 +1,10 @@
|
||||
angular
|
||||
.module('bit.accounts')
|
||||
|
||||
.controller('accountsHintController', function ($scope, $state, apiService, toastr, $q, platformUtilsService,
|
||||
.controller('accountsHintController', function ($scope, $state, apiService, toastr, $q, popupUtilsService,
|
||||
$analytics, i18nService, $timeout) {
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
document.getElementById('email').focus();
|
||||
}, 500);
|
||||
|
||||
|
@ -2,9 +2,9 @@ angular
|
||||
.module('bit.accounts')
|
||||
|
||||
.controller('accountsLoginController', function ($scope, $state, $stateParams, authService, userService, toastr,
|
||||
platformUtilsService, $analytics, i18nService, $timeout) {
|
||||
popupUtilsService, $analytics, i18nService, $timeout) {
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
if ($stateParams.email) {
|
||||
document.getElementById('master-password').focus();
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ angular
|
||||
|
||||
.controller('accountsLoginTwoFactorController', function ($scope, $state, authService, toastr, platformUtilsService,
|
||||
$analytics, i18nService, $stateParams, $filter, constantsService, $timeout, $window, cryptoService, apiService,
|
||||
environmentService, SweetAlert) {
|
||||
environmentService, SweetAlert, popupUtilsService) {
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
|
||||
$scope.i18n = i18nService;
|
||||
|
@ -3,10 +3,10 @@ angular
|
||||
|
||||
.controller(
|
||||
'accountsRegisterController',
|
||||
function ($scope, $state, cryptoService, toastr, $q, apiService, platformUtilsService, $analytics,
|
||||
function ($scope, $state, cryptoService, toastr, $q, apiService, popupUtilsService, $analytics,
|
||||
i18nService, $timeout) {
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
document.getElementById('email').focus();
|
||||
}, 500);
|
||||
|
||||
|
@ -3,15 +3,15 @@ import * as template from './lock.component.html';
|
||||
|
||||
import { CryptoService } from 'jslib/abstractions/crypto.service';
|
||||
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
|
||||
import PopupUtilsService from '../services/popupUtils.service';
|
||||
|
||||
export class LockController {
|
||||
i18n: any;
|
||||
masterPassword: string;
|
||||
|
||||
constructor(public $state: any, public i18nService: any, private $timeout: ng.ITimeoutService,
|
||||
private platformUtilsService: PlatformUtilsService,
|
||||
public cryptoService: CryptoService, public toastr: any, public userService: UserService,
|
||||
public messagingService: MessagingService, public SweetAlert: any) {
|
||||
this.i18n = i18nService;
|
||||
@ -19,7 +19,7 @@ export class LockController {
|
||||
|
||||
$onInit() {
|
||||
this.$timeout(() => {
|
||||
this.platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
PopupUtilsService.initListSectionItemListeners(document, angular);
|
||||
document.getElementById('master-password').focus();
|
||||
}, 500);
|
||||
}
|
||||
|
87
src/popup/app/services/popupUtils.service.ts
Normal file
87
src/popup/app/services/popupUtils.service.ts
Normal file
@ -0,0 +1,87 @@
|
||||
export default class PopupUtilsService {
|
||||
static initListSectionItemListeners(doc: Document, angular: any): void {
|
||||
if (!doc) {
|
||||
throw new Error('doc parameter required');
|
||||
}
|
||||
|
||||
const sectionItems = doc.querySelectorAll(
|
||||
'.list-section-item:not([data-bw-events="1"])');
|
||||
const sectionFormItems = doc.querySelectorAll(
|
||||
'.list-section-item:not([data-bw-events="1"]) input, ' +
|
||||
'.list-section-item:not([data-bw-events="1"]) select, ' +
|
||||
'.list-section-item:not([data-bw-events="1"]) textarea');
|
||||
|
||||
sectionItems.forEach((item) => {
|
||||
(item as HTMLElement).dataset.bwEvents = '1';
|
||||
|
||||
item.addEventListener('click', (e) => {
|
||||
if (e.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
const el = e.target as HTMLElement;
|
||||
|
||||
// Some elements will already focus properly
|
||||
if (el.tagName != null) {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'label': case 'input': case 'textarea': case 'select':
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const cell = el.closest('.list-section-item');
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
const textFilter = 'input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"])';
|
||||
const text = cell.querySelectorAll(textFilter + ', textarea');
|
||||
const checkbox = cell.querySelectorAll('input[type="checkbox"]');
|
||||
const select = cell.querySelectorAll('select');
|
||||
|
||||
if (text.length > 0) {
|
||||
(text[0] as HTMLElement).focus();
|
||||
} else if (select.length > 0) {
|
||||
(select[0] as HTMLElement).focus();
|
||||
} else if (checkbox.length > 0) {
|
||||
const cb = checkbox[0] as HTMLInputElement;
|
||||
cb.checked = !cb.checked;
|
||||
if (angular) {
|
||||
angular.element(checkbox[0]).triggerHandler('click');
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
});
|
||||
|
||||
sectionFormItems.forEach((item) => {
|
||||
const itemCell = item.closest('.list-section-item');
|
||||
(itemCell as HTMLElement).dataset.bwEvents = '1';
|
||||
|
||||
item.addEventListener('focus', (e: Event) => {
|
||||
const el = e.target as HTMLElement;
|
||||
const cell = el.closest('.list-section-item');
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
cell.classList.add('active');
|
||||
}, false);
|
||||
|
||||
item.addEventListener('blur', (e: Event) => {
|
||||
const el = e.target as HTMLElement;
|
||||
const cell = el.closest('.list-section-item');
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
cell.classList.remove('active');
|
||||
}, false);
|
||||
});
|
||||
}
|
||||
|
||||
initListSectionItemListeners(doc: Document, angular: any): void {
|
||||
PopupUtilsService.initListSectionItemListeners(doc, angular);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import * as angular from 'angular';
|
||||
import AuthService from './auth.service';
|
||||
import * as backgroundServices from './background.service';
|
||||
import PopupUtilsService from './popupUtils.service';
|
||||
import StateService from './state.service';
|
||||
import { ValidationService } from './validation.service';
|
||||
|
||||
@ -13,6 +14,7 @@ export default angular
|
||||
.service('stateService', StateService)
|
||||
.service('validationService', ValidationService)
|
||||
.service('authService', AuthService)
|
||||
.service('popupUtilsService', PopupUtilsService)
|
||||
|
||||
.factory('messagingService', () => messagingService)
|
||||
.factory('storageService', backgroundServices.storageService)
|
||||
|
@ -2,7 +2,8 @@ import * as angular from 'angular';
|
||||
import * as template from './environment.component.html';
|
||||
|
||||
import { EnvironmentService } from 'jslib/abstractions/environment.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
|
||||
import PopupUtilsService from '../services/popupUtils.service';
|
||||
|
||||
export class EnvironmentController {
|
||||
iconsUrl: string;
|
||||
@ -12,12 +13,12 @@ export class EnvironmentController {
|
||||
baseUrl: string;
|
||||
i18n: any;
|
||||
|
||||
constructor(private i18nService: any, private $analytics: any, private platformUtilsService: PlatformUtilsService,
|
||||
constructor(private i18nService: any, private $analytics: any,
|
||||
private environmentService: EnvironmentService, private toastr: any, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
PopupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
|
||||
this.baseUrl = environmentService.baseUrl || '';
|
||||
|
@ -4,7 +4,8 @@ import * as template from './add-folder.component.html';
|
||||
import { Folder } from 'jslib/models/domain/folder';
|
||||
|
||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
|
||||
import PopupUtilsService from '../../services/popupUtils.service';
|
||||
|
||||
export class AddFolderController {
|
||||
savePromise: any;
|
||||
@ -12,10 +13,9 @@ export class AddFolderController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private folderService: FolderService, private $state: any, private toastr: any,
|
||||
platformUtilsService: PlatformUtilsService, private $analytics: any, private i18nService: any,
|
||||
$timeout: ng.ITimeoutService) {
|
||||
private $analytics: any, private i18nService: any, $timeout: ng.ITimeoutService) {
|
||||
$timeout(() => {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
PopupUtilsService.initListSectionItemListeners(document, angular);
|
||||
document.getElementById('name').focus();
|
||||
}, 500);
|
||||
|
||||
|
@ -4,7 +4,8 @@ import * as template from './edit-folder.component.html';
|
||||
import { Folder } from 'jslib/models/domain/folder';
|
||||
|
||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
|
||||
import PopupUtilsService from '../../services/popupUtils.service';
|
||||
|
||||
export class EditFolderController {
|
||||
$transition$: any;
|
||||
@ -14,12 +15,12 @@ export class EditFolderController {
|
||||
folder: Folder;
|
||||
|
||||
constructor($scope: any, $stateParams: any, private folderService: FolderService, private toastr: any,
|
||||
private $state: any, private SweetAlert: any, platformUtilsService: PlatformUtilsService,
|
||||
private $analytics: any, private i18nService: any, $timeout: ng.ITimeoutService) {
|
||||
private $state: any, private SweetAlert: any, private $analytics: any, private i18nService: any,
|
||||
$timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
PopupUtilsService.initListSectionItemListeners(document, angular);
|
||||
document.getElementById('name').focus();
|
||||
}, 500);
|
||||
|
||||
|
@ -8,6 +8,7 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||
|
||||
import PopupUtilsService from '../services/popupUtils.service';
|
||||
import StateService from '../services/state.service';
|
||||
|
||||
export class OptionsController {
|
||||
@ -26,7 +27,7 @@ export class OptionsController {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
PopupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
|
||||
this.loadSettings();
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as angular from 'angular';
|
||||
import * as template from './settings.component.html';
|
||||
|
||||
import { DeviceType } from 'jslib/enums/deviceType';
|
||||
|
||||
@ -10,7 +11,7 @@ import { MessagingService } from 'jslib/abstractions/messaging.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
import { StorageService } from 'jslib/abstractions/storage.service';
|
||||
|
||||
import * as template from './settings.component.html';
|
||||
import PopupUtilsService from '../services/popupUtils.service';
|
||||
|
||||
const RateUrls = {
|
||||
[DeviceType.Chrome]:
|
||||
@ -41,7 +42,7 @@ export class SettingsController {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
PopupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
|
||||
this.showOnLocked = !platformUtilsService.isFirefox() && !platformUtilsService.isEdge();
|
||||
|
@ -2,7 +2,8 @@ import * as angular from 'angular';
|
||||
import * as template from './password-generator.component.html';
|
||||
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||
|
||||
import PopupUtilsService from '../services/popupUtils.service';
|
||||
|
||||
export class PasswordGeneratorController {
|
||||
$transition$: any;
|
||||
@ -14,8 +15,8 @@ export class PasswordGeneratorController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private $state: any, private passwordGenerationService: PasswordGenerationService,
|
||||
private toastr: any, private platformUtilsService: PlatformUtilsService,
|
||||
private $analytics: any, private i18nService: any, private $timeout: ng.ITimeoutService) {
|
||||
private toastr: any, private $analytics: any, private i18nService: any,
|
||||
private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
passwordGenerationService.getOptions().then((options: any) => {
|
||||
@ -43,7 +44,7 @@ export class PasswordGeneratorController {
|
||||
this.showSelect = this.addState || this.editState;
|
||||
|
||||
this.$timeout(() => {
|
||||
this.platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
PopupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultAddCipherController', function ($scope, $state, $stateParams, cipherService, folderService,
|
||||
cryptoService, toastr, platformUtilsService, $analytics, i18nService, constantsService, $timeout) {
|
||||
cryptoService, toastr, popupUtilsService, $analytics, i18nService, constantsService, $timeout) {
|
||||
$scope.i18n = i18nService;
|
||||
$scope.constants = constantsService;
|
||||
$scope.addFieldType = constantsService.fieldType.text.toString();
|
||||
@ -31,7 +31,7 @@ angular
|
||||
}
|
||||
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
|
||||
if (!$stateParams.cipher && $scope.cipher.name && $scope.cipher.login && $scope.cipher.login.uri) {
|
||||
document.getElementById('loginUsername').focus();
|
||||
@ -49,7 +49,7 @@ angular
|
||||
$scope.cipher.type = parseInt($scope.selectedType);
|
||||
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
@ -106,7 +106,7 @@ angular
|
||||
});
|
||||
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
|
@ -2,9 +2,9 @@ angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultAttachmentsController', function ($scope, $state, $stateParams, cipherService, toastr,
|
||||
SweetAlert, platformUtilsService, $analytics, i18nService, cryptoService, tokenService, $timeout) {
|
||||
SweetAlert, popupUtilsService, $analytics, i18nService, cryptoService, tokenService, $timeout) {
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
|
||||
$scope.i18n = i18nService;
|
||||
|
@ -2,9 +2,10 @@ angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultEditCipherController', function ($scope, $state, $stateParams, cipherService, folderService,
|
||||
cryptoService, toastr, SweetAlert, platformUtilsService, $analytics, i18nService, constantsService, $timeout) {
|
||||
cryptoService, toastr, SweetAlert, platformUtilsService, $analytics, i18nService, constantsService, $timeout,
|
||||
popupUtilsService) {
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
document.getElementById('name').focus();
|
||||
}, 500);
|
||||
|
||||
@ -40,7 +41,7 @@ angular
|
||||
$scope.cipher.type = parseInt($scope.selectedType);
|
||||
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
@ -123,7 +124,7 @@ angular
|
||||
});
|
||||
|
||||
$timeout(function () {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
popupUtilsService.initListSectionItemListeners(document, angular);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
|
@ -112,88 +112,6 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
return this.analyticsIdCache;
|
||||
}
|
||||
|
||||
initListSectionItemListeners(doc: Document, angular: any): void {
|
||||
if (!doc) {
|
||||
throw new Error('doc parameter required');
|
||||
}
|
||||
|
||||
const sectionItems = doc.querySelectorAll(
|
||||
'.list-section-item:not([data-bw-events="1"])');
|
||||
const sectionFormItems = doc.querySelectorAll(
|
||||
'.list-section-item:not([data-bw-events="1"]) input, ' +
|
||||
'.list-section-item:not([data-bw-events="1"]) select, ' +
|
||||
'.list-section-item:not([data-bw-events="1"]) textarea');
|
||||
|
||||
sectionItems.forEach((item) => {
|
||||
(item as HTMLElement).dataset.bwEvents = '1';
|
||||
|
||||
item.addEventListener('click', (e) => {
|
||||
if (e.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
|
||||
const el = e.target as HTMLElement;
|
||||
|
||||
// Some elements will already focus properly
|
||||
if (el.tagName != null) {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case 'label': case 'input': case 'textarea': case 'select':
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const cell = el.closest('.list-section-item');
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
const textFilter = 'input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"])';
|
||||
const text = cell.querySelectorAll(textFilter + ', textarea');
|
||||
const checkbox = cell.querySelectorAll('input[type="checkbox"]');
|
||||
const select = cell.querySelectorAll('select');
|
||||
|
||||
if (text.length > 0) {
|
||||
(text[0] as HTMLElement).focus();
|
||||
} else if (select.length > 0) {
|
||||
(select[0] as HTMLElement).focus();
|
||||
} else if (checkbox.length > 0) {
|
||||
const cb = checkbox[0] as HTMLInputElement;
|
||||
cb.checked = !cb.checked;
|
||||
if (angular) {
|
||||
angular.element(checkbox[0]).triggerHandler('click');
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
});
|
||||
|
||||
sectionFormItems.forEach((item) => {
|
||||
const itemCell = item.closest('.list-section-item');
|
||||
(itemCell as HTMLElement).dataset.bwEvents = '1';
|
||||
|
||||
item.addEventListener('focus', (e: Event) => {
|
||||
const el = e.target as HTMLElement;
|
||||
const cell = el.closest('.list-section-item');
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
cell.classList.add('active');
|
||||
}, false);
|
||||
|
||||
item.addEventListener('blur', (e: Event) => {
|
||||
const el = e.target as HTMLElement;
|
||||
const cell = el.closest('.list-section-item');
|
||||
if (!cell) {
|
||||
return;
|
||||
}
|
||||
|
||||
cell.classList.remove('active');
|
||||
}, false);
|
||||
});
|
||||
}
|
||||
|
||||
getDomain(uriString: string): string {
|
||||
return BrowserPlatformUtilsService.getDomain(uriString);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user