Force Menus to stay on screen
This commit is contained in:
parent
ac939e5fb6
commit
d01e3d57a2
4 changed files with 29 additions and 1 deletions
|
@ -47,6 +47,7 @@ class Contextmenu {
|
||||||
div.style.top = y + 'px';
|
div.style.top = y + 'px';
|
||||||
div.style.left = x + 'px';
|
div.style.left = x + 'px';
|
||||||
document.body.appendChild(div);
|
document.body.appendChild(div);
|
||||||
|
Contextmenu.keepOnScreen(div);
|
||||||
console.log(div);
|
console.log(div);
|
||||||
Contextmenu.currentmenu = div;
|
Contextmenu.currentmenu = div;
|
||||||
return this.div;
|
return this.div;
|
||||||
|
@ -61,6 +62,18 @@ class Contextmenu {
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
static keepOnScreen(obj) {
|
static keepOnScreen(obj) {
|
||||||
|
const html = document.documentElement.getBoundingClientRect();
|
||||||
|
const docheight = html.height;
|
||||||
|
const docwidth = html.width;
|
||||||
|
const box = obj.getBoundingClientRect();
|
||||||
|
console.log(box, docheight, docwidth);
|
||||||
|
if (box.right > docwidth) {
|
||||||
|
console.log("test");
|
||||||
|
obj.style.left = docwidth - box.width + 'px';
|
||||||
|
}
|
||||||
|
if (box.bottom > docheight) {
|
||||||
|
obj.style.top = docheight - box.height + 'px';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Contextmenu.setup();
|
Contextmenu.setup();
|
||||||
|
|
|
@ -126,6 +126,7 @@ class User {
|
||||||
if (x !== -1) {
|
if (x !== -1) {
|
||||||
Contextmenu.currentmenu = div;
|
Contextmenu.currentmenu = div;
|
||||||
document.body.appendChild(div);
|
document.body.appendChild(div);
|
||||||
|
Contextmenu.keepOnScreen(div);
|
||||||
}
|
}
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Contextmenu{
|
||||||
div.style.top = y+'px';
|
div.style.top = y+'px';
|
||||||
div.style.left = x+'px';
|
div.style.left = x+'px';
|
||||||
document.body.appendChild(div);
|
document.body.appendChild(div);
|
||||||
|
Contextmenu.keepOnScreen(div);
|
||||||
console.log(div)
|
console.log(div)
|
||||||
Contextmenu.currentmenu=div;
|
Contextmenu.currentmenu=div;
|
||||||
return this.div;
|
return this.div;
|
||||||
|
@ -59,7 +60,18 @@ class Contextmenu{
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
static keepOnScreen(obj:HTMLElement){
|
static keepOnScreen(obj:HTMLElement){
|
||||||
|
const html = document.documentElement.getBoundingClientRect();
|
||||||
|
const docheight=html.height
|
||||||
|
const docwidth=html.width
|
||||||
|
const box=obj.getBoundingClientRect();
|
||||||
|
console.log(box,docheight,docwidth);
|
||||||
|
if(box.right>docwidth){
|
||||||
|
console.log("test")
|
||||||
|
obj.style.left = docwidth-box.width+'px';
|
||||||
|
}
|
||||||
|
if(box.bottom>docheight){
|
||||||
|
obj.style.top = docheight-box.height+'px';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Contextmenu.setup();
|
Contextmenu.setup();
|
||||||
|
|
|
@ -125,9 +125,11 @@ class User{
|
||||||
userbody.appendChild(biohtml);
|
userbody.appendChild(biohtml);
|
||||||
}
|
}
|
||||||
console.log(div);
|
console.log(div);
|
||||||
|
|
||||||
if(x!==-1){
|
if(x!==-1){
|
||||||
Contextmenu.currentmenu=div;
|
Contextmenu.currentmenu=div;
|
||||||
document.body.appendChild(div)
|
document.body.appendChild(div)
|
||||||
|
Contextmenu.keepOnScreen(div);
|
||||||
}
|
}
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue