Skip to content

Commit 8aad378

Browse files
authored
Merge pull request #5 from canalplus/ctrl-keys-click
scripts: make ctrl & alt + click work as expected on site links
2 parents 7addcb5 + 0359bf7 commit 8aad378

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

build/scripts/script.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,22 @@ function initializeSideBarLinks() {
815815
loadSidebarLink(link, { display: false, updateURL: false });
816816
}
817817
function onClick(evt) {
818+
// Let browser handle modified clicks
819+
if (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey) {
820+
return;
821+
}
822+
823+
// Let browser handle non-left clicks (middle click, right click)
824+
if (evt.button !== 0) {
825+
return;
826+
}
827+
828+
// Let browser handle links that open in new windows/tabs
829+
const link = evt.currentTarget;
830+
if (link.target && link.target !== "_self") {
831+
return;
832+
}
833+
818834
evt.preventDefault();
819835
loadSidebarLink(link, { display: true, updateURL: true });
820836
}
@@ -851,6 +867,22 @@ function initializeContentLinks() {
851867
contentLink.removeEventListener("mouseover", onMouseOver);
852868
});
853869
function onClick(evt) {
870+
// Let browser handle modified clicks
871+
if (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey) {
872+
return;
873+
}
874+
875+
// Let browser handle non-left clicks (middle click, right click)
876+
if (evt.button !== 0) {
877+
return;
878+
}
879+
880+
// Let browser handle links that open in new windows/tabs
881+
const link = evt.currentTarget;
882+
if (link.target && link.target !== "_self") {
883+
return;
884+
}
885+
854886
evt.preventDefault();
855887
loadSidebarLink(correspondingElt, {
856888
display: true,

0 commit comments

Comments
 (0)