Skip to content

Commit

Permalink
add Image Preview in Content Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcibotari committed Sep 28, 2024
1 parent 7383a00 commit f57aa5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@if (asset.type.startsWith('image/')) {
<img
matListItemAvatar
llImagePreview
llImagePreview="3"
class="border object-contain bg-stripes-gray !rounded"
width="200"
height="200"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@if (asset.type.startsWith('image/')) {
<img
matListItemAvatar
llImagePreview="3"
class="border object-contain bg-stripes-gray !rounded"
width="200"
height="200"
Expand Down
34 changes: 25 additions & 9 deletions src/app/shared/directives/image-preview.directive.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import { Directive, ElementRef, HostListener } from '@angular/core';
import { Directive, ElementRef, HostListener, input } from '@angular/core';

@Directive({
selector: '[llImagePreview]',
selector: 'img[llImagePreview]',
})
export class ImagePreviewDirective {
constructor(private hostElement: ElementRef<HTMLImageElement>) {
console.log('ImagePreviewDirective', hostElement.nativeElement);
scale = input<number>(2, { alias: 'llImagePreview' });

constructor(private hostElement: ElementRef<HTMLImageElement>) {}

@HostListener('mouseover')
public onMouseOver() {
if (this.hostElement.nativeElement.parentElement) {
this.hostElement.nativeElement.parentElement.style.overflow = 'visible';
}
this.hostElement.nativeElement.style.zIndex = '50';
this.hostElement.nativeElement.style.transform = `scale(${this.scale() || 2})`;
this.hostElement.nativeElement.style.transition = 'transform 0.3s ease-in-out';
}

@HostListener('mouseover', ['$event'])
public onMouseOver(event: MouseEvent) {
const img = event.target as HTMLImageElement;
console.log('mouseover', event);
console.log('mouseover', img.srcset);
@HostListener('mouseout')
public onMouseOut() {
this.hostElement.nativeElement.style.transform = 'scale(1)';
this.hostElement.nativeElement.style.zIndex = '';
setTimeout(() => {
if (this.hostElement.nativeElement.parentElement) {
this.hostElement.nativeElement.style.transform = '';
this.hostElement.nativeElement.style.transition = '';
this.hostElement.nativeElement.parentElement.style.overflow = '';
}
}, 400);
}
}

0 comments on commit f57aa5e

Please sign in to comment.