From 8e8bb6d148a42ac1c625701b1f1a2504affa87bd Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 9 Jan 2018 14:50:18 +0200 Subject: [PATCH] Updated web script Used emoji for clipboard icons, added persistent scroll to top button with proper smooth scrolling. --- docs/mini/flavor.scss | 17 +++++++++++++++++ scripts/web.js | 4 ++-- static-parts/index-end.html | 2 +- static-parts/index-start.html | 10 ++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/mini/flavor.scss b/docs/mini/flavor.scss index b3e3f11c0..59775783e 100644 --- a/docs/mini/flavor.scss +++ b/docs/mini/flavor.scss @@ -437,3 +437,20 @@ code[class*="language-"]::selection, code[class*="language-"] ::selection { .token.entity { cursor: help; } + +button.scroll-to-top { + border-radius: 100%; + font-size: 1.5rem; + line-height: 1; + box-sizing: border-box; + width: 2.75rem; + height: 2.75rem; + position: fixed; + bottom: 1rem; + right: 2rem; + background: var(#{$back-color-var}); + box-shadow: 0 .25rem .25rem 0 rgba(0,0,0,0.125),0 .125rem .125rem -.125rem rgba(0,0,0,0.25); + &:hover, &:focus { + background: var(#{$secondary-back-color-var}); + } +} diff --git a/scripts/web.js b/scripts/web.js index 6b86c7683..36864f989 100644 --- a/scripts/web.js +++ b/scripts/web.js @@ -169,7 +169,7 @@ try { .replace(/<\/h3>/g, `${taggedSnippet[1].includes('advanced')?'advanced':''}`) .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) .replace(/<\/pre>\s+
clipboard Copy to clipboard' +
+          '' +
           '';
     } else {
       output += md
@@ -185,7 +185,7 @@ try {
             .replace(/<\/h3>/g, '
') .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) .replace(/<\/pre>\s+
clipboard Copy to clipboard' +
+          '' +
           '
'; } } diff --git a/static-parts/index-end.html b/static-parts/index-end.html index d7aef2012..a977f3cb7 100644 --- a/static-parts/index-end.html +++ b/static-parts/index-end.html @@ -1,6 +1,6 @@ + diff --git a/static-parts/index-start.html b/static-parts/index-start.html index 00bbe441b..e5c0702d1 100644 --- a/static-parts/index-start.html +++ b/static-parts/index-start.html @@ -27,6 +27,13 @@ x.style.display = matchingTags.includes(x.innerText.toLowerCase()) ? '' : 'none'; }) } + function scrollToTop(){ + const c = document.querySelector('main').scrollTop; + if (c > 0) { + window.requestAnimationFrame(scrollToTop); + document.querySelector('main').scrollTo(0, c - c / 4); + } + }; function loader() { registerClickListener(); } @@ -54,6 +61,9 @@ },300); },1700); } + else if (event.target.classList.contains('scroll-to-top')){ + scrollToTop(); + } }, false); }