1
0
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:
Kyle Spearrin
2017-10-17 13:16:05 -04:00
parent 09c340bbe5
commit cebf913999
4 changed files with 35 additions and 33 deletions

View File

@@ -5,32 +5,28 @@ 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:
ctrl.icon = 'fa-sticky-note-o'; ctrl.icon = 'fa-sticky-note-o';
break; break;
case constantsService.cipherType.card: case constantsService.cipherType.card:
ctrl.icon = 'fa-credit-card'; ctrl.icon = 'fa-credit-card';
break; break;
case constantsService.cipherType.identity: case constantsService.cipherType.identity:
ctrl.icon = 'fa-id-card-o'; ctrl.icon = 'fa-id-card-o';
break; break;
default: default:
break; break;
}
} }
}; };
@@ -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;
} }
} }

View 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>

View File

@@ -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) {

View File

@@ -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;
}; };