From 10f0c6c92d9d371d24c1e38871e14d74345b4006 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 18 Feb 2017 20:19:24 +0100 Subject: [PATCH] dynamically setting position of a submenu --- js/uw.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/js/uw.js b/js/uw.js index 7e0f332..a87ca27 100644 --- a/js/uw.js +++ b/js/uw.js @@ -1943,9 +1943,40 @@ function showMenu(id, sizes){ if(debugmsg){ console.log("uw::showMenu | showing menu with id ", id, "\n\n", document.getElementById(id)); } - document.getElementById(id).classList.add("show"); + + var div = document.getElementById(id); + + console.log("showMenu | asasdas", sizes); + + div.classList.add("show"); + console.log("showMenu | asasdas"); if(sizes){ - //TODO: determine where to put submenu + console.log("uw::showMenu",sizes); + var player_leftmost = sizes.player.left; + console.log("showMenu | asasdassssssssssssssssssssssssssssssss"); + + var parent_leftmost = sizes.parent.left; + var player_rightmost = sizes.player.left + sizes.player.width; + console.log("showMenu | asas421das"); + var parent_rightmost = sizes.parent.left + sizes.parent.width; + + if(debugmsg){ + console.log("uw::showMenu | space on left:", parent_leftmost - player_leftmost, "| space on right:", player_rightmost - parent_rightmost); + } + + // if: + // space left of the parent is bigger than space right of the parent + if( (parent_leftmost - player_leftmost) > (player_rightmost - parent_rightmost) ){ + //player goes to the left side + if(debugmsg){ + console.log("uw::showMenu | setting position on the submenu relative to the parent. left:", -div.getBoundingClientRect().width ) + } + div.style.left = (- div.getBoundingClientRect().width ) + "px"; + } + else{ + alert("this wasn't defined yet. pls do this. ctrl+f rivianpoint"); + div.style.left = sizes.parent.width + "px"; + } } }