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
8fd20bd4
Commit
8fd20bd4
authored
Jun 05, 2023
by
Aarni Koskela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Zoom and Pan: move helpers into its namespace to avoid littering global scope
parent
9781f31f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
97 deletions
+95
-97
extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
+95
-97
No files found.
extensions-builtin/canvas-zoom-and-pan/javascript/zoom.js
View file @
8fd20bd4
// Helper functions
onUiLoaded
(
async
()
=>
{
// Get active tab
// Helper functions
function
getActiveTab
(
elements
,
all
=
false
)
{
// Get active tab
function
getActiveTab
(
elements
,
all
=
false
)
{
const
tabs
=
elements
.
img2imgTabs
.
querySelectorAll
(
"
button
"
);
const
tabs
=
elements
.
img2imgTabs
.
querySelectorAll
(
"
button
"
);
if
(
all
)
return
tabs
;
if
(
all
)
return
tabs
;
...
@@ -10,10 +11,10 @@ function getActiveTab(elements, all = false) {
...
@@ -10,10 +11,10 @@ function getActiveTab(elements, all = false) {
return
tab
;
return
tab
;
}
}
}
}
}
}
// Get tab ID
// Get tab ID
function
getTabId
(
elements
,
elementIDs
)
{
function
getTabId
(
elements
,
elementIDs
)
{
const
activeTab
=
getActiveTab
(
elements
);
const
activeTab
=
getActiveTab
(
elements
);
const
tabIdLookup
=
{
const
tabIdLookup
=
{
"
Sketch
"
:
elementIDs
.
sketch
,
"
Sketch
"
:
elementIDs
.
sketch
,
...
@@ -21,10 +22,10 @@ function getTabId(elements, elementIDs) {
...
@@ -21,10 +22,10 @@ function getTabId(elements, elementIDs) {
"
Inpaint
"
:
elementIDs
.
inpaint
"
Inpaint
"
:
elementIDs
.
inpaint
};
};
return
tabIdLookup
[
activeTab
.
innerText
];
return
tabIdLookup
[
activeTab
.
innerText
];
}
}
// Wait until opts loaded
// Wait until opts loaded
async
function
waitForOpts
()
{
async
function
waitForOpts
()
{
return
new
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
const
checkInterval
=
setInterval
(()
=>
{
const
checkInterval
=
setInterval
(()
=>
{
if
(
window
.
opts
&&
Object
.
keys
(
window
.
opts
).
length
!==
0
)
{
if
(
window
.
opts
&&
Object
.
keys
(
window
.
opts
).
length
!==
0
)
{
...
@@ -33,17 +34,17 @@ async function waitForOpts() {
...
@@ -33,17 +34,17 @@ async function waitForOpts() {
}
}
},
100
);
},
100
);
});
});
}
}
// Check is hotkey valid
// Check is hotkey valid
function
isSingleLetter
(
value
)
{
function
isSingleLetter
(
value
)
{
return
(
return
(
typeof
value
===
"
string
"
&&
value
.
length
===
1
&&
/
[
a-z
]
/i
.
test
(
value
)
typeof
value
===
"
string
"
&&
value
.
length
===
1
&&
/
[
a-z
]
/i
.
test
(
value
)
);
);
}
}
// Create hotkeyConfig from opts
// Create hotkeyConfig from opts
function
createHotkeyConfig
(
defaultHotkeysConfig
,
hotkeysConfigOpts
)
{
function
createHotkeyConfig
(
defaultHotkeysConfig
,
hotkeysConfigOpts
)
{
const
result
=
{};
const
result
=
{};
const
usedKeys
=
new
Set
();
const
usedKeys
=
new
Set
();
...
@@ -70,17 +71,16 @@ function createHotkeyConfig(defaultHotkeysConfig, hotkeysConfigOpts) {
...
@@ -70,17 +71,16 @@ function createHotkeyConfig(defaultHotkeysConfig, hotkeysConfigOpts) {
}
}
return
result
;
return
result
;
}
}
/**
/**
* The restoreImgRedMask function displays a red mask around an image to indicate the aspect ratio.
* The restoreImgRedMask function displays a red mask around an image to indicate the aspect ratio.
* If the image display property is set to 'none', the mask breaks. To fix this, the function
* If the image display property is set to 'none', the mask breaks. To fix this, the function
* temporarily sets the display property to 'block' and then hides the mask again after 300 milliseconds
* temporarily sets the display property to 'block' and then hides the mask again after 300 milliseconds
* to avoid breaking the canvas. Additionally, the function adjusts the mask to work correctly on
* to avoid breaking the canvas. Additionally, the function adjusts the mask to work correctly on
* very long images.
* very long images.
*/
*/
function
restoreImgRedMask
(
elements
,
elementIDs
)
{
function
restoreImgRedMask
(
elements
,
elementIDs
)
{
const
mainTabId
=
getTabId
(
elements
,
elementIDs
);
const
mainTabId
=
getTabId
(
elements
,
elementIDs
);
if
(
!
mainTabId
)
return
;
if
(
!
mainTabId
)
return
;
...
@@ -112,10 +112,8 @@ function restoreImgRedMask(elements, elementIDs) {
...
@@ -112,10 +112,8 @@ function restoreImgRedMask(elements, elementIDs) {
setTimeout
(()
=>
{
setTimeout
(()
=>
{
img
.
style
.
display
=
"
none
"
;
img
.
style
.
display
=
"
none
"
;
},
400
);
},
400
);
}
}
// Main
onUiLoaded
(
async
()
=>
{
const
hotkeysConfigOpts
=
await
waitForOpts
();
const
hotkeysConfigOpts
=
await
waitForOpts
();
// Default config
// Default config
...
...
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