From a95e628c208c08b9f06f4f0602b9a8768e250422 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Wed, 2 Dec 2020 02:25:34 -0700 Subject: [PATCH] use more specific selector for on this page component --- src/js/02-on-this-page.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/js/02-on-this-page.js b/src/js/02-on-this-page.js index 7976c8b..0bf7320 100644 --- a/src/js/02-on-this-page.js +++ b/src/js/02-on-this-page.js @@ -7,11 +7,21 @@ var levels = parseInt(sidebar.dataset.levels || 2) if (levels < 0) return - var article = document.querySelector('article.doc') - var headings - var headingSelector = [] - for (var l = 0; l <= levels; l++) headingSelector.push(l ? '.sect' + l + '>h' + (l + 1) + '[id]' : 'h1[id].sect0') - if (!(headings = find(headingSelector.join(','), article)).length) return sidebar.parentNode.removeChild(sidebar) + var articleSelector = 'article.doc' + var article = document.querySelector(articleSelector) + var headingsSelector = [] + for (var level = 0; level <= levels; level++) { + var headingSelector = [articleSelector] + if (level) { + for (var l = 1; l <= level; l++) headingSelector.push((l === 2 ? '.sectionbody>' : '') + '.sect' + l) + headingSelector.push('h' + (level + 1) + '[id]') + } else { + headingSelector.push('h1[id].sect0') + } + headingsSelector.push(headingSelector.join('>')) + } + var headings = find(headingsSelector.join(','), article.parentNode) + if (!headings.length) return sidebar.parentNode.removeChild(sidebar) var lastActiveFragment var links = {} -- 2.11.0