Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
web-ui
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WEBGDE-Components
web-ui
Commits
da4b5379
Commit
da4b5379
authored
Jan 04, 2024
by
Owen Ryan Ang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fit content changes, zoom level limit
parent
ecc0aad1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
14 deletions
+67
-14
imageViewer.css
...ets/ImageViewerWidget/modules/imageViewer/imageViewer.css
+4
-0
imageViewer.js
...gets/ImageViewerWidget/modules/imageViewer/imageViewer.js
+63
-14
No files found.
WebGde/WebContent/WebGde-Widgets/ImageViewerWidget/modules/imageViewer/imageViewer.css
View file @
da4b5379
...
@@ -125,6 +125,10 @@ div.fit-content{
...
@@ -125,6 +125,10 @@ div.fit-content{
object-fit
:
cover
;
object-fit
:
cover
;
margin
:
auto
;
margin
:
auto
;
}
}
div
.fit-content
img
{
height
:
100%
;
width
:
100%
;
}
canvas
.fit-content
{
canvas
.fit-content
{
max-height
:
100%
;
max-height
:
100%
;
max-width
:
100%
;
max-width
:
100%
;
...
...
WebGde/WebContent/WebGde-Widgets/ImageViewerWidget/modules/imageViewer/imageViewer.js
View file @
da4b5379
...
@@ -38,6 +38,7 @@ export class ImageViewer {
...
@@ -38,6 +38,7 @@ export class ImageViewer {
constructor
(
imageContainerID
)
{
constructor
(
imageContainerID
)
{
this
.
imageContainerID
=
imageContainerID
;
this
.
imageContainerID
=
imageContainerID
;
this
.
scale
=
1.0
;
}
}
async
init
()
{
async
init
()
{
...
@@ -188,6 +189,8 @@ export class ImageViewer {
...
@@ -188,6 +189,8 @@ export class ImageViewer {
}
}
}
}
this
.
resetImage
();
}
}
displayCurrentImageFileName
(
imageName
)
{
displayCurrentImageFileName
(
imageName
)
{
...
@@ -299,11 +302,20 @@ export class ImageViewer {
...
@@ -299,11 +302,20 @@ export class ImageViewer {
fitContentBtn
.
setAttribute
(
"id"
,
"fitContentBtn"
);
fitContentBtn
.
setAttribute
(
"id"
,
"fitContentBtn"
);
fitContentBtn
.
setAttribute
(
"title"
,
"Fit-Content"
);
fitContentBtn
.
setAttribute
(
"title"
,
"Fit-Content"
);
fitContentBtn
.
addEventListener
(
"click"
,
function
()
{
fitContentBtn
.
addEventListener
(
"click"
,
function
()
{
// get current image element
let
currentImage
=
document
.
getElementById
(
_this
.
currentImageID
);
let
fitContentClasslist
=
document
.
getElementById
(
_this
.
currentImageID
).
classList
;
let
fitContentClasslist
=
document
.
getElementById
(
_this
.
currentImageID
).
classList
;
if
(
!
fitContentClasslist
.
contains
(
"fit-content"
))
{
if
(
!
fitContentClasslist
.
contains
(
"fit-content"
))
{
sessionStorage
.
setItem
(
'currentZoom'
,
currentImage
.
style
.
zoom
);
currentImage
.
style
.
zoom
=
""
;
fitContentClasslist
.
add
(
"fit-content"
);
fitContentClasslist
.
add
(
"fit-content"
);
document
.
getElementById
(
"zoomDetails"
).
textContent
=
"Fit Content"
_this
.
imageMainContainerElement
.
classList
.
add
(
"fit-container"
);
_this
.
imageMainContainerElement
.
classList
.
add
(
"fit-container"
);
}
else
{
}
else
{
currentImage
.
style
.
zoom
=
sessionStorage
.
getItem
(
'currentZoom'
);
document
.
getElementById
(
"zoomDetails"
).
textContent
=
"Zoom: "
+
Math
.
trunc
(
sessionStorage
.
getItem
(
'currentZoom'
)
*
100
)
+
"%"
;
fitContentClasslist
.
remove
(
"fit-content"
);
fitContentClasslist
.
remove
(
"fit-content"
);
_this
.
imageMainContainerElement
.
classList
.
remove
(
"fit-container"
);
_this
.
imageMainContainerElement
.
classList
.
remove
(
"fit-container"
);
}
}
...
@@ -398,18 +410,19 @@ export class ImageViewer {
...
@@ -398,18 +410,19 @@ export class ImageViewer {
}
}
}
}
let
scale
=
1.0
;
let
zoomInBtn
=
document
.
createElement
(
"button"
);
let
zoomInBtn
=
document
.
createElement
(
"button"
);
zoomInBtn
.
setAttribute
(
"class"
,
"button image-btn-control"
)
zoomInBtn
.
setAttribute
(
"class"
,
"button image-btn-control"
)
zoomInBtn
.
setAttribute
(
"id"
,
"zoomInBtn"
);
zoomInBtn
.
setAttribute
(
"id"
,
"zoomInBtn"
);
zoomInBtn
.
setAttribute
(
"title"
,
"Zoom In"
)
zoomInBtn
.
setAttribute
(
"title"
,
"Zoom In"
)
zoomInBtn
.
addEventListener
(
'click'
,
function
()
{
zoomInBtn
.
addEventListener
(
'click'
,
function
()
{
if
(
scale
<
2
)
{
if
(
_this
.
scale
<
2
)
{
scale
+=
0.10
;
_this
.
scale
+=
0.10
;
console
.
log
(
scale
);
console
.
log
(
_this
.
scale
);
}
}
const
container
=
document
.
getElementById
(
_this
.
currentImageID
);
const
container
=
document
.
getElementById
(
_this
.
currentImageID
);
if
(
container
.
classList
.
contains
(
'fit-content'
)){
container
.
classList
.
remove
(
'fit-content'
)
}
if
(
container
.
getAttribute
(
"file-type"
)
!==
"pdf"
)
{
if
(
container
.
getAttribute
(
"file-type"
)
!==
"pdf"
)
{
container
.
childNodes
.
forEach
(
element
=>
{
container
.
childNodes
.
forEach
(
element
=>
{
element
.
classList
.
remove
(
"image"
);
element
.
classList
.
remove
(
"image"
);
...
@@ -421,14 +434,14 @@ export class ImageViewer {
...
@@ -421,14 +434,14 @@ export class ImageViewer {
}
}
});
});
}
}
container
.
style
.
zoom
=
scale
;
container
.
style
.
zoom
=
_this
.
scale
;
document
.
getElementById
(
"zoomDetails"
).
textContent
=
"Zoom: "
+
Math
.
trunc
(
scale
*
100
)
+
"%"
;
document
.
getElementById
(
"zoomDetails"
).
textContent
=
"Zoom: "
+
Math
.
trunc
(
_this
.
scale
*
100
)
+
"%"
;
//container.style.transform = "scale(" + scale + ")";
//container.style.transform = "scale(" + scale + ")";
//container.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
//container.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
let
highlight
=
document
.
getElementById
(
_this
.
highLightCanvasID
);
let
highlight
=
document
.
getElementById
(
_this
.
highLightCanvasID
);
if
(
highlight
)
{
if
(
highlight
)
{
highlight
.
style
.
zoom
=
scale
;
highlight
.
style
.
zoom
=
_this
.
scale
;
//highlight.style.transform = "scale(" + scale + ")";
//highlight.style.transform = "scale(" + scale + ")";
// highlight.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
// highlight.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
...
@@ -441,19 +454,22 @@ export class ImageViewer {
...
@@ -441,19 +454,22 @@ export class ImageViewer {
zoomOutBtn
.
setAttribute
(
"id"
,
"zoomOutBtn"
);
zoomOutBtn
.
setAttribute
(
"id"
,
"zoomOutBtn"
);
zoomOutBtn
.
setAttribute
(
"title"
,
"Zoom Out"
)
zoomOutBtn
.
setAttribute
(
"title"
,
"Zoom Out"
)
zoomOutBtn
.
addEventListener
(
'click'
,
function
()
{
zoomOutBtn
.
addEventListener
(
'click'
,
function
()
{
if
(
scale
>
0
)
{
if
(
_this
.
scale
>
0.2
)
{
scale
-=
0.10
;
_this
.
scale
-=
0.10
;
console
.
log
(
scale
);
console
.
log
(
_this
.
scale
);
}
}
const
container
=
document
.
getElementById
(
_this
.
currentImageID
);
const
container
=
document
.
getElementById
(
_this
.
currentImageID
);
container
.
style
.
zoom
=
scale
;
if
(
container
.
classList
.
contains
(
'fit-content'
)){
document
.
getElementById
(
"zoomDetails"
).
textContent
=
"Zoom: "
+
Math
.
trunc
(
scale
*
100
)
+
"%"
;
container
.
classList
.
remove
(
'fit-content'
)
}
container
.
style
.
zoom
=
_this
.
scale
;
document
.
getElementById
(
"zoomDetails"
).
textContent
=
"Zoom: "
+
Math
.
trunc
(
_this
.
scale
*
100
)
+
"%"
;
//container.style.transform = "scale(" + scale + ")";
//container.style.transform = "scale(" + scale + ")";
//container.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
//container.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
let
highlight
=
document
.
getElementById
(
_this
.
highLightCanvasID
);
let
highlight
=
document
.
getElementById
(
_this
.
highLightCanvasID
);
if
(
highlight
)
{
if
(
highlight
)
{
highlight
.
style
.
zoom
=
scale
;
highlight
.
style
.
zoom
=
_this
.
scale
;
//highlight.style.transform = "scale(" + scale + ")";
//highlight.style.transform = "scale(" + scale + ")";
//highlight.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
//highlight.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
}
}
...
@@ -589,4 +605,36 @@ export class ImageViewer {
...
@@ -589,4 +605,36 @@ export class ImageViewer {
}
}
resetImage
(){
this
.
scale
=
1
;
const
container
=
document
.
getElementById
(
this
.
currentImageID
);
if
(
container
.
getAttribute
(
"file-type"
)
!==
"pdf"
)
{
container
.
childNodes
.
forEach
(
element
=>
{
element
.
classList
.
remove
(
"image"
);
});
}
else
{
container
.
childNodes
.
forEach
(
element
=>
{
if
(
!
element
.
classList
.
includes
(
"image"
))
{
element
.
classList
.
add
(
"image"
);
}
});
}
if
(
container
.
classList
.
contains
(
'fit-content'
)){
container
.
classList
.
remove
(
'fit-content'
)
}
container
.
style
.
zoom
=
this
.
scale
;
document
.
getElementById
(
"zoomDetails"
).
textContent
=
"Zoom: "
+
Math
.
trunc
(
this
.
scale
*
100
)
+
"%"
;
//container.style.transform = "scale(" + scale + ")";
//container.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
let
highlight
=
document
.
getElementById
(
this
.
highLightCanvasID
);
if
(
highlight
)
{
highlight
.
style
.
zoom
=
this
.
scale
;
//highlight.style.transform = "scale(" + scale + ")";
// highlight.style.transformOrigin = (scale * 100) + "% " + (scale * 100) + "%";
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment