icon component only $onChanges

This commit is contained in:
Kyle Spearrin 2017-10-16 11:12:24 -04:00
parent 9a79f6989e
commit 276be2fa87
1 changed files with 7 additions and 10 deletions

View File

@ -6,13 +6,13 @@ angular
cipher: '<' cipher: '<'
}, },
template: '<div class="icon" ng-if="$ctrl.enabled">' + template: '<div class="icon" ng-if="$ctrl.enabled">' +
'<img src="{{$ctrl.image}}" fallback-src="{{$ctrl.fallbackImage}}" ng-if="$ctrl.image" alt="" />' + '<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>' + '<i class="fa fa-fw fa-lg {{$ctrl.icon}}" ng-if="!$ctrl.image"></i>' +
'</div>', '</div>',
controller: function (stateService, constantsService) { controller: function (stateService, constantsService) {
var ctrl = this; var ctrl = this;
ctrl.$onInit = function () { ctrl.$onChanges = function () {
ctrl.enabled = stateService.getState('faviconEnabled'); ctrl.enabled = stateService.getState('faviconEnabled');
if (ctrl.enabled) { if (ctrl.enabled) {
switch (ctrl.cipher.type) { switch (ctrl.cipher.type) {
@ -34,12 +34,6 @@ angular
} }
}; };
ctrl.$onChanges = function () {
if (ctrl.cipher.type === constantsService.cipherType.login) {
setLoginIcon(ctrl.cipher);
}
};
function setLoginIcon() { function setLoginIcon() {
if (ctrl.cipher.login.uri) { if (ctrl.cipher.login.uri) {
var hostnameUri = ctrl.cipher.login.uri, var hostnameUri = ctrl.cipher.login.uri,
@ -47,9 +41,11 @@ angular
if (hostnameUri.indexOf('androidapp://') === 0) { if (hostnameUri.indexOf('androidapp://') === 0) {
ctrl.icon = 'fa-android'; ctrl.icon = 'fa-android';
ctrl.image = null;
} }
else if (hostnameUri.indexOf('iosapp://') === 0) { else if (hostnameUri.indexOf('iosapp://') === 0) {
ctrl.icon = 'fa-apple'; ctrl.icon = 'fa-apple';
ctrl.image = null;
} }
else if (hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('http://') !== 0 && else if (hostnameUri.indexOf('://') === -1 && hostnameUri.indexOf('http://') !== 0 &&
hostnameUri.indexOf('https://') !== 0) { hostnameUri.indexOf('https://') !== 0) {
@ -61,6 +57,7 @@ angular
} }
if (isWebsite) { if (isWebsite) {
ctrl.icon = 'fa-globe';
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';
@ -69,9 +66,9 @@ angular
catch (e) { } catch (e) { }
} }
} }
else {
if (!ctrl.icon) {
ctrl.icon = 'fa-globe'; ctrl.icon = 'fa-globe';
ctrl.image = null;
} }
} }
} }