123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- import mediumZoom from './_vendor/medium-zoom.esm';
- import {hugoEnvironment, codeHighlighting, searchEnabled} from '@params';
- import {scrollParentToChild} from './wowchemy-utils';
- import {
- changeThemeModeClick,
- initThemeVariation,
- renderThemeVariation,
- onMediaQueryListEvent,
- } from './wowchemy-theming';
- console.debug(`Environment: ${hugoEnvironment}`);
- function getNavBarHeight() {
- let navbar = document.getElementById('navbar-main');
- let navbarHeight = navbar ? navbar.getBoundingClientRect().height : 0;
- console.debug('Navbar height: ' + navbarHeight);
- return navbarHeight;
- }
- function scrollToAnchor(target, duration = 0) {
-
-
- target =
- typeof target === 'undefined' || typeof target === 'object' ? decodeURIComponent(window.location.hash) : target;
-
- if ($(target).length) {
-
- target = '#' + $.escapeSelector(target.substring(1));
- let elementOffset = Math.ceil($(target).offset().top - getNavBarHeight());
- $('body').addClass('scrolling');
- $('html, body').animate(
- {
- scrollTop: elementOffset,
- },
- duration,
- function () {
- $('body').removeClass('scrolling');
- },
- );
- } else {
- console.debug('Cannot scroll to target `#' + target + '`. ID not found!');
- }
- }
- function fixScrollspy() {
- let $body = $('body');
- let data = $body.data('bs.scrollspy');
- if (data) {
- data._config.offset = getNavBarHeight();
- $body.data('bs.scrollspy', data);
- $body.scrollspy('refresh');
- }
- }
- function removeQueryParamsFromUrl() {
- if (window.history.replaceState) {
- let urlWithoutSearchParams =
- window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.hash;
- window.history.replaceState({path: urlWithoutSearchParams}, '', urlWithoutSearchParams);
- }
- }
- window.addEventListener('hashchange', scrollToAnchor);
- $('#navbar-main li.nav-item a.nav-link, .js-scroll').on('click', function (event) {
-
- let hash = this.hash;
-
- if (this.pathname === window.location.pathname && hash && $(hash).length && $('.js-widget-page').length > 0) {
-
- event.preventDefault();
-
-
- let elementOffset = Math.ceil($(hash).offset().top - getNavBarHeight());
-
-
-
-
- $('html, body').animate(
- {
- scrollTop: elementOffset,
- },
- 800,
- );
- }
- });
- $(document).on('click', '.navbar-collapse.show', function (e) {
-
- let targetElement = $(e.target).is('a') ? $(e.target) : $(e.target).parent();
- if (targetElement.is('a') && targetElement.attr('class') != 'dropdown-toggle') {
- $(this).collapse('hide');
- }
- });
- function printLatestRelease(selector, repo) {
- if (hugoEnvironment === 'production') {
- $.getJSON('https://api.github.com/repos/' + repo + '/tags')
- .done(function (json) {
- let release = json[0];
- $(selector).append(' ' + release.name);
- })
- .fail(function (jqxhr, textStatus, error) {
- let err = textStatus + ', ' + error;
- console.log('Request Failed: ' + err);
- });
- }
- }
- function toggleSearchDialog() {
- if ($('body').hasClass('searching')) {
-
- $('[id=search-query]').blur();
- $('body').removeClass('searching compensate-for-scrollbar');
-
- removeQueryParamsFromUrl();
-
- $('#fancybox-style-noscroll').remove();
- } else {
-
- if (!$('#fancybox-style-noscroll').length && document.body.scrollHeight > window.innerHeight) {
- $('head').append(
- '<style id="fancybox-style-noscroll">.compensate-for-scrollbar{margin-right:' +
- (window.innerWidth - document.documentElement.clientWidth) +
- 'px;}</style>',
- );
- $('body').addClass('compensate-for-scrollbar');
- }
-
- $('body').addClass('searching');
- $('.search-results').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 200);
- let algoliaSearchBox = document.querySelector('.ais-SearchBox-input');
- if (algoliaSearchBox) {
- algoliaSearchBox.focus();
- } else {
- $('#search-query').focus();
- }
- }
- }
- function fixHugoOutput() {
-
-
- $('#TableOfContents').addClass('nav flex-column');
- $('#TableOfContents li').addClass('nav-item');
- $('#TableOfContents li a').addClass('nav-link');
-
- $("input[type='checkbox'][disabled]").parents('ul').addClass('task-list');
-
- $("table").addClass('.table');
- }
- function getSiblings(elem) {
-
- return Array.prototype.filter.call(elem.parentNode.children, function (sibling) {
- return sibling !== elem;
- });
- }
- $(document).ready(function () {
- fixHugoOutput();
-
- let {isDarkTheme, themeMode} = initThemeVariation();
- renderThemeVariation(isDarkTheme, themeMode, true);
-
-
- if (codeHighlighting) {
- hljs.initHighlighting();
- }
-
- let child = document.querySelector('.docs-links .active');
- let parent = document.querySelector('.docs-links');
- if (child && parent) {
- scrollParentToChild(parent, child);
- }
- });
- $(window).on('load', function () {
-
- fixScrollspy();
-
- let isotopeInstances = document.querySelectorAll('.projects-container');
- let isotopeInstancesCount = isotopeInstances.length;
-
-
- if (window.location.hash && isotopeInstancesCount === 0) {
- scrollToAnchor(decodeURIComponent(window.location.hash), 0);
- }
-
-
- let child = document.querySelector('.docs-toc .nav-link.active');
- let parent = document.querySelector('.docs-toc');
- if (child && parent) {
- scrollParentToChild(parent, child);
- }
-
- let zoomOptions = {};
- if (document.body.classList.contains('dark')) {
- zoomOptions.background = 'rgba(0,0,0,0.9)';
- } else {
- zoomOptions.background = 'rgba(255,255,255,0.9)';
- }
- mediumZoom('[data-zoomable]', zoomOptions);
-
- let isotopeCounter = 0;
- isotopeInstances.forEach(function (isotopeInstance, index) {
- console.debug(`Loading Isotope instance ${index}`);
-
- let iso;
-
- let isoSection = isotopeInstance.closest('section');
- let layout = '';
- if (isoSection.querySelector('.isotope').classList.contains('js-layout-row')) {
- layout = 'fitRows';
- } else {
- layout = 'masonry';
- }
-
- let defaultFilter = isoSection.querySelector('.default-project-filter');
- let filterText = '*';
- if (defaultFilter !== null) {
- filterText = defaultFilter.textContent;
- }
- console.debug(`Default Isotope filter: ${filterText}`);
-
- imagesLoaded(isotopeInstance, function () {
- iso = new Isotope(isotopeInstance, {
- itemSelector: '.isotope-item',
- layoutMode: layout,
- masonry: {
- gutter: 20,
- },
- filter: filterText,
- });
-
- let isoFilterButtons = isoSection.querySelectorAll('.project-filters a');
- isoFilterButtons.forEach((button) =>
- button.addEventListener('click', (e) => {
- e.preventDefault();
- let selector = button.getAttribute('data-filter');
-
- console.debug(`Updating Isotope filter to ${selector}`);
- iso.arrange({filter: selector});
-
- button.classList.remove('active');
- button.classList.add('active');
- let buttonSiblings = getSiblings(button);
- buttonSiblings.forEach((buttonSibling) => {
- buttonSibling.classList.remove('active');
- buttonSibling.classList.remove('all');
- });
- }),
- );
-
- incrementIsotopeCounter();
- });
- });
-
- function incrementIsotopeCounter() {
- isotopeCounter++;
- if (isotopeCounter === isotopeInstancesCount) {
- console.debug(`All Portfolio Isotope instances loaded.`);
-
-
-
-
-
- if (window.location.hash) {
- scrollToAnchor(decodeURIComponent(window.location.hash), 0);
- }
- }
- }
-
- let githubReleaseSelector = '.js-github-release';
- if ($(githubReleaseSelector).length > 0) {
- printLatestRelease(githubReleaseSelector, $(githubReleaseSelector).data('repo'));
- }
-
- document.addEventListener('keyup', (event) => {
- if (event.code === 'Escape') {
- const body = document.body;
- if (body.classList.contains('searching')) {
-
- toggleSearchDialog();
- }
- }
-
- if (event.key === '/') {
- let focusedElement =
- (document.hasFocus() &&
- document.activeElement !== document.body &&
- document.activeElement !== document.documentElement &&
- document.activeElement) ||
- null;
- let isInputFocused = focusedElement instanceof HTMLInputElement || focusedElement instanceof HTMLTextAreaElement;
- if (searchEnabled && !isInputFocused) {
-
- event.preventDefault();
- toggleSearchDialog();
- }
- }
- });
-
-
- if (searchEnabled) {
-
- $('.js-search').click(function (e) {
- e.preventDefault();
- toggleSearchDialog();
- });
- }
-
- $('[data-toggle="tooltip"]').tooltip();
- });
- let linkLight = document.querySelector('.js-set-theme-light');
- let linkDark = document.querySelector('.js-set-theme-dark');
- let linkAuto = document.querySelector('.js-set-theme-auto');
- if (linkLight && linkDark && linkAuto) {
- linkLight.addEventListener('click', (event) => {
- event.preventDefault();
- changeThemeModeClick(0);
- });
- linkDark.addEventListener('click', (event) => {
- event.preventDefault();
- changeThemeModeClick(1);
- });
- linkAuto.addEventListener('click', (event) => {
- event.preventDefault();
- changeThemeModeClick(2);
- });
- }
- const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
- darkModeMediaQuery.addEventListener('change', (event) => {
- onMediaQueryListEvent(event);
- });
- $('body').on('mouseenter mouseleave', '.dropdown', function (e) {
- var dropdown = $(e.target).closest('.dropdown');
- var menu = $('.dropdown-menu', dropdown);
- dropdown.addClass('show');
- menu.addClass('show');
- setTimeout(function () {
- dropdown[dropdown.is(':hover') ? 'addClass' : 'removeClass']('show');
- menu[dropdown.is(':hover') ? 'addClass' : 'removeClass']('show');
- }, 300);
- });
- let resizeTimer;
- $(window).resize(function () {
- clearTimeout(resizeTimer);
- resizeTimer = setTimeout(fixScrollspy, 200);
- });
|