File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed
Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -96,18 +96,18 @@ if (codeExamples.length === 0 && !examplesRequired) {
9696 });
9797 });
9898
99- const hash = window.location.hash;
100- const match = hash.match(/^#example(\d+)$/i);
101- if (match) {
99+ function activateExampleFromHash() {
100+ const hash = window.location.hash;
101+ const match = hash.match(/^#example(\d+)$/i);
102+ if (!match) return;
103+
102104 const tabIndex = String(parseInt(match[1], 10) - 1);
103105 const targetBtn = document.querySelector(`.tab-btn[data-tab="${tabIndex}"]`);
104- if (targetBtn) {
105- activateTab(tabIndex);
106+ const targetContent = document.querySelector(`.tab-content[data-tab="${tabIndex}"]`);
106107
107- const section = document.querySelector('.examples-section');
108- if (section) {
109- section.scrollIntoView({ behavior: 'smooth' });
110- }
108+ if (targetBtn && targetContent) {
109+ activateTab(tabIndex);
110+ targetBtn.scrollIntoView({ behavior: 'smooth' });
111111 }
112112 }
113113
@@ -122,6 +122,9 @@ if (codeExamples.length === 0 && !examplesRequired) {
122122 }
123123 }
124124
125+ activateExampleFromHash();
126+ window.addEventListener('hashchange', activateExampleFromHash);
127+
125128 checkOverflow();
126129 window.addEventListener('resize', checkOverflow);
127130 });
You can’t perform that action at this time.
0 commit comments