mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 22:33:35 +00:00
icon component updates for all cipher types
This commit is contained in:
@@ -3,25 +3,76 @@ angular
|
|||||||
|
|
||||||
.component('icon', {
|
.component('icon', {
|
||||||
bindings: {
|
bindings: {
|
||||||
uri: '<'
|
cipher: '<'
|
||||||
},
|
},
|
||||||
template: '<div class="icon" ng-if="$ctrl.enabled()"><img src="{{$ctrl.url}}"></div>',
|
template: '<div class="icon" ng-if="$ctrl.enabled">' +
|
||||||
controller: function (stateService) {
|
'<img src="{{$ctrl.image}}" fallback-src="{{$ctrl.fallbackImage}}" ng-if="$ctrl.image" alt="" />' +
|
||||||
this.$onInit = (function () {
|
'<i class="fa fa-fw fa-lg {{$ctrl.icon}}" ng-if="!$ctrl.image"></i>' +
|
||||||
this.enabled = function () {
|
'</div>',
|
||||||
return stateService.getState('faviconEnabled');
|
controller: function (stateService, constantsService) {
|
||||||
};
|
var ctrl = this;
|
||||||
}).bind(this);
|
|
||||||
|
|
||||||
this.$onChanges = (function () {
|
ctrl.$onInit = function () {
|
||||||
var hostname;
|
ctrl.enabled = stateService.getState('faviconEnabled');
|
||||||
try {
|
if (ctrl.enabled) {
|
||||||
hostname = new URL(this.uri).hostname;
|
switch (ctrl.cipher.type) {
|
||||||
this.url = 'https://icons.bitwarden.com/' + hostname + '/icon.png';
|
case constantsService.cipherType.login:
|
||||||
} catch (e) {
|
setLoginIcon(ctrl.cipher);
|
||||||
// Invalid URL.
|
break;
|
||||||
this.url = chrome.extension.getURL('images/fa-globe.png');
|
case constantsService.cipherType.secureNote:
|
||||||
|
ctrl.icon = 'fa-sticky-note-o';
|
||||||
|
break;
|
||||||
|
case constantsService.cipherType.card:
|
||||||
|
ctrl.icon = 'fa-credit-card';
|
||||||
|
break;
|
||||||
|
case constantsService.cipherType.identity:
|
||||||
|
ctrl.icon = 'fa-id-card-o';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}).bind(this);
|
};
|
||||||
|
|
||||||
|
ctrl.$onChanges = function () {
|
||||||
|
if (ctrl.cipher.type === constantsService.cipherType.login) {
|
||||||
|
setLoginIcon(ctrl.cipher);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function setLoginIcon() {
|
||||||
|
if (ctrl.cipher.login.uri) {
|
||||||
|
var hostnameUri = ctrl.cipher.login.uri,
|
||||||
|
isWebsite = false;
|
||||||
|
|
||||||
|
if (hostnameUri.indexOf('androidapp://') === 0) {
|
||||||
|
ctrl.icon = 'fa-android';
|
||||||
|
}
|
||||||
|
else if (hostnameUri.indexOf('iosapp://') === 0) {
|
||||||
|
ctrl.icon = 'fa-apple';
|
||||||
|
}
|
||||||
|
else if (hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('http://') !== 0 &&
|
||||||
|
hostnameUri.indexOf('https://') !== 0) {
|
||||||
|
hostnameUri = "http://" + hostnameUri;
|
||||||
|
isWebsite = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
isWebsite = hostnameUri.indexOf('http') === 0 && hostnameUri.indexOf('.') > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isWebsite) {
|
||||||
|
try {
|
||||||
|
var url = new URL(hostnameUri);
|
||||||
|
ctrl.image = 'https://icons.bitwarden.com/' + url.hostname + '/icon.png';
|
||||||
|
ctrl.fallbackImage = chrome.extension.getURL('images/fa-globe.png');
|
||||||
|
}
|
||||||
|
catch (e) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ctrl.icon) {
|
||||||
|
ctrl.icon = 'fa-globe';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
11
src/popup/app/directives/fallbackSrcDirective.js
Normal file
11
src/popup/app/directives/fallbackSrcDirective.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
angular
|
||||||
|
.module('bit.directives')
|
||||||
|
|
||||||
|
.directive('fallbackSrc', function () {
|
||||||
|
return function (scope, element, attrs) {
|
||||||
|
var el = $(element);
|
||||||
|
el.bind('error', function (event) {
|
||||||
|
el.attr('src', attrs.fallbackSrc);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
ng-class="{'disabled': !cipher.uri}">
|
ng-class="{'disabled': !cipher.uri}">
|
||||||
<i class="fa fa-lg fa-share-square-o"></i>
|
<i class="fa fa-lg fa-share-square-o"></i>
|
||||||
</span>
|
</span>
|
||||||
<icon uri="cipher.uri"></icon>
|
<icon cipher="cipher"></icon>
|
||||||
<span class="text">
|
<span class="text">
|
||||||
{{cipher.name}}
|
{{cipher.name}}
|
||||||
<i class="fa fa-share-alt text-muted" ng-if="cipher.organizationId" title="{{i18n.shared}}"></i>
|
<i class="fa fa-share-alt text-muted" ng-if="cipher.organizationId" title="{{i18n.shared}}"></i>
|
||||||
@@ -88,7 +88,7 @@
|
|||||||
ng-class="{'disabled': !cipher.uri}">
|
ng-class="{'disabled': !cipher.uri}">
|
||||||
<i class="fa fa-lg fa-share-square-o"></i>
|
<i class="fa fa-lg fa-share-square-o"></i>
|
||||||
</span>
|
</span>
|
||||||
<icon uri="cipher.uri"></icon>
|
<icon cipher="cipher"></icon>
|
||||||
<span class="text">
|
<span class="text">
|
||||||
{{cipher.name}}
|
{{cipher.name}}
|
||||||
<i class="fa fa-share-alt text-muted" ng-if="cipher.organizationId" title="{{i18n.shared}}"></i>
|
<i class="fa fa-share-alt text-muted" ng-if="cipher.organizationId" title="{{i18n.shared}}"></i>
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
<script src="app/directives/formDirective.js"></script>
|
<script src="app/directives/formDirective.js"></script>
|
||||||
<script src="app/directives/stopClickDirective.js"></script>
|
<script src="app/directives/stopClickDirective.js"></script>
|
||||||
<script src="app/directives/stopPropDirective.js"></script>
|
<script src="app/directives/stopPropDirective.js"></script>
|
||||||
|
<script src="app/directives/fallbackSrcDirective.js"></script>
|
||||||
|
|
||||||
<script src="app/components/componentsModule.js"></script>
|
<script src="app/components/componentsModule.js"></script>
|
||||||
<script src="app/components/iconComponent.js"></script>
|
<script src="app/components/iconComponent.js"></script>
|
||||||
|
|||||||
@@ -357,6 +357,7 @@
|
|||||||
height: 36px;
|
height: 36px;
|
||||||
width: 34px;
|
width: 34px;
|
||||||
margin-left: -5px;
|
margin-left: -5px;
|
||||||
|
color: @text-muted;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
|
|||||||
Reference in New Issue
Block a user