diff options
Diffstat (limited to '_includes/scripts/article.js')
-rw-r--r-- | _includes/scripts/article.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/_includes/scripts/article.js b/_includes/scripts/article.js new file mode 100644 index 0000000..9b18ef5 --- /dev/null +++ b/_includes/scripts/article.js @@ -0,0 +1,24 @@ +(function() { + var SOURCES = window.TEXT_VARIABLES.sources; + window.Lazyload.js(SOURCES.jquery, function() { + $(function() { + var $this ,$scroll; + var $articleContent = $('.js-article-content'); + var hasSidebar = $('.js-page-root').hasClass('layout--page--sidebar'); + var scroll = hasSidebar ? '.js-page-main' : 'html, body'; + $scroll = $(scroll); + + $articleContent.find('.highlight').each(function() { + $this = $(this); + $this.attr('data-lang', $this.find('code').attr('data-lang')); + }); + $articleContent.find('h1[id], h2[id], h3[id], h4[id], h5[id], h6[id]').each(function() { + $this = $(this); + $this.append($('<a class="anchor d-print-none" aria-hidden="true"></a>').html('<i class="fas fa-anchor"></i>')); + }); + $articleContent.on('click', '.anchor', function() { + $scroll.scrollToAnchor('#' + $(this).parent().attr('id'), 400); + }); + }); + }); +})(); |