introduce
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/* global wp, jQuery */
|
||||
/**
|
||||
* File customizer.js.
|
||||
*
|
||||
* Theme Customizer enhancements for a better user experience.
|
||||
*
|
||||
* Contains handlers to make Theme Customizer preview reload changes asynchronously.
|
||||
*/
|
||||
|
||||
( function( $ ) {
|
||||
// Site title and description.
|
||||
wp.customize( 'blogname', function( value ) {
|
||||
value.bind( function( to ) {
|
||||
$( '.site-title a' ).text( to );
|
||||
} );
|
||||
} );
|
||||
wp.customize( 'blogdescription', function( value ) {
|
||||
value.bind( function( to ) {
|
||||
$( '.site-description' ).text( to );
|
||||
} );
|
||||
} );
|
||||
|
||||
// Header text color.
|
||||
wp.customize( 'header_textcolor', function( value ) {
|
||||
value.bind( function( to ) {
|
||||
if ( 'blank' === to ) {
|
||||
$( '.site-title, .site-description' ).css( {
|
||||
clip: 'rect(1px, 1px, 1px, 1px)',
|
||||
position: 'absolute',
|
||||
} );
|
||||
} else {
|
||||
$( '.site-title, .site-description' ).css( {
|
||||
clip: 'auto',
|
||||
position: 'relative',
|
||||
} );
|
||||
$( '.site-title a, .site-description' ).css( {
|
||||
color: to,
|
||||
} );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
}( jQuery ) );
|
||||
Vendored
+9
File diff suppressed because one or more lines are too long
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* File navigation.js.
|
||||
*
|
||||
* Handles toggling the navigation menu for small screens and enables TAB key
|
||||
* navigation support for dropdown menus.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File navigation.js.
|
||||
*
|
||||
* Handles toggling the navigation menu for small screens and enables TAB key
|
||||
* navigation support for dropdown menus.
|
||||
*/
|
||||
( function() {
|
||||
var container, button, menu, links, i, len;
|
||||
|
||||
container = document.getElementById( 'site-navigation' );
|
||||
if ( ! container ) {
|
||||
return;
|
||||
}
|
||||
|
||||
button = container.getElementsByTagName( 'button' )[0];
|
||||
if ( 'undefined' === typeof button ) {
|
||||
return;
|
||||
}
|
||||
|
||||
menu = container.getElementsByTagName( 'ul' )[0];
|
||||
|
||||
// Hide menu toggle button if menu is empty and return early.
|
||||
if ( 'undefined' === typeof menu ) {
|
||||
button.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
if ( -1 === menu.className.indexOf( 'nav-menu' ) ) {
|
||||
menu.className += ' nav-menu';
|
||||
}
|
||||
|
||||
button.onclick = function() {
|
||||
if ( -1 !== container.className.indexOf( 'toggled' ) ) {
|
||||
container.className = container.className.replace( ' toggled', '' );
|
||||
button.setAttribute( 'aria-expanded', 'false' );
|
||||
} else {
|
||||
container.className += ' toggled';
|
||||
button.setAttribute( 'aria-expanded', 'true' );
|
||||
}
|
||||
};
|
||||
|
||||
function handleTabPress (e){
|
||||
if((e.keyCode === 9 || e.key === 'Tab') && !e.shiftKey){
|
||||
container.classList.remove('toggled')
|
||||
button.setAttribute('aria-expanded', 'false');
|
||||
const toggleButton = document.querySelector('.menu-toggle');
|
||||
toggleButton.setAttribute('tabindex', -1);
|
||||
toggleButton.focus()
|
||||
toggleButton.setAttribute('tabindex', 0);
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
function handleSiftTabPress(e){
|
||||
if(e.shiftKey && (e.keyCode === 9 || e.key === 'Tab') && e.target.classList.contains('menu-toggle') ){
|
||||
container.classList.remove('toggled')
|
||||
button.setAttribute('aria-expanded', 'false');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setupResponsiveMenu (e){
|
||||
document.querySelector('#site-navigation').addEventListener('keydown', handleSiftTabPress)
|
||||
if (window.innerWidth < 1200) {
|
||||
if(document.querySelector("#primary-menu > .menu-item:last-of-type > .sub-menu > .menu-item > .sub-menu > .menu-item, #primary-menu > .nav-menu > .page_item:last-of-type > .children > .page_item > .children > .page_item")){
|
||||
document.querySelector("#primary-menu > .menu-item:last-of-type > .sub-menu > .menu-item:last-of-type > .sub-menu > .menu-item:last-of-type, #primary-menu > .nav-menu > .page_item:last-of-type > .children > .page_item:last-of-type > .children > .page_item:last-of-type").addEventListener("keydown", handleTabPress);
|
||||
}
|
||||
else if(document.querySelector("#primary-menu > .menu-item:last-of-type > .sub-menu > .menu-item, #primary-menu > .nav-menu > .page_item:last-of-type > .children > .page_item")){
|
||||
document.querySelector("#primary-menu > .menu-item:last-of-type > .sub-menu > .menu-item:last-of-type, #primary-menu > .nav-menu > .page_item:last-of-type > .children > .page_item:last-of-type").addEventListener("keydown", handleTabPress);
|
||||
} else {
|
||||
if( document.querySelector("#primary-menu > .menu-item:last-of-type, #primary-menu > .nav-menu > .page_item:last-of-type") != null )
|
||||
document.querySelector("#primary-menu > .menu-item:last-of-type, #primary-menu > .nav-menu > .page_item:last-of-type").addEventListener("keydown", handleTabPress);
|
||||
}
|
||||
|
||||
}else{
|
||||
if( document.querySelector("#primary-menu > .menu-item:last-of-type, #primary-menu > .nav-menu > .page_item:last-of-type") != null )
|
||||
document.querySelector("#primary-menu > .menu-item:last-of-type, #primary-menu > .menu-item:last-of-type > .sub-menu > .menu-item:last-of-type, #primary-menu > .nav-menu > .page_item:last-of-type, #primary-menu > .nav-menu > .page_item:last-of-type > .children > .page_item:last-of-type").removeEventListener("keydown", handleTabPress);
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('resize', setupResponsiveMenu);
|
||||
setupResponsiveMenu();
|
||||
|
||||
|
||||
// Close small menu when user clicks outside
|
||||
document.addEventListener( 'click', function( event ) {
|
||||
var isClickInside = container.contains( event.target );
|
||||
|
||||
if ( ! isClickInside ) {
|
||||
container.className = container.className.replace( ' toggled', '' );
|
||||
button.setAttribute( 'aria-expanded', 'false' );
|
||||
}
|
||||
} );
|
||||
|
||||
// Get all the link elements within the menu.
|
||||
links = menu.getElementsByTagName( 'a' );
|
||||
|
||||
// Each time a menu link is focused or blurred, toggle focus.
|
||||
for ( i = 0, len = links.length; i < len; i++ ) {
|
||||
links[i].addEventListener( 'focus', toggleFocus, true );
|
||||
links[i].addEventListener( 'blur', toggleFocus, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or removes .focus class on an element.
|
||||
*/
|
||||
function toggleFocus() {
|
||||
var self = this;
|
||||
|
||||
// Move up through the ancestors of the current link until we hit .nav-menu.
|
||||
while ( -1 === self.className.indexOf( 'nav-menu' ) ) {
|
||||
// On li elements toggle the class .focus.
|
||||
if ( 'li' === self.tagName.toLowerCase() ) {
|
||||
if ( -1 !== self.className.indexOf( 'focus' ) ) {
|
||||
self.className = self.className.replace( ' focus', '' );
|
||||
} else {
|
||||
self.className += ' focus';
|
||||
}
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles `focus` class to allow submenu access on tablets.
|
||||
*/
|
||||
( function() {
|
||||
var touchStartFn,
|
||||
parentLink = container.querySelectorAll( '.menu-item-has-children > a, .page_item_has_children > a' );
|
||||
|
||||
if ( 'ontouchstart' in window ) {
|
||||
touchStartFn = function( e ) {
|
||||
var menuItem = this.parentNode;
|
||||
|
||||
if ( ! menuItem.classList.contains( 'focus' ) ) {
|
||||
e.preventDefault();
|
||||
for ( i = 0; i < menuItem.parentNode.children.length; ++i ) {
|
||||
if ( menuItem === menuItem.parentNode.children[i] ) {
|
||||
continue;
|
||||
}
|
||||
menuItem.parentNode.children[i].classList.remove( 'focus' );
|
||||
}
|
||||
menuItem.classList.add( 'focus' );
|
||||
} else {
|
||||
menuItem.classList.remove( 'focus' );
|
||||
}
|
||||
};
|
||||
|
||||
for ( i = 0; i < parentLink.length; ++i ) {
|
||||
parentLink[i].addEventListener( 'touchstart', touchStartFn, false );
|
||||
}
|
||||
}
|
||||
}( container ) );
|
||||
}() );
|
||||
@@ -0,0 +1,40 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var scrollToTop = document.querySelector('.scroll-to-top');
|
||||
var navToggle = document.getElementById('nav-icon3');
|
||||
var grid = document.querySelector('.blog-grid-view');
|
||||
|
||||
function updateScrollButton() {
|
||||
if (!scrollToTop) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.scrollY > 1) {
|
||||
scrollToTop.classList.add('show');
|
||||
} else {
|
||||
scrollToTop.classList.remove('show');
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollToTop) {
|
||||
updateScrollButton();
|
||||
|
||||
window.addEventListener('scroll', updateScrollButton, { passive: true });
|
||||
|
||||
scrollToTop.addEventListener('click', function (event) {
|
||||
event.preventDefault();
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
});
|
||||
}
|
||||
|
||||
if (navToggle) {
|
||||
navToggle.addEventListener('click', function () {
|
||||
navToggle.classList.toggle('open');
|
||||
});
|
||||
}
|
||||
|
||||
if (grid && typeof Masonry !== 'undefined') {
|
||||
new Masonry(grid, {
|
||||
itemSelector: '.type-post'
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,243 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var toc = document.getElementById('zeitfresser-floating-toc');
|
||||
var title = document.querySelector('.zeitfresser-article-heading .page-title, .zeitfresser-article-heading .entry-title, .entry-header .entry-title');
|
||||
var progressBar = document.getElementById('zeitfresser-floating-toc-progress');
|
||||
var nav = toc ? toc.querySelector('.zeitfresser-floating-toc__nav') : null;
|
||||
|
||||
if (!toc || !title) {
|
||||
return;
|
||||
}
|
||||
|
||||
var links = Array.prototype.slice.call(toc.querySelectorAll('a[data-target]'));
|
||||
var desktopQuery = window.matchMedia('(min-width: 1500px)');
|
||||
var stickyTop = 100;
|
||||
var headingOffset = 88;
|
||||
var ticking = false;
|
||||
|
||||
var tocBottomOffset = null;
|
||||
|
||||
function isDesktop() {
|
||||
return desktopQuery.matches;
|
||||
}
|
||||
|
||||
function getTarget(link) {
|
||||
var id = link.getAttribute('data-target');
|
||||
return id ? document.getElementById(id) : null;
|
||||
}
|
||||
|
||||
function getHeadings() {
|
||||
return links.map(function (link) {
|
||||
return {
|
||||
link: link,
|
||||
target: getTarget(link)
|
||||
};
|
||||
}).filter(function (item) {
|
||||
return !!item.target;
|
||||
});
|
||||
}
|
||||
|
||||
function getArticleElement() {
|
||||
return document.querySelector(
|
||||
'.single-post .post-content article, ' +
|
||||
'.single-post .post-content, ' +
|
||||
'article.post, article, ' +
|
||||
'.entry-content'
|
||||
);
|
||||
}
|
||||
|
||||
function getTocBottomOffset() {
|
||||
if (tocBottomOffset !== null) return tocBottomOffset;
|
||||
|
||||
var value = getComputedStyle(document.documentElement)
|
||||
.getPropertyValue('--toc-bottom-offset')
|
||||
.trim();
|
||||
|
||||
tocBottomOffset = parseInt(value, 10) || 12;
|
||||
return tocBottomOffset;
|
||||
}
|
||||
|
||||
function syncPosition() {
|
||||
if (!isDesktop()) {
|
||||
document.documentElement.style.setProperty('--zeitfresser-toc-top', stickyTop + 'px');
|
||||
document.documentElement.style.setProperty('--zeitfresser-toc-left', '24px');
|
||||
document.documentElement.style.setProperty('--zeitfresser-toc-width', '220px');
|
||||
return;
|
||||
}
|
||||
|
||||
var titleRect = title.getBoundingClientRect();
|
||||
var scrollTop = window.scrollY || window.pageYOffset || 0;
|
||||
|
||||
var contentColumn = document.querySelector(
|
||||
'.inside-page .main-wrapper > *:first-child, ' +
|
||||
'.inside-page .main-wrapper .primary-content, ' +
|
||||
'.inside-page .main-wrapper #primary, ' +
|
||||
'.inside-page .main-wrapper main'
|
||||
);
|
||||
|
||||
var sidebar = document.querySelector(
|
||||
'.inside-page .main-wrapper > aside, ' +
|
||||
'.inside-page .main-wrapper .widget-area, ' +
|
||||
'.inside-page .main-wrapper #secondary, ' +
|
||||
'.inside-page .main-wrapper .sidebar'
|
||||
);
|
||||
|
||||
var contentRect = contentColumn ? contentColumn.getBoundingClientRect() : titleRect;
|
||||
var sidebarRect = sidebar ? sidebar.getBoundingClientRect() : null;
|
||||
|
||||
var mirroredGap = 56;
|
||||
|
||||
if (sidebarRect) {
|
||||
mirroredGap = Math.max(Math.round(sidebarRect.left - contentRect.right), 40);
|
||||
}
|
||||
|
||||
var maxWidth = Math.max(Math.round(contentRect.left - mirroredGap - 24), 180);
|
||||
var tocWidth = Math.max(190, Math.min(250, maxWidth));
|
||||
var tocLeft = Math.max(24, Math.round(contentRect.left - mirroredGap - tocWidth));
|
||||
var tocTop = Math.max(stickyTop, Math.round(titleRect.top + scrollTop + 14));
|
||||
|
||||
document.documentElement.style.setProperty('--zeitfresser-toc-top', tocTop + 'px');
|
||||
document.documentElement.style.setProperty('--zeitfresser-toc-left', tocLeft + 'px');
|
||||
document.documentElement.style.setProperty('--zeitfresser-toc-width', tocWidth + 'px');
|
||||
}
|
||||
|
||||
function handleFooterCollision() {
|
||||
if (!isDesktop()) {
|
||||
toc.style.transform = '';
|
||||
return;
|
||||
}
|
||||
|
||||
var article = getArticleElement();
|
||||
|
||||
if (!article) {
|
||||
toc.style.transform = '';
|
||||
return;
|
||||
}
|
||||
|
||||
toc.style.transform = '';
|
||||
|
||||
var scrollTop = window.scrollY || window.pageYOffset;
|
||||
|
||||
var articleRect = article.getBoundingClientRect();
|
||||
var articleBottom = articleRect.top + scrollTop + articleRect.height;
|
||||
|
||||
var tocRect = toc.getBoundingClientRect();
|
||||
var tocTop = tocRect.top + scrollTop;
|
||||
var tocHeight = tocRect.height;
|
||||
var tocBottom = tocTop + tocHeight;
|
||||
|
||||
var offset = getTocBottomOffset();
|
||||
|
||||
var maxBottom = articleBottom - offset;
|
||||
var overflow = Math.ceil(tocBottom - maxBottom);
|
||||
|
||||
if (overflow > 0) {
|
||||
toc.style.transform = 'translateY(-' + overflow + 'px)';
|
||||
}
|
||||
}
|
||||
|
||||
function setActiveLink(id) {
|
||||
links.forEach(function (link) {
|
||||
var active = link.getAttribute('data-target') === id;
|
||||
link.classList.toggle('is-active', active);
|
||||
|
||||
if (active) {
|
||||
link.setAttribute('aria-current', 'true');
|
||||
} else {
|
||||
link.removeAttribute('aria-current');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateProgress() {
|
||||
if (!progressBar) return;
|
||||
|
||||
var article = getArticleElement();
|
||||
|
||||
if (!article) {
|
||||
progressBar.style.width = '0%';
|
||||
return;
|
||||
}
|
||||
|
||||
var rect = article.getBoundingClientRect();
|
||||
var total = Math.max(article.offsetHeight - window.innerHeight, 1);
|
||||
var progress = Math.min(Math.max((-rect.top / total) * 100, 0), 100);
|
||||
|
||||
progressBar.style.width = progress + '%';
|
||||
}
|
||||
|
||||
function updateActiveHeading() {
|
||||
var headings = getHeadings();
|
||||
if (!headings.length) return;
|
||||
|
||||
var currentId = headings[0].target.id;
|
||||
var triggerY = headingOffset + 24;
|
||||
|
||||
headings.forEach(function (item) {
|
||||
if (item.target.getBoundingClientRect().top <= triggerY) {
|
||||
currentId = item.target.id;
|
||||
}
|
||||
});
|
||||
|
||||
setActiveLink(currentId);
|
||||
}
|
||||
|
||||
function onViewportChange() {
|
||||
if (ticking) return;
|
||||
|
||||
ticking = true;
|
||||
|
||||
window.requestAnimationFrame(function () {
|
||||
syncPosition();
|
||||
handleFooterCollision();
|
||||
updateProgress();
|
||||
updateActiveHeading();
|
||||
ticking = false;
|
||||
});
|
||||
}
|
||||
|
||||
links.forEach(function (link) {
|
||||
link.addEventListener('click', function (event) {
|
||||
var target = getTarget(link);
|
||||
if (!target) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var top = target.getBoundingClientRect().top + window.scrollY - headingOffset;
|
||||
|
||||
window.scrollTo({
|
||||
top: top,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
|
||||
setActiveLink(target.id);
|
||||
});
|
||||
});
|
||||
|
||||
if (nav) {
|
||||
nav.addEventListener('wheel', function (event) {
|
||||
var canScroll = nav.scrollHeight > nav.clientHeight;
|
||||
if (!canScroll) return;
|
||||
|
||||
var atTop = nav.scrollTop <= 0;
|
||||
var atBottom = Math.ceil(nav.scrollTop + nav.clientHeight) >= nav.scrollHeight;
|
||||
|
||||
if ((event.deltaY < 0 && !atTop) || (event.deltaY > 0 && !atBottom)) {
|
||||
event.preventDefault();
|
||||
nav.scrollTop += event.deltaY;
|
||||
}
|
||||
}, { passive: false });
|
||||
}
|
||||
|
||||
// Initial run
|
||||
syncPosition();
|
||||
handleFooterCollision();
|
||||
updateProgress();
|
||||
updateActiveHeading();
|
||||
|
||||
requestAnimationFrame(function () {
|
||||
toc.classList.add('is-visible');
|
||||
});
|
||||
|
||||
window.addEventListener('scroll', onViewportChange, { passive: true });
|
||||
window.addEventListener('resize', onViewportChange, { passive: true });
|
||||
});
|
||||
Reference in New Issue
Block a user