From 00fe7d0f71fc391df9ace7366df8828522975af0 Mon Sep 17 00:00:00 2001 From: Stephen Fluin Date: Fri, 7 May 2021 15:44:51 -0700 Subject: [PATCH] add anchor links on hover --- _includes/feed.liquid | 2 +- _includes/main.liquid | 87 ++++++++++++++++++++++++------------------ _includes/nodes.liquid | 2 +- _src/docs.css | 11 ++++++ _src/images/link.svg | 1 + 5 files changed, 64 insertions(+), 39 deletions(-) create mode 100644 _src/images/link.svg diff --git a/_includes/feed.liquid b/_includes/feed.liquid index 0a185287861..8b4620a5adc 100644 --- a/_includes/feed.liquid +++ b/_includes/feed.liquid @@ -38,7 +38,7 @@ section: smartContract render = (data) => { let html = ''; for(let network of data["{{stub}}"].networks) { - html += `

${network.name}

`; + html += `

${network.name} Link to this section

`; let proxyList = ''; for(let proxy of network.proxies) { diff --git a/_includes/main.liquid b/_includes/main.liquid index 69df4172b7f..1d809110fad 100644 --- a/_includes/main.liquid +++ b/_includes/main.liquid @@ -54,35 +54,7 @@ gtag("config", "UA-128878871-16"); - + @@ -275,17 +247,58 @@ + + document.addEventListener('mouseup',checkForHighlight); + // Track remix deployments + [...document.getElementsByTagName('a')] + .filter(x => x.href.startsWith('https://remix.ethereum.org/') && x.href.length > 27 ) + .map(x => {x.addEventListener('click',(event) => { + gtag('event','deploy-to-remix',{event_category:'docs-engagement'}); + });}); + [...document.getElementsByClassName('copy-to-clipboard-button')] + .map(x => {x.addEventListener('click',(event) => { + gtag('event','copy-code',{event_category:'docs-engagement'}); + });}); + + // Open all external links in a blank context + const links = document.links; + for (var i = 0, linksLength = links.length; i < linksLength; i++) { + if(!links[i].href.startsWith("javascript:")) { + if (links[i].hostname != window.location.hostname) { + links[i].target = '_blank'; + } + } + } + + // Add header anchor tags + const headers = document.querySelectorAll('.article > h1:not(.page-title),.article > h2,.article > h3'); + [...headers].map(header => { + const link = document.createElement('a'); + link.href = `#${header.id}`; + link.classList.add('anchor'); + link.innerHTML = 'Link to this section'; + header.appendChild(link); + }) + }) + + + diff --git a/_includes/nodes.liquid b/_includes/nodes.liquid index 5eb3a56a838..ce2efb54680 100644 --- a/_includes/nodes.liquid +++ b/_includes/nodes.liquid @@ -30,7 +30,7 @@ layout: ./main.liquid {% endfor %} -
+
{% if title %}

{{title}}

diff --git a/_src/docs.css b/_src/docs.css index 9ed241f57a8..44308986920 100644 --- a/_src/docs.css +++ b/_src/docs.css @@ -109,6 +109,17 @@ a:hover, #nav-container .tab a:hover { color: #375bd2; } +a.anchor { + display: none; +} +h1:hover .anchor, +h2:hover .anchor, +h3:hover .anchor { + display: inline; +} +a.anchor img { + margin: 0 0 0 8px; +} /** Side navigation */ .nav-content { diff --git a/_src/images/link.svg b/_src/images/link.svg new file mode 100644 index 00000000000..6f4c3b604d8 --- /dev/null +++ b/_src/images/link.svg @@ -0,0 +1 @@ + \ No newline at end of file