Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
9e69009d
Commit
9e69009d
authored
May 28, 2023
by
Danil Boldyrev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve reset zoom when toggle tabs
parent
433c70b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
1 deletion
+34
-1
javascript/zoom.js
javascript/zoom.js
+34
-1
No files found.
javascript/zoom.js
View file @
9e69009d
// Main
// Helper functions
// Get active tab
function
getActiveTab
(
elements
,
all
=
false
)
{
const
tabs
=
elements
.
img2imgTabs
.
querySelectorAll
(
"
button
"
);
if
(
all
)
return
tabs
;
for
(
let
tab
of
tabs
)
{
if
(
tab
.
classList
.
contains
(
"
selected
"
))
{
return
tab
;
}
}
}
onUiLoaded
(
async
()
=>
{
const
hotkeysConfig
=
{
resetZoom
:
"
KeyR
"
,
...
...
@@ -33,12 +48,27 @@ onUiLoaded(async () => {
let
[
zoomLevel
,
panX
,
panY
]
=
[
1
,
0
,
0
];
let
fullScreenMode
=
false
;
// In the course of research, it was found that the tag img is very harmful when zooming and creates white canvases. This hack allows you to almost never think about this problem, it has no effect on webui.
function
fixCanvas
()
{
const
activeTab
=
getActiveTab
(
elements
).
textContent
.
trim
();
if
(
activeTab
!==
"
img2img
"
)
{
const
img
=
targetElement
.
querySelector
(
`
${
elemId
}
img`
);
if
(
img
&&
img
.
style
.
display
!==
"
none
"
)
{
img
.
style
.
display
=
"
none
"
;
img
.
style
.
visibility
=
"
hidden
"
;
}
}
}
// Reset the zoom level and pan position of the target element to their initial values
function
resetZoom
()
{
zoomLevel
=
1
;
panX
=
0
;
panY
=
0
;
fixCanvas
();
targetElement
.
style
.
transform
=
`scale(
${
zoomLevel
}
) translate(
${
panX
}
px,
${
panY
}
px)`
;
const
canvas
=
document
.
querySelector
(
...
...
@@ -318,7 +348,10 @@ onUiLoaded(async () => {
// Reset zoom when click on another tab
elements
.
img2imgTabs
.
addEventListener
(
"
click
"
,
resetZoom
);
elements
.
img2imgTabs
.
addEventListener
(
"
click
"
,
()
=>
{
targetElement
.
style
.
width
=
""
;
// targetElement.style.width = "";
if
(
parseInt
(
targetElement
.
style
.
width
)
>
865
)
{
setTimeout
(
fitToElement
,
0
);
}
});
targetElement
.
addEventListener
(
"
wheel
"
,
(
e
)
=>
{
...
...
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