diff --git a/src/core/plugins/deep-linking/spec-wrap-actions.js b/src/core/plugins/deep-linking/spec-wrap-actions.js index a90d924c..d69fc465 100644 --- a/src/core/plugins/deep-linking/spec-wrap-actions.js +++ b/src/core/plugins/deep-linking/spec-wrap-actions.js @@ -31,20 +31,32 @@ export const updateResolved = (ori, { layoutActions, getConfigs }) => (...args) let swaggerUI = document.querySelector(".swagger-ui") let myScroller = zenscroll.createScroller(swaggerUI) + let target + if(tag && operationId) { // Pre-expand and scroll to the operation layoutActions.show(["operations-tag", tag], true) layoutActions.show(["operations", tag, operationId], true) - let target = document.getElementById(`operations-${escapeDeepLinkPath(tag)}-${escapeDeepLinkPath(operationId)}`) - myScroller.to(target) - + target = document + .getElementById(`operations-${escapeDeepLinkPath(tag)}-${escapeDeepLinkPath(operationId)}`) } else if(tag) { // Pre-expand and scroll to the tag layoutActions.show(["operations-tag", tag], true) - let target = document.getElementById(`operations-tag-${escapeDeepLinkPath(tag)}`) + target = document.getElementById(`operations-tag-${escapeDeepLinkPath(tag)}`) + } + + + if(target) { myScroller.to(target) + setTimeout(() => { + // Backup functionality: if we're still at the top of the document, + // scroll on the entire page (not within the Swagger-UI container) + if(zenscroll.getY() === 0) { + zenscroll.to(target) + } + }, 50) } }