Skip to content

Commit

Permalink
Automatically adjustu topmenu alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
kezsulap committed Nov 21, 2024
1 parent d56382a commit 3a23f79
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions resources/bridge-bidding-styl-v13.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ table {
td {
font-size: 1em;
}
#topmenulist {
display: grid;
}
.bidding {
padding-left: 0.4em;
border-radius: 5px;
Expand Down Expand Up @@ -117,10 +120,8 @@ ul.topmenu li {
margin: 2px;
padding: 0;
border-radius: 5px;
min-width: 50px;
height: 1.25em;
text-align: center;
width: min-content;
}
a.topmenu {
display: block;
Expand Down
2 changes: 2 additions & 0 deletions resources/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function init() {
catch (e) {
display_error(e);
}
align_topmenu();
addEventListener("resize", (event) => {align_topmenu()});
})
}
init();
18 changes: 18 additions & 0 deletions resources/parse-v13.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,3 +1006,21 @@ function get_versions() {
if (owner === undefined) {owner = 'kezsulap', repo = 'SSO_MAX_CC'} //Uncomment for local testing of web related features
return [owner, repo, params_list]
}
function doesOverflowVertically(el) {
let curOverflow = el.style.overflow;
if (!curOverflow || curOverflow === "visible")
el.style.overflow = "hidden";
let isOverflowing = el.clientWidth < el.scrollWidth;
el.style.overflow = curOverflow;
return isOverflowing;
}
function align_topmenu() {
let topmenu = document.querySelector('#topmenulist');
let all_answers = topmenu.children;
for (let i = all_answers.length; i >= 1; --i) {
document.querySelector('#topmenulist').style.gridTemplateColumns = 'repeat(' + i + ', ' + (100 / i - 0.00001) + '%)';
let any_overflow = false;
for (let x of all_answers) if (doesOverflowVertically(x)) any_overflow = true;
if (!any_overflow) break;
}
}

0 comments on commit 3a23f79

Please sign in to comment.