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
"python/git@developer.sourcefind.cn:zhaoyu6/sglang.git" did not exist on "65f091310ca63b96384c9fcf24c0c5aa0c1e4f39"
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) {
}
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 present, the handle is where you move the DIV from:
dragEl
.
getElementsByClassName
(
'
drag-handle
'
)[
0
].
onmousedown
=
dragMouseDown
;
...
...
@@ -49,8 +54,8 @@ function dragElement(dragEl) {
e
=
e
||
window
.
event
;
e
.
preventDefault
();
// get the mouse cursor position at startup:
pos
3
=
e
.
clientX
;
pos
4
=
e
.
clientY
;
pos
StartX
=
e
.
clientX
;
pos
StartY
=
e
.
clientY
;
document
.
onmouseup
=
closeDragElement
;
// call a function whenever the cursor moves:
document
.
onmousemove
=
elementDrag
;
...
...
@@ -60,13 +65,15 @@ function dragElement(dragEl) {
e
=
e
||
window
.
event
;
e
.
preventDefault
();
// calculate the new cursor position:
pos1
=
pos3
-
e
.
clientX
;
pos2
=
pos4
-
e
.
clientY
;
pos3
=
e
.
clientX
;
pos4
=
e
.
clientY
;
posDiffX
=
e
.
clientX
-
posStartX
;
posDiffY
=
e
.
clientY
-
posStartY
;
posStartX
=
e
.
clientX
;
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:
dragEl
.
style
.
top
=
(
dragEl
.
offsetTop
-
pos2
)
+
"
px
"
;
dragEl
.
style
.
left
=
(
dragEl
.
offsetLeft
-
pos1
)
+
"
px
"
;
dragEl
.
style
.
top
=
newPosY
+
"
px
"
;
dragEl
.
style
.
left
=
newPosX
+
"
px
"
;
}
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