mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
updates to icon component and state init
This commit is contained in:
@@ -5,18 +5,15 @@ angular
|
|||||||
bindings: {
|
bindings: {
|
||||||
cipher: '<'
|
cipher: '<'
|
||||||
},
|
},
|
||||||
template: '<div class="icon" ng-if="$ctrl.enabled">' +
|
templateUrl: 'app/components/views/icon.html',
|
||||||
'<img ng-src="{{$ctrl.image}}" fallback-src="{{$ctrl.fallbackImage}}" ng-if="$ctrl.image" alt="" />' +
|
|
||||||
'<i class="fa fa-fw fa-lg {{$ctrl.icon}}" ng-if="!$ctrl.image"></i>' +
|
|
||||||
'</div>',
|
|
||||||
controller: function (stateService, constantsService) {
|
controller: function (stateService, constantsService) {
|
||||||
var ctrl = this;
|
var ctrl = this;
|
||||||
ctrl.enabled = stateService.getState('faviconEnabled');
|
ctrl.imageEnabled = stateService.getState('faviconEnabled');
|
||||||
|
|
||||||
ctrl.$onChanges = function () {
|
ctrl.$onChanges = function () {
|
||||||
if (ctrl.enabled) {
|
|
||||||
switch (ctrl.cipher.type) {
|
switch (ctrl.cipher.type) {
|
||||||
case constantsService.cipherType.login:
|
case constantsService.cipherType.login:
|
||||||
|
ctrl.icon = 'fa-globe';
|
||||||
setLoginIcon(ctrl.cipher);
|
setLoginIcon(ctrl.cipher);
|
||||||
break;
|
break;
|
||||||
case constantsService.cipherType.secureNote:
|
case constantsService.cipherType.secureNote:
|
||||||
@@ -31,7 +28,6 @@ angular
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function setLoginIcon() {
|
function setLoginIcon() {
|
||||||
@@ -47,18 +43,16 @@ angular
|
|||||||
ctrl.icon = 'fa-apple';
|
ctrl.icon = 'fa-apple';
|
||||||
ctrl.image = null;
|
ctrl.image = null;
|
||||||
}
|
}
|
||||||
else if (hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('http://') !== 0 &&
|
else if (ctrl.imageEnabled && hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('http://') !== 0 &&
|
||||||
hostnameUri.indexOf('https://') !== 0) {
|
hostnameUri.indexOf('https://') !== 0) {
|
||||||
hostnameUri = "http://" + hostnameUri;
|
hostnameUri = "http://" + hostnameUri;
|
||||||
isWebsite = true;
|
isWebsite = true;
|
||||||
ctrl.icon = 'fa-globe';
|
|
||||||
}
|
}
|
||||||
else {
|
else if (ctrl.imageEnabled) {
|
||||||
isWebsite = hostnameUri.indexOf('http') === 0 && hostnameUri.indexOf('.') > 0;
|
isWebsite = hostnameUri.indexOf('http') === 0 && hostnameUri.indexOf('.') > 0;
|
||||||
ctrl.icon = 'fa-globe';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isWebsite) {
|
if (ctrl.imageEnabled && isWebsite) {
|
||||||
try {
|
try {
|
||||||
var url = new URL(hostnameUri);
|
var url = new URL(hostnameUri);
|
||||||
ctrl.image = 'https://icons.bitwarden.com/' + url.hostname + '/icon.png';
|
ctrl.image = 'https://icons.bitwarden.com/' + url.hostname + '/icon.png';
|
||||||
@@ -68,7 +62,6 @@ angular
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctrl.icon = 'fa-globe';
|
|
||||||
ctrl.image = null;
|
ctrl.image = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/popup/app/components/views/icon.html
Normal file
4
src/popup/app/components/views/icon.html
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<div class="icon">
|
||||||
|
<img ng-src="{{$ctrl.image}}" fallback-src="{{$ctrl.fallbackImage}}" ng-if="$ctrl.imageEnabled && $ctrl.image" alt="" />
|
||||||
|
<i class="fa fa-fw fa-lg {{$ctrl.icon}}" ng-if="!$ctrl.imageEnabled || !$ctrl.image"></i>
|
||||||
|
</div>
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
.module('bit')
|
.module('bit')
|
||||||
|
|
||||||
.config(function ($stateProvider, $urlRouterProvider, $compileProvider, $sceDelegateProvider, toastrConfig) {
|
.config(function ($stateProvider, $urlRouterProvider, $compileProvider, $sceDelegateProvider, toastrConfig) {
|
||||||
$compileProvider.imgSrcSanitizationWhitelist(/^\s*((https?|ftp|file|blob):|data:image\/|(moz|chrome|ms-browser)-extension)/);
|
$compileProvider.imgSrcSanitizationWhitelist(
|
||||||
|
/^\s*((https?|ftp|file|blob):|data:image\/|(moz|chrome|ms-browser)-extension)/);
|
||||||
|
|
||||||
angular.extend(toastrConfig, {
|
angular.extend(toastrConfig, {
|
||||||
closeButton: true,
|
closeButton: true,
|
||||||
@@ -258,9 +259,7 @@
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.run(function ($rootScope, userService, $state, constantsService, stateService) {
|
.run(function ($rootScope, userService, $state, constantsService, stateService) {
|
||||||
chrome.storage.local.get(constantsService.disableFaviconKey, function(obj) {
|
stateService.init();
|
||||||
stateService.saveState('faviconEnabled', !obj[constantsService.disableFaviconKey]);
|
|
||||||
});
|
|
||||||
|
|
||||||
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
||||||
if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) {
|
if ($state.current.name.indexOf('tabs.') > -1 && toState.name.indexOf('tabs.') > -1) {
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
angular
|
angular
|
||||||
.module('bit.services')
|
.module('bit.services')
|
||||||
|
|
||||||
.factory('stateService', function () {
|
.factory('stateService', function (utilsService, constantsService) {
|
||||||
var _service = {},
|
var _service = {},
|
||||||
_state = {};
|
_state = {};
|
||||||
|
|
||||||
|
_service.init = function () {
|
||||||
|
utilsService.getObjFromStorage(constantsService.disableFaviconKey).then(function (disabledFavicons) {
|
||||||
|
_service.saveState('faviconEnabled', !disabledFavicons);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
_service.saveState = function (key, data) {
|
_service.saveState = function (key, data) {
|
||||||
_state[key] = data;
|
_state[key] = data;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user