Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
48d4edbc
Commit
48d4edbc
authored
Mar 25, 2023
by
Jairo Correa
Browse files
Prevent draggable menu to get outside of window
parent
a5c78a57
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
9 deletions
+16
-9
web/scripts/ui.js
web/scripts/ui.js
+16
-9
No files found.
web/scripts/ui.js
View file @
48d4edbc
...
@@ -36,7 +36,12 @@ function $el(tag, propsOrChildren, children) {
...
@@ -36,7 +36,12 @@ function $el(tag, propsOrChildren, children) {
}
}
function
dragElement
(
dragEl
)
{
function
dragElement
(
dragEl
)
{
var
pos1
=
0
,
pos2
=
0
,
pos3
=
0
,
pos4
=
0
;
var
posDiffX
=
0
,
posDiffY
=
0
,
posStartX
=
0
,
posStartY
=
0
,
newPosX
=
0
,
newPosY
=
0
;
if
(
dragEl
.
getElementsByClassName
(
'
drag-handle
'
)[
0
])
{
if
(
dragEl
.
getElementsByClassName
(
'
drag-handle
'
)[
0
])
{
// if present, the handle is where you move the DIV from:
// if present, the handle is where you move the DIV from:
dragEl
.
getElementsByClassName
(
'
drag-handle
'
)[
0
].
onmousedown
=
dragMouseDown
;
dragEl
.
getElementsByClassName
(
'
drag-handle
'
)[
0
].
onmousedown
=
dragMouseDown
;
...
@@ -49,8 +54,8 @@ function dragElement(dragEl) {
...
@@ -49,8 +54,8 @@ function dragElement(dragEl) {
e
=
e
||
window
.
event
;
e
=
e
||
window
.
event
;
e
.
preventDefault
();
e
.
preventDefault
();
// get the mouse cursor position at startup:
// get the mouse cursor position at startup:
pos
3
=
e
.
clientX
;
pos
StartX
=
e
.
clientX
;
pos
4
=
e
.
clientY
;
pos
StartY
=
e
.
clientY
;
document
.
onmouseup
=
closeDragElement
;
document
.
onmouseup
=
closeDragElement
;
// call a function whenever the cursor moves:
// call a function whenever the cursor moves:
document
.
onmousemove
=
elementDrag
;
document
.
onmousemove
=
elementDrag
;
...
@@ -60,13 +65,15 @@ function dragElement(dragEl) {
...
@@ -60,13 +65,15 @@ function dragElement(dragEl) {
e
=
e
||
window
.
event
;
e
=
e
||
window
.
event
;
e
.
preventDefault
();
e
.
preventDefault
();
// calculate the new cursor position:
// calculate the new cursor position:
pos1
=
pos3
-
e
.
clientX
;
posDiffX
=
e
.
clientX
-
posStartX
;
pos2
=
pos4
-
e
.
clientY
;
posDiffY
=
e
.
clientY
-
posStartY
;
pos3
=
e
.
clientX
;
posStartX
=
e
.
clientX
;
pos4
=
e
.
clientY
;
posStartY
=
e
.
clientY
;
newPosX
=
Math
.
min
((
document
.
body
.
clientWidth
-
dragEl
.
clientWidth
),
Math
.
max
(
0
,
(
dragEl
.
offsetLeft
+
posDiffX
)));
newPosY
=
Math
.
min
((
document
.
body
.
clientHeight
-
dragEl
.
clientHeight
),
Math
.
max
(
0
,
(
dragEl
.
offsetTop
+
posDiffY
)));
// set the element's new position:
// set the element's new position:
dragEl
.
style
.
top
=
(
dragEl
.
offsetTop
-
pos2
)
+
"
px
"
;
dragEl
.
style
.
top
=
newPosY
+
"
px
"
;
dragEl
.
style
.
left
=
(
dragEl
.
offsetLeft
-
pos1
)
+
"
px
"
;
dragEl
.
style
.
left
=
newPosX
+
"
px
"
;
}
}
function
closeDragElement
()
{
function
closeDragElement
()
{
...
...
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