diff options
Diffstat (limited to 'docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js')
11 files changed, 229 insertions, 0 deletions
diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/clipboardjs.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/clipboardjs.js new file mode 100644 index 000000000..ffae31c7f --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/clipboardjs.js @@ -0,0 +1,30 @@ +var Clipboard = require('clipboard/dist/clipboard.js'); +new Clipboard('.copy', { + target: function(trigger) { + if(trigger.classList.contains('copy-toggle')){ + return trigger.previousElementSibling; + } + return trigger.nextElementSibling; + } + }).on('success', function(e) { + successMessage(e.trigger, 'Copied!'); + e.clearSelection(); + }).on('error', function(e) { + successMessage(e.trigger, fallbackMessage(e.action)); +}); + +function successMessage(elem, msg) { + elem.setAttribute('class', 'copied bg-primary-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2'); + elem.setAttribute('aria-label', msg); +} + +function fallbackMessage(elem, action) { + var actionMsg = ''; + var actionKey = (action === 'cut' ? 'X' : 'C'); + if (isMac) { + actionMsg = 'Press ⌘-' + actionKey; + } else { + actionMsg = 'Press Ctrl-' + actionKey; + } + return actionMsg; +} diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/codeblocks.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/codeblocks.js new file mode 100644 index 000000000..d8039c5d6 --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/codeblocks.js @@ -0,0 +1,10 @@ +let article = document.getElementById('prose') + +if (article) { + let codeBlocks = article.getElementsByTagName('code') + for (let [key, codeBlock] of Object.entries(codeBlocks)){ + var widthDif = codeBlock.scrollWidth - codeBlock.clientWidth + if (widthDif > 0) + codeBlock.parentNode.classList.add('expand') + } +} diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/docsearch.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/docsearch.js new file mode 100644 index 000000000..e14fb2994 --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/docsearch.js @@ -0,0 +1,8 @@ +var docsearch = require('docsearch.js/dist/cdn/docsearch.js'); +docsearch({ + appId: 'D1BPLZHGYQ', + apiKey: '6df94e1e5d55d258c56f60d974d10314', + indexName: 'hugodocs', + inputSelector: '#search-input', + debug: true, // Set debug to true if you want to inspect the dropdown +}); diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/filesaver.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/filesaver.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/filesaver.js diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/lazysizes.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/lazysizes.js new file mode 100644 index 000000000..4eb3950af --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/lazysizes.js @@ -0,0 +1,3 @@ +var lazysizes = require('lazysizes'); +// var lsnoscript = require('lazysizes/plugins/noscript/ls.noscript.js'); +var unveilhooks = require('lazysizes/plugins/unveilhooks/ls.unveilhooks.js'); diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/main.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/main.js new file mode 100644 index 000000000..f6d3eac9f --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/main.js @@ -0,0 +1,22 @@ +import styles from './../css/main.css'; +import './clipboardjs.js' +import './codeblocks.js' +import './docsearch.js' +import './lazysizes.js' +import './menutoggle.js' +import './scrolldir.js' +import './smoothscroll.js' +import './tabs.js' +import './nojs.js' + +// TO use jQuery, just call the modules you want +// var $ = require('jquery/src/core'); +// require('jquery/src/core/init'); +// require('jquery/src/manipulation'); + +// OR, use all of them +// var $ = require('jquery/src/jquery'); + +// And write your code +// $('body').append('<p>Jquery is working</p>'); +// diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/menutoggle.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/menutoggle.js new file mode 100644 index 000000000..d0e645385 --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/menutoggle.js @@ -0,0 +1,31 @@ +// Grab any element that has the 'js-toggle' class and add an event listner for the toggleClass function +var toggleBtns = document.getElementsByClassName('js-toggle') + for (var i = 0; i < toggleBtns.length; i++) { + toggleBtns[i].addEventListener('click', toggleClass, false) + } + +function toggleClass() { + // Define the data target via the dataset "target" (e.g. data-target=".docsmenu") + var content = this.dataset.target.split(' ') + // Find any menu items that are open + var mobileCurrentlyOpen = document.querySelector('.mobilemenu:not(.dn)') + var desktopCurrentlyOpen = document.querySelector('.desktopmenu:not(.dn)') + var desktopActive = document.querySelector('.desktopmenu:not(.dn)') + + // Loop through the targets' divs + for (var i = 0; i < content.length; i++) { + var matches = document.querySelectorAll(content[i]); + //for each, if the div has the 'dn' class (which is "display:none;"), remove it, otherwise, add that class + [].forEach.call(matches, function(dom) { + dom.classList.contains('dn') ? + dom.classList.remove('dn') : + dom.classList.add('dn'); + return false; + }); + // close the currently open menu items + if (mobileCurrentlyOpen) mobileCurrentlyOpen.classList.add('dn') + if (desktopCurrentlyOpen) desktopCurrentlyOpen.classList.add('dn') + if (desktopActive) desktopActive.classList.remove('db') + + } + } diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/nojs.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/nojs.js new file mode 100644 index 000000000..50b5126a9 --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/nojs.js @@ -0,0 +1 @@ +document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/, 'js'); diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/scrolldir.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/scrolldir.js new file mode 100644 index 000000000..0b69978cd --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/scrolldir.js @@ -0,0 +1 @@ +var scrollDir = require('scrolldir/dist/scrolldir.auto.min.js'); diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/smoothscroll.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/smoothscroll.js new file mode 100644 index 000000000..4bb2d99b8 --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/smoothscroll.js @@ -0,0 +1,80 @@ +// query selector targets Hugo TOC +(function() { + + 'use strict'; + + // Feature Test + if ('querySelector' in document && 'addEventListener' in window && Array.prototype.forEach) { + + // Function to animate the scroll + var smoothScroll = function(anchor, duration) { + + // Calculate how far and how fast to scroll + var startLocation = window.pageYOffset; + var endLocation = anchor.offsetTop; + var distance = endLocation - startLocation; + var increments = distance / (duration / 16); + var stopAnimation; + + // Scroll the page by an increment, and check if it's time to stop + var animateScroll = function() { + window.scrollBy(0, increments); + stopAnimation(); + }; + + // If scrolling down + if (increments >= 0) { + // Stop animation when you reach the anchor OR the bottom of the page + stopAnimation = function() { + var travelled = window.pageYOffset; + if ((travelled >= (endLocation - increments)) || ((window.innerHeight + travelled) >= document.body.offsetHeight)) { + clearInterval(runAnimation); + } + }; + } + // If scrolling up + else { + // Stop animation when you reach the anchor OR the top of the page + stopAnimation = function() { + var travelled = window.pageYOffset; + if (travelled <= (endLocation || 0)) { + clearInterval(runAnimation); + } + }; + } + + // Loop the animation function + var runAnimation = setInterval(animateScroll, 16); + + }; + + // Define smooth scroll links + var scrollToggle = document.querySelectorAll('#TableOfContents ul li a'); + + // For each smooth scroll link + [].forEach.call(scrollToggle, function(toggle) { + + // When the smooth scroll link is clicked + toggle.addEventListener('click', function(e) { + + // Prevent the default link behavior + e.preventDefault(); + + // Get anchor link and calculate distance from the top + var dataID = toggle.getAttribute('href'); + var dataTarget = document.querySelector(dataID); + var dataSpeed = toggle.getAttribute('data-speed'); + + // If the anchor exists + if (dataTarget) { + // Scroll to the anchor + smoothScroll(dataTarget, dataSpeed || 500); + } + + }, false); + + }); + + } + +})(); diff --git a/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/tabs.js b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/tabs.js new file mode 100644 index 000000000..a689d474e --- /dev/null +++ b/docs/_vendor/github.com/gohugoio/gohugoioTheme/assets/js/tabs.js @@ -0,0 +1,43 @@ +/** + * Scripts which manages Code Toggle tabs. + */ +var i; +// store tabs variable +var allTabs = document.querySelectorAll("[data-toggle-tab]"); +var allPanes = document.querySelectorAll("[data-pane]"); + +function toggleTabs(event) { + + if(event.target){ + event.preventDefault(); + var clickedTab = event.currentTarget; + var targetKey = clickedTab.getAttribute("data-toggle-tab") + }else { + var targetKey = event + } + // We store the config language selected in users' localStorage + if(window.localStorage){ + window.localStorage.setItem("configLangPref", targetKey) + } + var selectedTabs = document.querySelectorAll("[data-toggle-tab='" + targetKey + "']"); + var selectedPanes = document.querySelectorAll("[data-pane='" + targetKey + "']"); + + for (var i = 0; i < allTabs.length; i++) { + allTabs[i].classList.remove("active"); + allPanes[i].classList.remove("active"); + } + + for (var i = 0; i < selectedTabs.length; i++) { + selectedTabs[i].classList.add("active"); + selectedPanes[i].classList.add("active"); + } + +} + +for (i = 0; i < allTabs.length; i++) { + allTabs[i].addEventListener("click", toggleTabs) +} +// Upon page load, if user has a preferred language in its localStorage, tabs are set to it. +if(window.localStorage.getItem('configLangPref')) { + toggleTabs(window.localStorage.getItem('configLangPref')) +} |