Skip to content

Commit

Permalink
allow references pane to be resized (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra authored Aug 31, 2023
1 parent 6ecb8bc commit b9e720f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
5 changes: 4 additions & 1 deletion css/elements.css
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ tr.del > td {
flex-grow: 0;
flex-shrink: 0;
font-size: 80%;
cursor: row-resize;
user-select: none;
}

.menu-pane-header emu-opt,
Expand Down Expand Up @@ -1245,7 +1247,6 @@ li.menu-search-result-term:before {
bottom: 0;
left: 0;
right: 0;
height: 250px;
display: none;
background-color: #ddd;
z-index: 1;
Expand All @@ -1254,6 +1255,8 @@ li.menu-search-result-term:before {
#references-pane-table-container {
overflow-x: hidden;
overflow-y: auto;
min-height: 35px;
max-height: 85vh;
}

#references-pane {
Expand Down
41 changes: 37 additions & 4 deletions js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,10 @@ let referencePane = {
this.$header.appendChild(this.$headerText);
this.$headerRefId = document.createElement('a');
this.$header.appendChild(this.$headerRefId);
this.$header.addEventListener('pointerdown', e => {
this.dragStart(e);
});

this.$closeButton = document.createElement('span');
this.$closeButton.setAttribute('id', 'references-pane-close');
this.$closeButton.addEventListener('click', () => {
Expand All @@ -731,16 +735,16 @@ let referencePane = {
this.$header.appendChild(this.$closeButton);

this.$pane.appendChild(this.$header);
let tableContainer = document.createElement('div');
tableContainer.setAttribute('id', 'references-pane-table-container');
this.$tableContainer = document.createElement('div');
this.$tableContainer.setAttribute('id', 'references-pane-table-container');

this.$table = document.createElement('table');
this.$table.setAttribute('id', 'references-pane-table');

this.$tableBody = this.$table.createTBody();

tableContainer.appendChild(this.$table);
this.$pane.appendChild(tableContainer);
this.$tableContainer.appendChild(this.$table);
this.$pane.appendChild(this.$tableContainer);

menu.$specContainer.appendChild(this.$container);
},
Expand Down Expand Up @@ -793,6 +797,7 @@ let referencePane = {
this.$table.removeChild(this.$tableBody);
this.$tableBody = newBody;
this.$table.appendChild(this.$tableBody);
this.autoSize();
},

showSDOs(sdos, alternativeId) {
Expand Down Expand Up @@ -839,6 +844,34 @@ let referencePane = {
this.$table.removeChild(this.$tableBody);
this.$tableBody = newBody;
this.$table.appendChild(this.$tableBody);
this.autoSize();
},

autoSize() {
this.$tableContainer.style.height =
Math.min(250, this.$table.getBoundingClientRect().height) + 'px';
},

dragStart(pointerDownEvent) {
let startingMousePos = pointerDownEvent.clientY;
let startingHeight = this.$tableContainer.getBoundingClientRect().height;
let moveListener = pointerMoveEvent => {
if (pointerMoveEvent.buttons === 0) {
removeListeners();
return;
}
let desiredHeight = startingHeight - (pointerMoveEvent.clientY - startingMousePos);
this.$tableContainer.style.height = Math.max(0, desiredHeight) + 'px';
};
let listenerOptions = { capture: true, passive: true };
let removeListeners = () => {
document.removeEventListener('pointermove', moveListener, listenerOptions);
this.$header.removeEventListener('pointerup', removeListeners, listenerOptions);
this.$header.removeEventListener('pointercancel', removeListeners, listenerOptions);
};
document.addEventListener('pointermove', moveListener, listenerOptions);
this.$header.addEventListener('pointerup', removeListeners, listenerOptions);
this.$header.addEventListener('pointercancel', removeListeners, listenerOptions);
},
};

Expand Down

0 comments on commit b9e720f

Please sign in to comment.