-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
display PDF document preview in lightbox's iframe #97
Open
piotrmocek
wants to merge
7
commits into
themyth92:master
Choose a base branch
from
piotrmocek:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−34
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03fc61d
display PDF document preview in lightbox's iframe
7ad840c
Merge branch 'master' into master
piotrmocek 9d174b5
album.item.iframe attribute for files which do not ends with .pdf ext…
7589bd4
don't sanitize url for needsIframe method
985473d
use safe pipe to prevent iframe reload
8e3ccea
Emit FILE_NOT_FOUND event
42c7f96
updated package.json
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,7 @@ src/*.js | |
*.log | ||
/dist | ||
*.d.ts | ||
*.ngsummary.json | ||
*.ngsummary.json | ||
.idea | ||
.DS_Store | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "ngx-lightbox", | ||
"version": "2.4.0", | ||
"name": "@piotrmocek/ngx-lightbox", | ||
"version": "2.4.4", | ||
"description": "A port >= angular5 for lightbox2", | ||
"main": "index.js", | ||
"dependencies": {}, | ||
|
@@ -42,7 +42,7 @@ | |
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/themyth92/ngx-lightbox.git" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please dont change the name of the package |
||
"url": "git+https://github.com/piotrmocek/ngx-lightbox.git" | ||
}, | ||
"keywords": [ | ||
"lightbox2", | ||
|
@@ -52,7 +52,7 @@ | |
"angular", | ||
"directives" | ||
], | ||
"author": "themyth92", | ||
"author": "themyth92 & piotrmocek", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/themyth92/ngx-lightbox/issues" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import { DOCUMENT } from '@angular/common'; | ||
import {DOCUMENT} from '@angular/common'; | ||
import { | ||
AfterViewInit, | ||
Component, | ||
ElementRef, | ||
Inject, | ||
Input, | ||
OnDestroy, | ||
OnInit, | ||
OnInit, Pipe, PipeTransform, | ||
Renderer2, | ||
SecurityContext, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import { DomSanitizer } from '@angular/platform-browser'; | ||
import {DomSanitizer} from '@angular/platform-browser'; | ||
|
||
import { | ||
IAlbum, | ||
IEvent, | ||
LIGHTBOX_EVENT, | ||
LightboxEvent, | ||
LightboxWindowRef, | ||
} from './lightbox-event.service'; | ||
import {IAlbum, IEvent, LIGHTBOX_EVENT, LightboxEvent, LightboxWindowRef,} from './lightbox-event.service'; | ||
|
||
@Pipe({ name: 'safe' }) | ||
export class SafePipe implements PipeTransform { | ||
constructor(private sanitizer: DomSanitizer) {} | ||
transform(url) { | ||
return this.sanitizer.bypassSecurityTrustResourceUrl(url); | ||
} | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
|
@@ -30,7 +32,14 @@ import { | |
[src]="album[currentImageIndex].src" | ||
class="lb-image animation fadeIn" | ||
[hidden]="ui.showReloader" | ||
#image> | ||
#image *ngIf="!album[currentImageIndex].iframe && !needsIframe(album[currentImageIndex].src)"> | ||
<iframe class="lb-image" | ||
id="iframe" | ||
[src]="album[currentImageIndex].src | safe" | ||
class="lb-image lb-iframe animation fadeIn" | ||
[hidden]="ui.showReloader" | ||
#iframe *ngIf="album[currentImageIndex].iframe || needsIframe(album[currentImageIndex].src)"> | ||
</iframe> | ||
<div class="lb-nav" [hidden]="!ui.showArrowNav" #navArrow> | ||
<a class="lb-prev" [hidden]="!ui.showLeftArrow" (click)="prevImage()" #leftArrow></a> | ||
<a class="lb-next" [hidden]="!ui.showRightArrow" (click)="nextImage()" #rightArrow></a> | ||
|
@@ -80,6 +89,7 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
@ViewChild('navArrow', { static: false }) _navArrowElem: ElementRef; | ||
@ViewChild('dataContainer', { static: false }) _dataContainerElem: ElementRef; | ||
@ViewChild('image', { static: false }) _imageElem: ElementRef; | ||
@ViewChild('iframe', { static: false }) _iframeElem: ElementRef; | ||
@ViewChild('caption', { static: false }) _captionElem: ElementRef; | ||
@ViewChild('number', { static: false }) _numberElem: ElementRef; | ||
public content: any; | ||
|
@@ -155,10 +165,10 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
containerRightPadding: Math.round(this._getCssStyleValue(this._containerElem, 'padding-right')), | ||
containerBottomPadding: Math.round(this._getCssStyleValue(this._containerElem, 'padding-bottom')), | ||
containerLeftPadding: Math.round(this._getCssStyleValue(this._containerElem, 'padding-left')), | ||
imageBorderWidthTop: Math.round(this._getCssStyleValue(this._imageElem, 'border-top-width')), | ||
imageBorderWidthBottom: Math.round(this._getCssStyleValue(this._imageElem, 'border-bottom-width')), | ||
imageBorderWidthLeft: Math.round(this._getCssStyleValue(this._imageElem, 'border-left-width')), | ||
imageBorderWidthRight: Math.round(this._getCssStyleValue(this._imageElem, 'border-right-width')) | ||
imageBorderWidthTop: Math.round(this._getCssStyleValue(this._imageElem || this._iframeElem, 'border-top-width')), | ||
imageBorderWidthBottom: Math.round(this._getCssStyleValue(this._imageElem || this._iframeElem, 'border-bottom-width')), | ||
imageBorderWidthLeft: Math.round(this._getCssStyleValue(this._imageElem || this._iframeElem, 'border-left-width')), | ||
imageBorderWidthRight: Math.round(this._getCssStyleValue(this._imageElem || this._iframeElem, 'border-right-width')) | ||
}; | ||
|
||
if (this._validateInputData()) { | ||
|
@@ -246,8 +256,12 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
|
||
private _resetImage(): void { | ||
this.rotate = 0; | ||
this._documentRef.getElementById('image').style.transform = `rotate(${this.rotate}deg)`; | ||
this._documentRef.getElementById('image').style.webkitTransform = `rotate(${this.rotate}deg)`; | ||
const image = this._documentRef.getElementById('image'); | ||
if (image) { | ||
image.style.transform = `rotate(${this.rotate}deg)`; | ||
image.style.webkitTransform = `rotate(${this.rotate}deg)`; | ||
} | ||
|
||
} | ||
|
||
private _calcTransformPoint(): void { | ||
|
@@ -315,13 +329,25 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
} | ||
|
||
private _registerImageLoadingEvent(): void { | ||
const src: any = this.album[this.currentImageIndex].src; | ||
|
||
if (this.album[this.currentImageIndex].iframe || this.needsIframe(src)) { | ||
setTimeout( () => { | ||
this._onLoadImageSuccess(); | ||
}); | ||
return; | ||
} | ||
|
||
const preloader = new Image(); | ||
|
||
preloader.onload = () => { | ||
this._onLoadImageSuccess(); | ||
} | ||
|
||
const src: any = this.album[this.currentImageIndex].src; | ||
preloader.onerror = (e) => { | ||
this._lightboxEvent.broadcastLightboxEvent({ id: LIGHTBOX_EVENT.FILE_NOT_FOUND, data: e }); | ||
} | ||
|
||
preloader.src = this._sanitizer.sanitize(SecurityContext.URL, src); | ||
} | ||
|
||
|
@@ -344,8 +370,8 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
let naturalImageHeight; | ||
|
||
// set default width and height of image to be its natural | ||
imageWidth = naturalImageWidth = this._imageElem.nativeElement.naturalWidth; | ||
imageHeight = naturalImageHeight = this._imageElem.nativeElement.naturalHeight; | ||
imageWidth = naturalImageWidth = this._imageElem ? this._imageElem.nativeElement.naturalWidth : this._windowRef.innerWidth * .8; | ||
imageHeight = naturalImageHeight = this._imageElem ? this._imageElem.nativeElement.naturalHeight : this._windowRef.innerHeight * .8; | ||
if (this.options.fitImageInViewPort) { | ||
windowWidth = this._windowRef.innerWidth; | ||
windowHeight = this._windowRef.innerHeight; | ||
|
@@ -365,8 +391,8 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
} | ||
} | ||
|
||
this._rendererRef.setStyle(this._imageElem.nativeElement, 'width', `${imageWidth}px`); | ||
this._rendererRef.setStyle(this._imageElem.nativeElement, 'height', `${imageHeight}px`); | ||
this._rendererRef.setStyle((this._imageElem || this._iframeElem).nativeElement, 'width', `${imageWidth}px`); | ||
this._rendererRef.setStyle((this._imageElem || this._iframeElem).nativeElement, 'height', `${imageHeight}px`); | ||
} | ||
|
||
this._sizeContainer(imageWidth, imageHeight); | ||
|
@@ -495,9 +521,9 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
'-webkit-animation-duration', `${fadeDuration}s`); | ||
this._rendererRef.setStyle(this._dataContainerElem.nativeElement, | ||
'animation-duration', `${fadeDuration}s`); | ||
this._rendererRef.setStyle(this._imageElem.nativeElement, | ||
this._rendererRef.setStyle((this._imageElem || this._iframeElem).nativeElement, | ||
'-webkit-animation-duration', `${fadeDuration}s`); | ||
this._rendererRef.setStyle(this._imageElem.nativeElement, | ||
this._rendererRef.setStyle((this._imageElem || this._iframeElem).nativeElement, | ||
'animation-duration', `${fadeDuration}s`); | ||
this._rendererRef.setStyle(this._captionElem.nativeElement, | ||
'-webkit-animation-duration', `${fadeDuration}s`); | ||
|
@@ -667,4 +693,13 @@ export class LightboxComponent implements OnInit, AfterViewInit, OnDestroy, OnIn | |
break; | ||
} | ||
} | ||
} | ||
|
||
public needsIframe(src: string) { | ||
// const sanitizedUrl = this._sanitizer.sanitize(SecurityContext.URL, src); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove this line if it is not needed ? |
||
if (src.match(/\.pdf$/)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the iframe options needed ? I dont really understand why it is needed for an image ?