|
1 | 1 | "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 | +}; |
2 | 25 | var safeDecodeURIComponent = function (value) { |
3 | 26 | try { |
4 | 27 | return decodeURIComponent(value); |
@@ -232,6 +255,24 @@ var initializeSwaggerPage = function () { |
232 | 255 | bundleConfig.url = absoluteSpecUrl(options.url); |
233 | 256 | } |
234 | 257 | 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 | + } |
235 | 276 | if (selectedUrl) { |
236 | 277 | window.ui.specActions.updateUrl(selectedUrl.url); |
237 | 278 | window.ui.specActions.download(selectedUrl.url); |
|
0 commit comments