1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-28 17:27:50 +01:00

directives

This commit is contained in:
Kyle Spearrin 2018-01-23 23:38:56 -05:00
parent e06704431a
commit 5703782a0f
10 changed files with 59 additions and 3 deletions

View File

@ -9,9 +9,12 @@ import { ServicesModule } from './services/services.module';
import { AppComponent } from './app.component';
import { CiphersComponent } from './vault/ciphers.component';
import { FallbackSrcDirective } from './directives/fallback-src.directive';
import { GroupingsComponent } from './vault/groupings.component';
import { IconComponent } from './vault/icon.component';
import { LoginComponent } from './accounts/login.component';
import { StopClickDirective } from './directives/stop-click.directive';
import { StopPropDirective } from './directives/stop-prop.directive';
import { VaultComponent } from './vault/vault.component';
import { ViewComponent } from './vault/view.component';
@ -25,9 +28,11 @@ import { ViewComponent } from './vault/view.component';
declarations: [
AppComponent,
CiphersComponent,
FallbackSrcDirective,
GroupingsComponent,
IconComponent,
LoginComponent,
StopClickDirective,
VaultComponent,
ViewComponent,
],

View File

@ -0,0 +1,20 @@
import {
Directive,
ElementRef,
HostListener,
Input,
} from '@angular/core';
@Directive({
selector: '[appFallbackSrc]'
})
export class FallbackSrcDirective {
@Input('appFallbackSrc') appFallbackSrc: string;
constructor(private el: ElementRef) {
}
@HostListener('error') OnError() {
this.el.nativeElement.src = this.appFallbackSrc;
}
}

View File

@ -0,0 +1,13 @@
import {
Directive,
HostListener,
} from '@angular/core';
@Directive({
selector: '[appStopClick]'
})
export class StopClickDirective {
@HostListener('click', ['$event']) onClick($event: MouseEvent) {
$event.preventDefault();
}
}

View File

@ -0,0 +1,13 @@
import {
Directive,
HostListener,
} from '@angular/core';
@Directive({
selector: '[appStopProp]'
})
export class StopPropDirective {
@HostListener('click', ['$event']) onClick($event: MouseEvent) {
$event.stopPropagation();
}
}

View File

@ -10,7 +10,7 @@
<div class="content">
<div class="list">
<div class="list-section" style="padding-top: 0; padding-bottom: 0;">
<a *ngFor="let cipher of ciphers"
<a *ngFor="let cipher of ciphers" appStopClick (click)="viewCipher(cipher)"
href="#" class="list-section-item condensed" title="View Item">
<app-vault-icon [cipher]="cipher"></app-vault-icon>
<span class="text">

View File

@ -20,4 +20,8 @@ export class CiphersComponent implements OnChanges {
ngOnChanges() {
}
viewCipher(cipher: any) {
console.log(cipher.id);
}
}

View File

@ -1,4 +1,4 @@
<div class="icon">
<img [src]="image" *ngIf="imageEnabled && image" alt="" />
<img [src]="image" appFallbackSrc="{{fallbackImage}}" *ngIf="imageEnabled && image" alt="" />
<i class="fa fa-fw fa-lg {{icon}}" *ngIf="!imageEnabled || !image"></i>
</div>

View File

@ -78,7 +78,7 @@ export class IconComponent implements OnChanges {
try {
const url = new URL(hostnameUri);
this.image = this.iconsUrl + '/' + url.hostname + '/icon.png';
this.fallbackImage = '../images/fa-globe.png'; // TODO?
this.fallbackImage = 'images/fa-globe.png';
} catch (e) { }
}
} else {

BIN
src/images/fa-globe.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

View File

@ -56,6 +56,7 @@ const main = {
]),
new CopyWebpackPlugin([
'./src/package.json',
{ from: './src/images', to: 'images' },
]),
],
externals: [nodeExternals()]