Skip to content

Commit 66eb7f5

Browse files
committed
yarn build:frontend
1 parent d4b0df9 commit 66eb7f5

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

app/assets/javascripts/grape_swagger_rails/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
"use strict";
2+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4+
if (ar || !(i in from)) {
5+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6+
ar[i] = from[i];
7+
}
8+
}
9+
return to.concat(ar || Array.prototype.slice.call(from));
10+
};
11+
var COPY_BUTTON_LABEL = "Copy to clipboard";
12+
var labelCopyButtons = function (root) {
13+
var targets = root instanceof Element && root.matches(".copy-to-clipboard")
14+
? __spreadArray([root], Array.from(root.querySelectorAll(".copy-to-clipboard")), true) : Array.from(root.querySelectorAll(".copy-to-clipboard"));
15+
targets.forEach(function (node) {
16+
var el = node;
17+
if (!el.getAttribute("title")) {
18+
el.setAttribute("title", COPY_BUTTON_LABEL);
19+
}
20+
if (!el.getAttribute("aria-label")) {
21+
el.setAttribute("aria-label", COPY_BUTTON_LABEL);
22+
}
23+
});
24+
};
225
var safeDecodeURIComponent = function (value) {
326
try {
427
return decodeURIComponent(value);
@@ -232,6 +255,24 @@ var initializeSwaggerPage = function () {
232255
bundleConfig.url = absoluteSpecUrl(options.url);
233256
}
234257
window.ui = SwaggerUIBundle(bundleConfig);
258+
// Swagger UI's `.copy-to-clipboard` elements (the icon next to
259+
// operation paths, cURL examples, OAuth redirect URLs, etc.) ship without
260+
// a `title` or `aria-label` in some renderings, so on hover users see no
261+
// tooltip and screen readers announce nothing. Label any unlabeled
262+
// instances as Swagger UI renders or re-renders the tree.
263+
labelCopyButtons(document.body);
264+
var container = document.getElementById("swagger-ui-container");
265+
if (container) {
266+
new MutationObserver(function (mutations) {
267+
mutations.forEach(function (mutation) {
268+
mutation.addedNodes.forEach(function (node) {
269+
if (node.nodeType === Node.ELEMENT_NODE) {
270+
labelCopyButtons(node);
271+
}
272+
});
273+
});
274+
}).observe(container, { childList: true, subtree: true });
275+
}
235276
if (selectedUrl) {
236277
window.ui.specActions.updateUrl(selectedUrl.url);
237278
window.ui.specActions.download(selectedUrl.url);

app/assets/javascripts/grape_swagger_rails/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)