refactor(js): run code formatter

This commit is contained in:
George Cushen 2021-01-08 23:29:45 +00:00
commit 3d8b76f092
12 changed files with 228 additions and 165 deletions

1
wowchemy/.prettierignore Normal file
View file

@ -0,0 +1 @@
assets/js/_vendor/

9
wowchemy/.prettierrc.js Normal file
View file

@ -0,0 +1,9 @@
'use strict';
module.exports = {
bracketSpacing: false,
singleQuote: true,
jsxBracketSameLine: true,
trailingComma: 'all',
printWidth: 120,
};

View file

@ -5,7 +5,7 @@
* Algolia based search algorithm. * Algolia based search algorithm.
**************************************************/ **************************************************/
if ((typeof instantsearch === 'function') && $('#search-box').length) { if (typeof instantsearch === 'function' && $('#search-box').length) {
function getTemplate(templateName) { function getTemplate(templateName) {
return document.querySelector(`#${templateName}-template`).innerHTML; return document.querySelector(`#${templateName}-template`).innerHTML;
} }
@ -16,17 +16,17 @@ if ((typeof instantsearch === 'function') && $('#search-box').length) {
indexName: algoliaConfig.indexName, indexName: algoliaConfig.indexName,
routing: true, routing: true,
searchParameters: { searchParameters: {
hitsPerPage: 10 hitsPerPage: 10,
}, },
searchFunction: function (helper) { searchFunction: function (helper) {
let searchResults = document.querySelector('#search-hits') let searchResults = document.querySelector('#search-hits');
if (helper.state.query === '') { if (helper.state.query === '') {
searchResults.style.display = 'none'; searchResults.style.display = 'none';
return; return;
} }
helper.search(); helper.search();
searchResults.style.display = 'block'; searchResults.style.display = 'block';
} },
}; };
const search = instantsearch(options); const search = instantsearch(options);
@ -38,8 +38,8 @@ if ((typeof instantsearch === 'function') && $('#search-box').length) {
autofocus: false, autofocus: false,
reset: true, reset: true,
poweredBy: algoliaConfig.poweredBy, poweredBy: algoliaConfig.poweredBy,
placeholder: i18n.placeholder placeholder: i18n.placeholder,
}) }),
); );
// Initialize search results. // Initialize search results.
@ -49,12 +49,12 @@ if ((typeof instantsearch === 'function') && $('#search-box').length) {
escapeHits: true, escapeHits: true,
templates: { templates: {
empty: '<div class="search-no-results">' + i18n.no_results + '</div>', empty: '<div class="search-no-results">' + i18n.no_results + '</div>',
item: getTemplate('search-hit-algolia') item: getTemplate('search-hit-algolia'),
}, },
cssClasses: { cssClasses: {
showmoreButton: 'btn btn-outline-primary' showmoreButton: 'btn btn-outline-primary',
} },
}) }),
); );
// On render search results, localize the content type metadata. // On render search results, localize the content type metadata.

View file

@ -5,12 +5,18 @@
// - The TeX.noUndefined.attributes option is not yet implemented (but may be in a future release) // - The TeX.noUndefined.attributes option is not yet implemented (but may be in a future release)
window.MathJax = { window.MathJax = {
tex: { tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']], inlineMath: [
displayMath: [['$$', '$$'], ['\\[', '\\]']], ['$', '$'],
['\\(', '\\)'],
],
displayMath: [
['$$', '$$'],
['\\[', '\\]'],
],
processEscapes: false, processEscapes: false,
packages: {'[+]': ['noerrors']} packages: {'[+]': ['noerrors']},
}, },
loader: { loader: {
load: ['[tex]/noerrors'] load: ['[tex]/noerrors'],
} },
}; };

View file

@ -9,7 +9,7 @@ function fadeIn(element, duration = 600) {
element.style.display = ''; element.style.display = '';
element.style.opacity = '0'; element.style.opacity = '0';
let last = +new Date(); let last = +new Date();
let tick = function() { let tick = function () {
element.style.opacity = (+element.style.opacity + (new Date() - last) / duration).toString(); element.style.opacity = (+element.style.opacity + (new Date() - last) / duration).toString();
last = +new Date(); last = +new Date();
if (+element.style.opacity < 1) { if (+element.style.opacity < 1) {
@ -19,6 +19,4 @@ function fadeIn(element, duration = 600) {
tick(); tick();
} }
export { export {fadeIn};
fadeIn,
};

View file

@ -12,7 +12,7 @@ import {wcDarkLightEnabled, wcIsSiteThemeDark} from '@params';
window.wc = { window.wc = {
darkLightEnabled: wcDarkLightEnabled, darkLightEnabled: wcDarkLightEnabled,
isSiteThemeDark: wcIsSiteThemeDark, isSiteThemeDark: wcIsSiteThemeDark,
} };
// Initialize theme variation and set body theme class. // Initialize theme variation and set body theme class.
initThemeVariation(); initThemeVariation();

View file

@ -6,35 +6,35 @@
**************************************************/ **************************************************/
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Configuration. * Configuration.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
// Configure Fuse. // Configure Fuse.
let fuseOptions = { let fuseOptions = {
shouldSort: true, shouldSort: true,
includeMatches: true, includeMatches: true,
tokenize: true, tokenize: true,
threshold: search_config.threshold, // Set to ~0.3 for parsing diacritics and CJK languages. threshold: search_config.threshold, // Set to ~0.3 for parsing diacritics and CJK languages.
location: 0, location: 0,
distance: 100, distance: 100,
maxPatternLength: 32, maxPatternLength: 32,
minMatchCharLength: search_config.minLength, // Set to 1 for parsing CJK languages. minMatchCharLength: search_config.minLength, // Set to 1 for parsing CJK languages.
keys: [ keys: [
{name:'title', weight:0.99}, /* 1.0 doesn't work o_O */ {name: 'title', weight: 0.99} /* 1.0 doesn't work o_O */,
{name:'summary', weight:0.6}, {name: 'summary', weight: 0.6},
{name:'authors', weight:0.5}, {name: 'authors', weight: 0.5},
{name:'content', weight:0.2}, {name: 'content', weight: 0.2},
{name:'tags', weight:0.5}, {name: 'tags', weight: 0.5},
{name:'categories', weight:0.5} {name: 'categories', weight: 0.5},
] ],
}; };
// Configure summary. // Configure summary.
let summaryLength = 60; let summaryLength = 60;
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Functions. * Functions.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
// Get query from URI. // Get query from URI.
function getSearchQuery(name) { function getSearchQuery(name) {
@ -44,29 +44,35 @@ function getSearchQuery(name) {
// Set query in URI without reloading the page. // Set query in URI without reloading the page.
function updateURL(url) { function updateURL(url) {
if (history.replaceState) { if (history.replaceState) {
window.history.replaceState({path:url}, '', url); window.history.replaceState({path: url}, '', url);
} }
} }
// Pre-process new search query. // Pre-process new search query.
function initSearch(force, fuse) { function initSearch(force, fuse) {
let query = $("#search-query").val(); let query = $('#search-query').val();
// If query deleted, clear results. // If query deleted, clear results.
if ( query.length < 1) { if (query.length < 1) {
$('#search-hits').empty(); $('#search-hits').empty();
$('#search-common-queries').show(); $('#search-common-queries').show();
} }
// Check for timer event (enter key not pressed) and query less than minimum length required. // Check for timer event (enter key not pressed) and query less than minimum length required.
if (!force && query.length < fuseOptions.minMatchCharLength) if (!force && query.length < fuseOptions.minMatchCharLength) return;
return;
// Do search. // Do search.
$('#search-hits').empty(); $('#search-hits').empty();
$('#search-common-queries').hide(); $('#search-common-queries').hide();
searchAcademic(query, fuse); searchAcademic(query, fuse);
let newURL = window.location.protocol + "//" + window.location.host + window.location.pathname + '?q=' + encodeURIComponent(query) + window.location.hash; let newURL =
window.location.protocol +
'//' +
window.location.host +
window.location.pathname +
'?q=' +
encodeURIComponent(query) +
window.location.hash;
updateURL(newURL); updateURL(newURL);
} }
@ -85,34 +91,42 @@ function searchAcademic(query, fuse) {
// Parse search results. // Parse search results.
function parseResults(query, results) { function parseResults(query, results) {
$.each( results, function(key, value) { $.each(results, function (key, value) {
let content_key = value.item.section; let content_key = value.item.section;
let content = ""; let content = '';
let snippet = ""; let snippet = '';
let snippetHighlights = []; let snippetHighlights = [];
// Show abstract in results for content types where the abstract is often the primary content. // Show abstract in results for content types where the abstract is often the primary content.
if (["publication", "event"].includes(content_key)) { if (['publication', 'event'].includes(content_key)) {
content = value.item.summary; content = value.item.summary;
} else { } else {
content = value.item.content; content = value.item.content;
} }
if ( fuseOptions.tokenize ) { if (fuseOptions.tokenize) {
snippetHighlights.push(query); snippetHighlights.push(query);
} else { } else {
$.each( value.matches, function(matchKey, matchValue) { $.each(value.matches, function (matchKey, matchValue) {
if (matchValue.key == "content") { if (matchValue.key == 'content') {
let start = (matchValue.indices[0][0]-summaryLength>0) ? matchValue.indices[0][0]-summaryLength : 0; let start = matchValue.indices[0][0] - summaryLength > 0 ? matchValue.indices[0][0] - summaryLength : 0;
let end = (matchValue.indices[0][1]+summaryLength<content.length) ? matchValue.indices[0][1]+summaryLength : content.length; let end =
matchValue.indices[0][1] + summaryLength < content.length
? matchValue.indices[0][1] + summaryLength
: content.length;
snippet += content.substring(start, end); snippet += content.substring(start, end);
snippetHighlights.push(matchValue.value.substring(matchValue.indices[0][0], matchValue.indices[0][1]-matchValue.indices[0][0]+1)); snippetHighlights.push(
matchValue.value.substring(
matchValue.indices[0][0],
matchValue.indices[0][1] - matchValue.indices[0][0] + 1,
),
);
} }
}); });
} }
if (snippet.length < 1) { if (snippet.length < 1) {
snippet += value.item.summary; // Alternative fallback: `content.substring(0, summaryLength*2);` snippet += value.item.summary; // Alternative fallback: `content.substring(0, summaryLength*2);`
} }
// Load template. // Load template.
@ -129,16 +143,15 @@ function parseResults(query, results) {
title: value.item.title, title: value.item.title,
type: content_key, type: content_key,
relpermalink: value.item.relpermalink, relpermalink: value.item.relpermalink,
snippet: snippet snippet: snippet,
}; };
let output = render(template, templateData); let output = render(template, templateData);
$('#search-hits').append(output); $('#search-hits').append(output);
// Highlight search terms in result. // Highlight search terms in result.
$.each( snippetHighlights, function(hlKey, hlValue){ $.each(snippetHighlights, function (hlKey, hlValue) {
$("#summary-"+key).mark(hlValue); $('#summary-' + key).mark(hlValue);
}); });
}); });
} }
@ -146,7 +159,7 @@ function render(template, data) {
// Replace placeholders with their values. // Replace placeholders with their values.
let key, find, re; let key, find, re;
for (key in data) { for (key in data) {
find = '\\{\\{\\s*' + key + '\\s*\\}\\}'; // Expect placeholder in the form `{{x}}`. find = '\\{\\{\\s*' + key + '\\s*\\}\\}'; // Expect placeholder in the form `{{x}}`.
re = new RegExp(find, 'g'); re = new RegExp(find, 'g');
template = template.replace(re, data[key]); template = template.replace(re, data[key]);
} }
@ -154,21 +167,21 @@ function render(template, data) {
} }
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Initialize. * Initialize.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
// If Academic's in-built search is enabled and Fuse loaded, then initialize it. // If Academic's in-built search is enabled and Fuse loaded, then initialize it.
if (typeof Fuse === 'function') { if (typeof Fuse === 'function') {
// Wait for Fuse to initialize. // Wait for Fuse to initialize.
$.getJSON(search_config.indexURI, function (search_index) { $.getJSON(search_config.indexURI, function (search_index) {
let fuse = new Fuse(search_index, fuseOptions); let fuse = new Fuse(search_index, fuseOptions);
// On page load, check for search query in URL. // On page load, check for search query in URL.
if (query = getSearchQuery('q')) { if ((query = getSearchQuery('q'))) {
$("body").addClass('searching'); $('body').addClass('searching');
$('.search-results').css({opacity: 0, visibility: "visible"}).animate({opacity: 1},200); $('.search-results').css({opacity: 0, visibility: 'visible'}).animate({opacity: 1}, 200);
$("#search-query").val(query); $('#search-query').val(query);
$("#search-query").focus(); $('#search-query').focus();
initSearch(true, fuse); initSearch(true, fuse);
} }
@ -178,9 +191,12 @@ if (typeof Fuse === 'function') {
if (e.keyCode == 13) { if (e.keyCode == 13) {
initSearch(true, fuse); initSearch(true, fuse);
} else { } else {
$(this).data('searchTimer', setTimeout(function () { $(this).data(
initSearch(false, fuse); 'searchTimer',
}, 250)); setTimeout(function () {
initSearch(false, fuse);
}, 250),
);
} }
}); });
}); });

View file

@ -34,7 +34,7 @@ function initThemeVariation() {
let isDarkTheme; let isDarkTheme;
let currentThemeMode = getThemeMode(); let currentThemeMode = getThemeMode();
console.debug(`User's theme variation: ${currentThemeMode}`) console.debug(`User's theme variation: ${currentThemeMode}`);
switch (currentThemeMode) { switch (currentThemeMode) {
case 0: case 0:
@ -59,10 +59,10 @@ function initThemeVariation() {
if (isDarkTheme && !body.classList.contains('dark')) { if (isDarkTheme && !body.classList.contains('dark')) {
console.debug('Applying Wowchemy dark theme'); console.debug('Applying Wowchemy dark theme');
document.body.classList.add("dark"); document.body.classList.add('dark');
} else if (!isDarkTheme && body.classList.contains('dark')) { } else if (!isDarkTheme && body.classList.contains('dark')) {
console.debug('Applying Wowchemy light theme'); console.debug('Applying Wowchemy light theme');
document.body.classList.remove("dark"); document.body.classList.remove('dark');
} }
return { return {
@ -149,7 +149,7 @@ function renderThemeVariation(isDarkTheme, themeMode = 2, init = false) {
// Is code highlighting enabled in site config? // Is code highlighting enabled in site config?
const codeHlLight = document.querySelector('link[title=hl-light]'); const codeHlLight = document.querySelector('link[title=hl-light]');
const codeHlDark = document.querySelector('link[title=hl-dark]'); const codeHlDark = document.querySelector('link[title=hl-dark]');
const codeHlEnabled = (codeHlLight !== null) || (codeHlDark !== null); const codeHlEnabled = codeHlLight !== null || codeHlDark !== null;
const diagramEnabled = document.querySelector('script[title=mermaid]') !== null; const diagramEnabled = document.querySelector('script[title=mermaid]') !== null;
// Update active theme mode in navbar theme selector. // Update active theme mode in navbar theme selector.
@ -159,7 +159,10 @@ function renderThemeVariation(isDarkTheme, themeMode = 2, init = false) {
if (!init) { if (!init) {
// If request to render light when light variation already rendered, return. // If request to render light when light variation already rendered, return.
// If request to render dark when dark variation already rendered, return. // If request to render dark when dark variation already rendered, return.
if ((isDarkTheme === false && !body.classList.contains('dark')) || (isDarkTheme === true && body.classList.contains('dark'))) { if (
(isDarkTheme === false && !body.classList.contains('dark')) ||
(isDarkTheme === true && body.classList.contains('dark'))
) {
return; return;
} }
} }
@ -176,7 +179,7 @@ function renderThemeVariation(isDarkTheme, themeMode = 2, init = false) {
if (codeHlLight) { if (codeHlLight) {
codeHlLight.disabled = false; codeHlLight.disabled = false;
} }
if (codeHlDark){ if (codeHlDark) {
codeHlDark.disabled = true; codeHlDark.disabled = true;
} }
} }
@ -196,13 +199,13 @@ function renderThemeVariation(isDarkTheme, themeMode = 2, init = false) {
Object.assign(document.body.style, {opacity: 0, visibility: 'visible'}); Object.assign(document.body.style, {opacity: 0, visibility: 'visible'});
fadeIn(document.body, 600); fadeIn(document.body, 600);
} }
body.classList.add("dark"); body.classList.add('dark');
if (codeHlEnabled) { if (codeHlEnabled) {
console.debug('Setting HLJS theme to dark'); console.debug('Setting HLJS theme to dark');
if (codeHlLight) { if (codeHlLight) {
codeHlLight.disabled = true; codeHlLight.disabled = true;
} }
if (codeHlDark){ if (codeHlDark) {
codeHlDark.disabled = false; codeHlDark.disabled = false;
} }
} }

View file

@ -23,6 +23,4 @@ function fixMermaid() {
} }
} }
export { export {fixMermaid};
fixMermaid,
};

View file

@ -16,9 +16,9 @@ import {
onMediaQueryListEvent, onMediaQueryListEvent,
} from './wowchemy-theming'; } from './wowchemy-theming';
const searchEnabled = (typeof search_config !== 'undefined'); const searchEnabled = typeof search_config !== 'undefined';
console.debug(`Environment: ${hugoEnvironment}`) console.debug(`Environment: ${hugoEnvironment}`);
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Responsive scrolling for URL hashes. * Responsive scrolling for URL hashes.
@ -41,20 +41,25 @@ function getNavBarHeight() {
function scrollToAnchor(target, duration = 600) { function scrollToAnchor(target, duration = 600) {
// If `target` is undefined or HashChangeEvent object, set it to window's hash. // If `target` is undefined or HashChangeEvent object, set it to window's hash.
// Decode the hash as browsers can encode non-ASCII characters (e.g. Chinese symbols). // Decode the hash as browsers can encode non-ASCII characters (e.g. Chinese symbols).
target = (typeof target === 'undefined' || typeof target === 'object') ? decodeURIComponent(window.location.hash) : target; target =
typeof target === 'undefined' || typeof target === 'object' ? decodeURIComponent(window.location.hash) : target;
// If target element exists, scroll to it taking into account fixed navigation bar offset. // If target element exists, scroll to it taking into account fixed navigation bar offset.
if ($(target).length) { if ($(target).length) {
// Escape special chars from IDs, such as colons found in Markdown footnote links. // Escape special chars from IDs, such as colons found in Markdown footnote links.
target = '#' + $.escapeSelector(target.substring(1)); // Previously, `target = target.replace(/:/g, '\\:');` target = '#' + $.escapeSelector(target.substring(1)); // Previously, `target = target.replace(/:/g, '\\:');`
let elementOffset = Math.ceil($(target).offset().top - getNavBarHeight()); // Round up to highlight right ID! let elementOffset = Math.ceil($(target).offset().top - getNavBarHeight()); // Round up to highlight right ID!
$('body').addClass('scrolling'); $('body').addClass('scrolling');
$('html, body').animate({ $('html, body').animate(
scrollTop: elementOffset {
}, duration, function () { scrollTop: elementOffset,
$('body').removeClass('scrolling'); },
}); duration,
function () {
$('body').removeClass('scrolling');
},
);
} else { } else {
console.debug('Cannot scroll to target `#' + target + '`. ID not found!'); console.debug('Cannot scroll to target `#' + target + '`. ID not found!');
} }
@ -73,13 +78,14 @@ function fixScrollspy() {
function removeQueryParamsFromUrl() { function removeQueryParamsFromUrl() {
if (window.history.replaceState) { if (window.history.replaceState) {
let urlWithoutSearchParams = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.hash; let urlWithoutSearchParams =
window.location.protocol + '//' + window.location.host + window.location.pathname + window.location.hash;
window.history.replaceState({path: urlWithoutSearchParams}, '', urlWithoutSearchParams); window.history.replaceState({path: urlWithoutSearchParams}, '', urlWithoutSearchParams);
} }
} }
// Check for hash change event and fix responsive offset for hash links (e.g. Markdown footnotes). // Check for hash change event and fix responsive offset for hash links (e.g. Markdown footnotes).
window.addEventListener("hashchange", scrollToAnchor); window.addEventListener('hashchange', scrollToAnchor);
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Add smooth scrolling to all links inside the main navbar. * Add smooth scrolling to all links inside the main navbar.
@ -90,22 +96,25 @@ $('#navbar-main li.nav-item a.nav-link, .js-scroll').on('click', function (event
let hash = this.hash; let hash = this.hash;
// If we are on a widget page and the navbar link is to a section on the same page. // If we are on a widget page and the navbar link is to a section on the same page.
if (this.pathname === window.location.pathname && hash && $(hash).length && ($(".js-widget-page").length > 0)) { if (this.pathname === window.location.pathname && hash && $(hash).length && $('.js-widget-page').length > 0) {
// Prevent default click behavior. // Prevent default click behavior.
event.preventDefault(); event.preventDefault();
// Use jQuery's animate() method for smooth page scrolling. // Use jQuery's animate() method for smooth page scrolling.
// The numerical parameter specifies the time (ms) taken to scroll to the specified hash. // The numerical parameter specifies the time (ms) taken to scroll to the specified hash.
let elementOffset = Math.ceil($(hash).offset().top - getNavBarHeight()); // Round up to highlight right ID! let elementOffset = Math.ceil($(hash).offset().top - getNavBarHeight()); // Round up to highlight right ID!
// Uncomment to debug. // Uncomment to debug.
// let scrollTop = $(window).scrollTop(); // let scrollTop = $(window).scrollTop();
// let scrollDelta = (elementOffset - scrollTop); // let scrollDelta = (elementOffset - scrollTop);
// console.debug('Scroll Delta: ' + scrollDelta); // console.debug('Scroll Delta: ' + scrollDelta);
$('html, body').animate({ $('html, body').animate(
scrollTop: elementOffset {
}, 800); scrollTop: elementOffset,
},
800,
);
} }
}); });
@ -145,21 +154,23 @@ if ($grid_pubs.length) {
percentPosition: true, percentPosition: true,
masonry: { masonry: {
// Use Bootstrap compatible grid layout. // Use Bootstrap compatible grid layout.
columnWidth: '.grid-sizer' columnWidth: '.grid-sizer',
}, },
filter: function () { filter: function () {
let $this = $(this); let $this = $(this);
let searchResults = searchRegex ? $this.text().match(searchRegex) : true; let searchResults = searchRegex ? $this.text().match(searchRegex) : true;
let filterResults = filterValues ? $this.is(filterValues) : true; let filterResults = filterValues ? $this.is(filterValues) : true;
return searchResults && filterResults; return searchResults && filterResults;
} },
}); });
// Filter by search term. // Filter by search term.
let $quickSearch = $('.filter-search').keyup(debounce(function () { let $quickSearch = $('.filter-search').keyup(
searchRegex = new RegExp($quickSearch.val(), 'gi'); debounce(function () {
$grid_pubs.isotope(); searchRegex = new RegExp($quickSearch.val(), 'gi');
})); $grid_pubs.isotope();
}),
);
$('.pub-filters').on('change', function () { $('.pub-filters').on('change', function () {
let $this = $(this); let $this = $(this);
@ -177,7 +188,7 @@ if ($grid_pubs.length) {
$grid_pubs.isotope(); $grid_pubs.isotope();
// If filtering by publication type, update the URL hash to enable direct linking to results. // If filtering by publication type, update the URL hash to enable direct linking to results.
if (filterGroup === "pubtype") { if (filterGroup === 'pubtype') {
// Set hash URL to current filter. // Set hash URL to current filter.
let url = $(this).val(); let url = $(this).val();
if (url.substr(0, 9) === '.pubtype-') { if (url.substr(0, 9) === '.pubtype-') {
@ -218,8 +229,7 @@ function concatValues(obj) {
// Filter publications according to hash in URL. // Filter publications according to hash in URL.
function filter_publications() { function filter_publications() {
// Check for Isotope publication layout. // Check for Isotope publication layout.
if (!$grid_pubs.length) if (!$grid_pubs.length) return;
return
let urlHash = window.location.hash.replace('#', ''); let urlHash = window.location.hash.replace('#', '');
let filterValue = '*'; let filterValue = '*';
@ -242,8 +252,8 @@ function filter_publications() {
} }
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Google Maps or OpenStreetMap via Leaflet. * Google Maps or OpenStreetMap via Leaflet.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
function initMap() { function initMap() {
if ($('#map').length) { if ($('#map').length) {
@ -263,11 +273,11 @@ function initMap() {
zoomControl: true, zoomControl: true,
zoomControlOpt: { zoomControlOpt: {
style: 'SMALL', style: 'SMALL',
position: 'TOP_LEFT' position: 'TOP_LEFT',
}, },
streetViewControl: false, streetViewControl: false,
mapTypeControl: false, mapTypeControl: false,
gestureHandling: "cooperative", gestureHandling: 'cooperative',
}); });
map.addMarker({ map.addMarker({
@ -275,30 +285,36 @@ function initMap() {
lng: lng, lng: lng,
click: function (e) { click: function (e) {
let url = 'https://www.google.com/maps/place/' + encodeURIComponent(address) + '/@' + lat + ',' + lng + '/'; let url = 'https://www.google.com/maps/place/' + encodeURIComponent(address) + '/@' + lat + ',' + lng + '/';
window.open(url, '_blank') window.open(url, '_blank');
}, },
title: address title: address,
}) });
} else { } else {
let map = new L.map('map').setView([lat, lng], zoom); let map = new L.map('map').setView([lat, lng], zoom);
if (map_provider == 3 && api_key.length) { if (map_provider == 3 && api_key.length) {
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', { L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>', attribution:
'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
tileSize: 512, tileSize: 512,
maxZoom: 18, maxZoom: 18,
zoomOffset: -1, zoomOffset: -1,
id: 'mapbox/streets-v11', id: 'mapbox/streets-v11',
accessToken: api_key accessToken: api_key,
}).addTo(map); }).addTo(map);
} else { } else {
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19, maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
}).addTo(map); }).addTo(map);
} }
let marker = L.marker([lat, lng]).addTo(map); let marker = L.marker([lat, lng]).addTo(map);
let url = lat + ',' + lng + '#map=' + zoom + '/' + lat + '/' + lng + '&layers=N'; let url = lat + ',' + lng + '#map=' + zoom + '/' + lat + '/' + lng + '&layers=N';
marker.bindPopup(address + '<p><a href="https://www.openstreetmap.org/directions?engine=osrm_car&route=' + url + '">Routing via OpenStreetMap</a></p>'); marker.bindPopup(
address +
'<p><a href="https://www.openstreetmap.org/directions?engine=osrm_car&route=' +
url +
'">Routing via OpenStreetMap</a></p>',
);
} }
} }
} }
@ -309,19 +325,21 @@ function initMap() {
function printLatestRelease(selector, repo) { function printLatestRelease(selector, repo) {
if (hugoEnvironment === 'production') { if (hugoEnvironment === 'production') {
$.getJSON('https://api.github.com/repos/' + repo + '/tags').done(function (json) { $.getJSON('https://api.github.com/repos/' + repo + '/tags')
let release = json[0]; .done(function (json) {
$(selector).append(' ' + release.name); let release = json[0];
}).fail(function (jqxhr, textStatus, error) { $(selector).append(' ' + release.name);
let err = textStatus + ", " + error; })
console.log("Request Failed: " + err); .fail(function (jqxhr, textStatus, error) {
}); let err = textStatus + ', ' + error;
console.log('Request Failed: ' + err);
});
} }
} }
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Toggle search dialog. * Toggle search dialog.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
function toggleSearchDialog() { function toggleSearchDialog() {
if ($('body').hasClass('searching')) { if ($('body').hasClass('searching')) {
@ -339,8 +357,8 @@ function toggleSearchDialog() {
if (!$('#fancybox-style-noscroll').length && document.body.scrollHeight > window.innerHeight) { if (!$('#fancybox-style-noscroll').length && document.body.scrollHeight > window.innerHeight) {
$('head').append( $('head').append(
'<style id="fancybox-style-noscroll">.compensate-for-scrollbar{margin-right:' + '<style id="fancybox-style-noscroll">.compensate-for-scrollbar{margin-right:' +
(window.innerWidth - document.documentElement.clientWidth) + (window.innerWidth - document.documentElement.clientWidth) +
'px;}</style>' 'px;}</style>',
); );
$('body').addClass('compensate-for-scrollbar'); $('body').addClass('compensate-for-scrollbar');
} }
@ -353,8 +371,8 @@ function toggleSearchDialog() {
} }
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Normalize Bootstrap Carousel Slide Heights. * Normalize Bootstrap Carousel Slide Heights.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
function normalizeCarouselSlideHeights() { function normalizeCarouselSlideHeights() {
$('.carousel').each(function () { $('.carousel').each(function () {
@ -363,16 +381,21 @@ function normalizeCarouselSlideHeights() {
// Reset all slide heights. // Reset all slide heights.
items.css('min-height', 0); items.css('min-height', 0);
// Normalize all slide heights. // Normalize all slide heights.
let maxHeight = Math.max.apply(null, items.map(function () { let maxHeight = Math.max.apply(
return $(this).outerHeight() null,
}).get()); items
.map(function () {
return $(this).outerHeight();
})
.get(),
);
items.css('min-height', maxHeight + 'px'); items.css('min-height', maxHeight + 'px');
}) });
} }
/* --------------------------------------------------------------------------- /* ---------------------------------------------------------------------------
* Fix Hugo's Goldmark output and Mermaid code blocks. * Fix Hugo's Goldmark output and Mermaid code blocks.
* --------------------------------------------------------------------------- */ * --------------------------------------------------------------------------- */
/** /**
* Fix Hugo's Goldmark output. * Fix Hugo's Goldmark output.
@ -453,30 +476,32 @@ $(window).on('load', function () {
itemSelector: '.isotope-item', itemSelector: '.isotope-item',
layoutMode: layout, layoutMode: layout,
masonry: { masonry: {
gutter: 20 gutter: 20,
}, },
filter: filterText filter: filterText,
}); });
// Filter Isotope items when a toolbar filter button is clicked. // Filter Isotope items when a toolbar filter button is clicked.
let isoFilterButtons = isoSection.querySelectorAll('.project-filters a'); let isoFilterButtons = isoSection.querySelectorAll('.project-filters a');
isoFilterButtons.forEach(button => button.addEventListener('click', (e) => { isoFilterButtons.forEach((button) =>
e.preventDefault(); button.addEventListener('click', (e) => {
let selector = button.getAttribute('data-filter'); e.preventDefault();
let selector = button.getAttribute('data-filter');
// Apply filter // Apply filter
console.debug(`Updating Isotope filter to ${selector}`); console.debug(`Updating Isotope filter to ${selector}`);
iso.arrange({filter: selector}); iso.arrange({filter: selector});
// Update active toolbar filter button // Update active toolbar filter button
button.classList.remove('active'); button.classList.remove('active');
button.classList.add('active'); button.classList.add('active');
let buttonSiblings = getSiblings(button); let buttonSiblings = getSiblings(button);
buttonSiblings.forEach(buttonSibling => { buttonSiblings.forEach((buttonSibling) => {
buttonSibling.classList.remove('active'); buttonSibling.classList.remove('active');
buttonSibling.classList.remove('all'); buttonSibling.classList.remove('all');
}); });
})); }),
);
// Check if all Isotope instances have loaded. // Check if all Isotope instances have loaded.
incrementIsotopeCounter(); incrementIsotopeCounter();
@ -513,8 +538,8 @@ $(window).on('load', function () {
let modal = $('#modal'); let modal = $('#modal');
modal.find('.modal-body code').load(filename, function (response, status, xhr) { modal.find('.modal-body code').load(filename, function (response, status, xhr) {
if (status == 'error') { if (status == 'error') {
let msg = "Error: "; let msg = 'Error: ';
$('#modal-error').html(msg + xhr.status + " " + xhr.statusText); $('#modal-error').html(msg + xhr.status + ' ' + xhr.statusText);
} else { } else {
$('.js-download-cite').attr('href', filename); $('.js-download-cite').attr('href', filename);
} }
@ -551,7 +576,7 @@ $(window).on('load', function () {
// Parse Wowchemy keyboard shortcuts. // Parse Wowchemy keyboard shortcuts.
document.addEventListener('keyup', (event) => { document.addEventListener('keyup', (event) => {
if (event.code === "Escape") { if (event.code === 'Escape') {
const body = document.body; const body = document.body;
if (body.classList.contains('searching')) { if (body.classList.contains('searching')) {
// Close search dialog. // Close search dialog.
@ -559,13 +584,13 @@ $(window).on('load', function () {
} }
} }
// Use `key` to check for slash. Otherwise, with `code` we need to check for modifiers. // Use `key` to check for slash. Otherwise, with `code` we need to check for modifiers.
if (event.key === "/" ) { if (event.key === '/') {
let focusedElement = ( let focusedElement =
document.hasFocus() && (document.hasFocus() &&
document.activeElement !== document.body && document.activeElement !== document.body &&
document.activeElement !== document.documentElement && document.activeElement !== document.documentElement &&
document.activeElement document.activeElement) ||
) || null; null;
let isInputFocused = focusedElement instanceof HTMLInputElement || focusedElement instanceof HTMLTextAreaElement; let isInputFocused = focusedElement instanceof HTMLInputElement || focusedElement instanceof HTMLTextAreaElement;
if (searchEnabled && !isInputFocused) { if (searchEnabled && !isInputFocused) {
// Open search dialog. // Open search dialog.
@ -597,15 +622,15 @@ let linkLight = document.querySelector('.js-set-theme-light');
let linkDark = document.querySelector('.js-set-theme-dark'); let linkDark = document.querySelector('.js-set-theme-dark');
let linkAuto = document.querySelector('.js-set-theme-auto'); let linkAuto = document.querySelector('.js-set-theme-auto');
if (linkLight && linkDark && linkAuto) { if (linkLight && linkDark && linkAuto) {
linkLight.addEventListener('click', event => { linkLight.addEventListener('click', (event) => {
event.preventDefault(); event.preventDefault();
changeThemeModeClick(0); changeThemeModeClick(0);
}); });
linkDark.addEventListener('click', event => { linkDark.addEventListener('click', (event) => {
event.preventDefault(); event.preventDefault();
changeThemeModeClick(1); changeThemeModeClick(1);
}); });
linkAuto.addEventListener('click', event => { linkAuto.addEventListener('click', (event) => {
event.preventDefault(); event.preventDefault();
changeThemeModeClick(2); changeThemeModeClick(2);
}); });
@ -615,7 +640,7 @@ if (linkLight && linkDark && linkAuto) {
// Live update of day/night mode on system preferences update (no refresh required). // Live update of day/night mode on system preferences update (no refresh required).
// Note: since we listen only for *dark* events, we won't detect other scheme changes such as light to no-preference. // Note: since we listen only for *dark* events, we won't detect other scheme changes such as light to no-preference.
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
darkModeMediaQuery.addEventListener("change", (event) => { darkModeMediaQuery.addEventListener('change', (event) => {
onMediaQueryListEvent(event); onMediaQueryListEvent(event);
}); });

View file

@ -7,7 +7,9 @@
"bootstrap": "^4.4.1", "bootstrap": "^4.4.1",
"instant.page": "^5.1.0" "instant.page": "^5.1.0"
}, },
"devDependencies": {}, "devDependencies": {
"prettier": "2.2.1"
},
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },

View file

@ -11,3 +11,8 @@ instant.page@^5.1.0:
version "5.1.0" version "5.1.0"
resolved "https://registry.yarnpkg.com/instant.page/-/instant.page-5.1.0.tgz#ee0b5c341eda6c16d63def214bb6126701d7154d" resolved "https://registry.yarnpkg.com/instant.page/-/instant.page-5.1.0.tgz#ee0b5c341eda6c16d63def214bb6126701d7154d"
integrity sha512-7tz0vkrbj6rN08+C56UDTs1Z71ATPNjMv2eCFaYnIIn3jlkEF6HZCaUtsigjaN2hVaYiuu06vu1usDMnu+OEFg== integrity sha512-7tz0vkrbj6rN08+C56UDTs1Z71ATPNjMv2eCFaYnIIn3jlkEF6HZCaUtsigjaN2hVaYiuu06vu1usDMnu+OEFg==
prettier@2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==