Skip to content

Commit cbd8c4b

Browse files
Copilotdoxygen
andauthored
Remove jQuery and jQuery UI dependencies from navtree.js (doxygen#11968)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Dimitri van Heesch <[email protected]>
1 parent 6abdb86 commit cbd8c4b

File tree

1 file changed

+86
-37
lines changed

1 file changed

+86
-37
lines changed

templates/html/navtree.js

Lines changed: 86 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,15 @@ function initNavTree(toroot,relpath,allMembersFile) {
336336
const windowHeight = window.innerHeight - headerHeight - footerHeight;
337337
(function retry() { // retry until we can scroll to the selected item
338338
try {
339-
const navtree = jQuery('#nav-tree');
340-
navtree.scrollTo('#selected',100,{offset:-windowHeight/2});
339+
const navtree = $('#nav-tree');
340+
if (navtree) {
341+
const selected = navtree.querySelector('#selected');
342+
if (selected) {
343+
const offset = -windowHeight/2;
344+
const targetPos = selected.offsetTop + offset;
345+
animateScrolling(navtree, Math.max(0, targetPos), 100);
346+
}
347+
}
341348
} catch (err) {
342349
setTimeout(retry, 0);
343350
}
@@ -723,41 +730,88 @@ function initNavTree(toroot,relpath,allMembersFile) {
723730
pagenav = $("#page-nav");
724731
container = $("#container");
725732

726-
// Note: .resizable() is from jQuery UI and would require significant reimplementation
727-
// For now, we keep minimal jQuery usage for this plugin-dependent functionality
728-
jQuery(".side-nav-resizable").resizable({resize: function(e, ui) { resizeWidth(true); } });
729-
jQuery(sidenav).resizable({ minWidth: 0 });
730-
if (pagenav) {
731-
const pagehandle = jQuery("#page-nav-resize-handle");
732-
pagehandle.on('mousedown touchmove', function(e) {
733+
// Native JavaScript implementation for resizable side navigation
734+
const splitbar = $("#splitbar");
735+
if (splitbar) {
736+
// Add the ui-resizable-e class to make the splitbar visible and styled correctly
737+
splitbar.classList.add('ui-resizable-e');
738+
splitbar.style.zIndex = 90;
739+
740+
let isResizing = false;
741+
let startX = 0;
742+
let startWidth = 0;
743+
744+
const startResize = (e) => {
745+
startX = e.clientX ?? e.touches?.[0]?.clientX;
746+
startWidth = sidenav.offsetWidth - barWidth;
733747
document.body.classList.add('resizing');
734-
pagehandle.addClass('dragging');
735-
736-
const mouseMoveHandler = function(e) {
737-
const clientX = e.clientX || (e.touches && e.touches[0].clientX);
738-
let pagenavWidth = container.offsetWidth - clientX + barWidth/2;
739-
const sidenavWidth = sidenav.clientWidth;
740-
const widths = constrainPanelWidths(sidenavWidth,pagenavWidth,false);
741-
container.style.gridTemplateColumns = 'auto '+parseFloat(widths.rightPanelWidth)+'px';
742-
pagenav.style.width = parseFloat(widths.rightPanelWidth-1)+'px';
743-
content.style.marginLeft = parseFloat(widths.leftPanelWidth)+'px';
744-
Cookie.writeSetting(PAGENAV_COOKIE_NAME,pagenavWidth);
748+
document.body.style.cursor = 'col-resize';
749+
750+
const doResize = (e) => {
751+
const clientX = e.clientX ?? e.touches?.[0]?.clientX;
752+
if (clientX === undefined) return;
753+
const delta = clientX - startX;
754+
const newWidth = startWidth + delta;
755+
sidenav.style.width = newWidth + 'px';
756+
resizeWidth(true);
745757
};
746758

747-
const mouseUpHandler = function(e) {
759+
const stopResize = () => {
748760
document.body.classList.remove('resizing');
749-
pagehandle.removeClass('dragging');
750-
document.removeEventListener('mousemove', mouseMoveHandler);
751-
document.removeEventListener('mouseup', mouseUpHandler);
752-
document.removeEventListener('touchmove', mouseMoveHandler);
753-
document.removeEventListener('touchend', mouseUpHandler);
761+
document.body.style.cursor = 'auto';
762+
document.removeEventListener('mousemove', doResize);
763+
document.removeEventListener('touchmove', doResize);
764+
document.removeEventListener('mouseup', stopResize);
765+
document.removeEventListener('touchend', stopResize);
754766
};
755767

756-
document.addEventListener('mousemove', mouseMoveHandler);
757-
document.addEventListener('touchmove', mouseMoveHandler);
758-
document.addEventListener('mouseup', mouseUpHandler);
759-
document.addEventListener('touchend', mouseUpHandler);
760-
});
768+
document.addEventListener('mousemove', doResize);
769+
document.addEventListener('touchmove', doResize);
770+
document.addEventListener('mouseup', stopResize);
771+
document.addEventListener('touchend', stopResize);
772+
};
773+
774+
splitbar.addEventListener('mousedown', startResize);
775+
splitbar.addEventListener('touchstart', startResize, { passive: false });
776+
}
777+
778+
if (pagenav) {
779+
const pagehandle = $("#page-nav-resize-handle");
780+
if (pagehandle) {
781+
const startDrag = (e) => {
782+
document.body.classList.add('resizing');
783+
pagehandle.classList.add('dragging');
784+
785+
const mouseMoveHandler = (e) => {
786+
const clientX = e.clientX ?? e.touches?.[0]?.clientX;
787+
if (clientX === undefined) return;
788+
let pagenavWidth = container.offsetWidth - clientX + barWidth/2;
789+
const sidenavWidth = sidenav.clientWidth;
790+
const widths = constrainPanelWidths(sidenavWidth,pagenavWidth,false);
791+
container.style.gridTemplateColumns = 'auto '+parseFloat(widths.rightPanelWidth)+'px';
792+
pagenav.style.width = parseFloat(widths.rightPanelWidth-1)+'px';
793+
content.style.marginLeft = parseFloat(widths.leftPanelWidth - barWidth)+'px';
794+
Cookie.writeSetting(PAGENAV_COOKIE_NAME,pagenavWidth);
795+
};
796+
797+
const mouseUpHandler = (e) => {
798+
document.body.classList.remove('resizing');
799+
pagehandle.classList.remove('dragging');
800+
document.removeEventListener('mousemove', mouseMoveHandler);
801+
document.removeEventListener('mouseup', mouseUpHandler);
802+
document.removeEventListener('touchmove', mouseMoveHandler);
803+
document.removeEventListener('touchend', mouseUpHandler);
804+
};
805+
806+
document.addEventListener('mousemove', mouseMoveHandler);
807+
document.addEventListener('touchmove', mouseMoveHandler);
808+
document.addEventListener('mouseup', mouseUpHandler);
809+
document.addEventListener('touchend', mouseUpHandler);
810+
};
811+
812+
pagehandle.addEventListener('mousedown', startDrag);
813+
pagehandle.addEventListener('touchstart', startDrag, { passive: false });
814+
}
761815
} else {
762816
container.style.gridTemplateColumns = 'auto';
763817
}
@@ -767,12 +821,7 @@ function initNavTree(toroot,relpath,allMembersFile) {
767821
const url = location.href;
768822
const i=url.indexOf("#");
769823
if (i>=0) window.location.hash=url.substr(i);
770-
const _preventDefault = function(evt) { evt.preventDefault(); };
771-
const splitbar = $("#splitbar");
772-
if (splitbar) {
773-
splitbar.addEventListener("dragstart", _preventDefault);
774-
splitbar.addEventListener("selectstart", _preventDefault);
775-
}
824+
776825

777826
let lastWidth = -1;
778827
let lastHeight = -1;

0 commit comments

Comments
 (0)