Skip to content

Commit 943b2dd

Browse files
committed
Copy the src JS and CSS to documentation _static
1 parent 35ac662 commit 943b2dd

2 files changed

Lines changed: 99 additions & 23 deletions

File tree

docs/_static/sphinxcontrib-httpexample.css

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77
}
88
.http-example .caption.selected {
99
font-weight: bold;
10-
background-color: #fff;
10+
background-color: transparent;
1111
border: 1px solid #e1e4e5;
1212
border-bottom: 1px solid white;
1313
}
1414
.http-example div[class^='highlight'] {
1515
margin-top: -1px;
1616
}
1717
.http-example div[class^='highlight'] pre {
18-
white-space: normal;
18+
white-space: break-spaces;
19+
}
20+
.http-example div.highlight-bash pre {
21+
white-space: pre-wrap;
1922
}
2023
.http-example-JavaScript div[class^='highlight'] pre,
2124
.http-example-http div[class^='highlight'] pre,
2225
.http-example-response div[class^='highlight'] pre {
2326
white-space: pre;
2427
}
25-
Lines changed: 94 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,99 @@
1-
(function() {
2-
var jQuery = window.jQuery || function() {};
3-
4-
jQuery(function($) {
5-
$('.http-example.container').each(function() {
6-
var $container = $(this),
7-
$blocks = $(this).children(),
8-
$captions = $(this).find('.caption');
9-
$captions.each(function() {
10-
var $block = $(this).parent();
11-
$(this).on('click', function() {
12-
$captions.removeClass('selected');
13-
$(this).addClass('selected');
14-
$blocks.hide();
15-
$block.show();
1+
document.addEventListener("DOMContentLoaded", function() {
2+
// Select all elements with the class 'http-example container'
3+
var containers = document.querySelectorAll('.http-example.container');
4+
containers.forEach(function(container) {
5+
6+
// Get all child elements
7+
var blocks = Array.from(container.children);
8+
9+
// Find caption elements or derive them from elements with the 'caption-text' class
10+
var captions = container.querySelectorAll('.caption');
11+
if (captions.length === 0) {
12+
captions = container.querySelectorAll('.caption-text');
13+
captions.forEach(function(caption) {
14+
caption.classList.add('caption');
15+
});
16+
} else {
17+
captions = Array.from(captions);
18+
}
19+
20+
// Process each caption element
21+
captions.forEach(function(caption, index) {
22+
var orphan, block = !!caption.parentElement.id ? caption.parentElement : caption.parentElement.parentElement;
23+
block.setAttribute('role', 'tabpanel');
24+
block.setAttribute('tabindex', '0');
25+
block.setAttribute('aria-labelledby', block.id + '-label');
26+
27+
caption.id = block.id + '-label';
28+
caption.setAttribute('role', 'tab');
29+
caption.setAttribute('tabindex', '0');
30+
caption.setAttribute('aria-label', caption.textContent.trim());
31+
caption.setAttribute('aria-controls', block.id);
32+
33+
// Click event for captions
34+
caption.addEventListener('click', function() {
35+
captions.forEach(function(otherCaption) {
36+
if (caption === otherCaption) {
37+
// Select the clicked caption
38+
caption.setAttribute('aria-selected', 'true');
39+
caption.classList.add('selected');
40+
otherCaption.setAttribute('tabindex', '0');
41+
} else {
42+
// Deselect other captions
43+
otherCaption.setAttribute('aria-selected', 'false');
44+
otherCaption.setAttribute('tabindex', '-1');
45+
otherCaption.classList.remove('selected');
46+
}
47+
});
48+
49+
// Hide other blocks and show the selected one
50+
blocks.forEach(function(otherBlock) {
51+
if (otherBlock !== block) {
52+
otherBlock.style.display = 'none';
53+
otherBlock.setAttribute('hidden', 'hidden');
54+
}
1655
});
17-
$container.append($(this));
56+
block.style.display = '';
57+
block.removeAttribute('hidden');
1858
});
19-
$container.append($blocks);
20-
$captions.first().click();
59+
60+
// Keydown event for accessibility
61+
caption.addEventListener('keydown', function(event) {
62+
if (event.code === 'Space' || event.code === 'Enter') {
63+
caption.click();
64+
} else if (event.code === 'ArrowRight') {
65+
// Move focus to the next tab
66+
var nextIndex = (index + 1) % captions.length;
67+
captions[nextIndex].focus();
68+
captions[nextIndex].click();
69+
} else if (event.code === 'ArrowLeft') {
70+
// Move focus to the previous tab
71+
var prevIndex = (index - 1 + captions.length) % captions.length;
72+
captions[prevIndex].focus();
73+
captions[prevIndex].click();
74+
}
75+
});
76+
77+
if (caption.classList.contains("caption-text")) {
78+
orphan = caption.parentElement;
79+
container.appendChild(caption);
80+
orphan.remove();
81+
} else {
82+
container.appendChild(caption);
83+
}
2184
});
22-
});
2385

24-
})();
86+
// Set ARIA role for the container
87+
container.setAttribute('role', 'tablist');
2588

89+
// Append blocks back to the container
90+
blocks.forEach(function(block) {
91+
container.appendChild(block);
92+
});
93+
94+
// Automatically click the first caption to set the initial state
95+
if (captions.length > 0) {
96+
captions[0].click();
97+
}
98+
});
99+
});

0 commit comments

Comments
 (0)