Edit File by line
/home/barbar84/www/wp-conte.../themes/twentytw.../assets/js
File: index.js
target = toggle.nextSibling;
[500] Fix | Delete
} else {
[501] Fix | Delete
target = _doc.querySelector( targetString );
[502] Fix | Delete
}
[503] Fix | Delete
[504] Fix | Delete
// Trigger events on the toggle targets before they are toggled.
[505] Fix | Delete
if ( target.classList.contains( activeClass ) ) {
[506] Fix | Delete
target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-before-active' ) );
[507] Fix | Delete
} else {
[508] Fix | Delete
target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-before-inactive' ) );
[509] Fix | Delete
}
[510] Fix | Delete
[511] Fix | Delete
// Get the class to toggle, if specified.
[512] Fix | Delete
classToToggle = toggle.dataset.classToToggle ? toggle.dataset.classToToggle : activeClass;
[513] Fix | Delete
[514] Fix | Delete
// For cover modals, set a short timeout duration so the class animations have time to play out.
[515] Fix | Delete
timeOutTime = 0;
[516] Fix | Delete
[517] Fix | Delete
if ( target.classList.contains( 'cover-modal' ) ) {
[518] Fix | Delete
timeOutTime = 10;
[519] Fix | Delete
}
[520] Fix | Delete
[521] Fix | Delete
setTimeout( function() {
[522] Fix | Delete
var focusElement,
[523] Fix | Delete
subMenued = target.classList.contains( 'sub-menu' ),
[524] Fix | Delete
newTarget = subMenued ? toggle.closest( '.menu-item' ).querySelector( '.sub-menu' ) : target,
[525] Fix | Delete
duration = toggle.dataset.toggleDuration;
[526] Fix | Delete
[527] Fix | Delete
// Toggle the target of the clicked toggle.
[528] Fix | Delete
if ( toggle.dataset.toggleType === 'slidetoggle' && ! instantly && duration !== '0' ) {
[529] Fix | Delete
twentytwentyMenuToggle( newTarget, duration );
[530] Fix | Delete
} else {
[531] Fix | Delete
newTarget.classList.toggle( classToToggle );
[532] Fix | Delete
}
[533] Fix | Delete
[534] Fix | Delete
// If the toggle target is 'next', only give the clicked toggle the active class.
[535] Fix | Delete
if ( targetString === 'next' ) {
[536] Fix | Delete
toggle.classList.toggle( activeClass );
[537] Fix | Delete
} else if ( target.classList.contains( 'sub-menu' ) ) {
[538] Fix | Delete
toggle.classList.toggle( activeClass );
[539] Fix | Delete
} else {
[540] Fix | Delete
// If not, toggle all toggles with this toggle target.
[541] Fix | Delete
_doc.querySelector( '*[data-toggle-target="' + targetString + '"]' ).classList.toggle( activeClass );
[542] Fix | Delete
}
[543] Fix | Delete
[544] Fix | Delete
// Toggle aria-expanded on the toggle.
[545] Fix | Delete
twentytwentyToggleAttribute( toggle, 'aria-expanded', 'true', 'false' );
[546] Fix | Delete
[547] Fix | Delete
if ( self.clickedEl && -1 !== toggle.getAttribute( 'class' ).indexOf( 'close-' ) ) {
[548] Fix | Delete
twentytwentyToggleAttribute( self.clickedEl, 'aria-expanded', 'true', 'false' );
[549] Fix | Delete
}
[550] Fix | Delete
[551] Fix | Delete
// Toggle body class.
[552] Fix | Delete
if ( toggle.dataset.toggleBodyClass ) {
[553] Fix | Delete
_doc.body.classList.toggle( toggle.dataset.toggleBodyClass );
[554] Fix | Delete
}
[555] Fix | Delete
[556] Fix | Delete
// Check whether to set focus.
[557] Fix | Delete
if ( toggle.dataset.setFocus ) {
[558] Fix | Delete
focusElement = _doc.querySelector( toggle.dataset.setFocus );
[559] Fix | Delete
[560] Fix | Delete
if ( focusElement ) {
[561] Fix | Delete
if ( target.classList.contains( activeClass ) ) {
[562] Fix | Delete
focusElement.focus();
[563] Fix | Delete
} else {
[564] Fix | Delete
focusElement.blur();
[565] Fix | Delete
}
[566] Fix | Delete
}
[567] Fix | Delete
}
[568] Fix | Delete
[569] Fix | Delete
// Trigger the toggled event on the toggle target.
[570] Fix | Delete
target.dispatchEvent( twentytwenty.createEvent( 'toggled' ) );
[571] Fix | Delete
[572] Fix | Delete
// Trigger events on the toggle targets after they are toggled.
[573] Fix | Delete
if ( target.classList.contains( activeClass ) ) {
[574] Fix | Delete
target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-after-active' ) );
[575] Fix | Delete
} else {
[576] Fix | Delete
target.dispatchEvent( twentytwenty.createEvent( 'toggle-target-after-inactive' ) );
[577] Fix | Delete
}
[578] Fix | Delete
}, timeOutTime );
[579] Fix | Delete
},
[580] Fix | Delete
[581] Fix | Delete
// Do the toggle.
[582] Fix | Delete
toggle: function() {
[583] Fix | Delete
var self = this;
[584] Fix | Delete
[585] Fix | Delete
document.querySelectorAll( '*[data-toggle-target]' ).forEach( function( element ) {
[586] Fix | Delete
element.addEventListener( 'click', function( event ) {
[587] Fix | Delete
event.preventDefault();
[588] Fix | Delete
self.performToggle( element );
[589] Fix | Delete
} );
[590] Fix | Delete
} );
[591] Fix | Delete
},
[592] Fix | Delete
[593] Fix | Delete
// Check for toggle/untoggle on screen resize.
[594] Fix | Delete
resizeCheck: function() {
[595] Fix | Delete
if ( document.querySelectorAll( '*[data-untoggle-above], *[data-untoggle-below], *[data-toggle-above], *[data-toggle-below]' ).length ) {
[596] Fix | Delete
window.addEventListener( 'resize', function() {
[597] Fix | Delete
var winWidth = window.innerWidth,
[598] Fix | Delete
toggles = document.querySelectorAll( '.toggle' );
[599] Fix | Delete
[600] Fix | Delete
toggles.forEach( function( toggle ) {
[601] Fix | Delete
var unToggleAbove = toggle.dataset.untoggleAbove,
[602] Fix | Delete
unToggleBelow = toggle.dataset.untoggleBelow,
[603] Fix | Delete
toggleAbove = toggle.dataset.toggleAbove,
[604] Fix | Delete
toggleBelow = toggle.dataset.toggleBelow;
[605] Fix | Delete
[606] Fix | Delete
// If no width comparison is set, continue.
[607] Fix | Delete
if ( ! unToggleAbove && ! unToggleBelow && ! toggleAbove && ! toggleBelow ) {
[608] Fix | Delete
return;
[609] Fix | Delete
}
[610] Fix | Delete
[611] Fix | Delete
// If the toggle width comparison is true, toggle the toggle.
[612] Fix | Delete
if (
[613] Fix | Delete
( ( ( unToggleAbove && winWidth > unToggleAbove ) ||
[614] Fix | Delete
( unToggleBelow && winWidth < unToggleBelow ) ) &&
[615] Fix | Delete
toggle.classList.contains( 'active' ) ) ||
[616] Fix | Delete
( ( ( toggleAbove && winWidth > toggleAbove ) ||
[617] Fix | Delete
( toggleBelow && winWidth < toggleBelow ) ) &&
[618] Fix | Delete
! toggle.classList.contains( 'active' ) )
[619] Fix | Delete
) {
[620] Fix | Delete
toggle.click();
[621] Fix | Delete
}
[622] Fix | Delete
} );
[623] Fix | Delete
} );
[624] Fix | Delete
}
[625] Fix | Delete
},
[626] Fix | Delete
[627] Fix | Delete
// Close toggle on escape key press.
[628] Fix | Delete
untoggleOnEscapeKeyPress: function() {
[629] Fix | Delete
document.addEventListener( 'keyup', function( event ) {
[630] Fix | Delete
if ( event.key === 'Escape' ) {
[631] Fix | Delete
document.querySelectorAll( '*[data-untoggle-on-escape].active' ).forEach( function( element ) {
[632] Fix | Delete
if ( element.classList.contains( 'active' ) ) {
[633] Fix | Delete
element.click();
[634] Fix | Delete
}
[635] Fix | Delete
} );
[636] Fix | Delete
}
[637] Fix | Delete
} );
[638] Fix | Delete
}
[639] Fix | Delete
[640] Fix | Delete
}; // twentytwenty.toggles
[641] Fix | Delete
[642] Fix | Delete
/**
[643] Fix | Delete
* Is the DOM ready?
[644] Fix | Delete
*
[645] Fix | Delete
* This implementation is coming from https://gomakethings.com/a-native-javascript-equivalent-of-jquerys-ready-method/
[646] Fix | Delete
*
[647] Fix | Delete
* @param {Function} fn Callback function to run.
[648] Fix | Delete
*/
[649] Fix | Delete
function twentytwentyDomReady( fn ) {
[650] Fix | Delete
if ( typeof fn !== 'function' ) {
[651] Fix | Delete
return;
[652] Fix | Delete
}
[653] Fix | Delete
[654] Fix | Delete
if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
[655] Fix | Delete
return fn();
[656] Fix | Delete
}
[657] Fix | Delete
[658] Fix | Delete
document.addEventListener( 'DOMContentLoaded', fn, false );
[659] Fix | Delete
}
[660] Fix | Delete
[661] Fix | Delete
twentytwentyDomReady( function() {
[662] Fix | Delete
twentytwenty.toggles.init(); // Handle toggles.
[663] Fix | Delete
twentytwenty.coverModals.init(); // Handle cover modals.
[664] Fix | Delete
twentytwenty.intrinsicRatioVideos.init(); // Retain aspect ratio of videos on window resize.
[665] Fix | Delete
twentytwenty.modalMenu.init(); // Modal Menu.
[666] Fix | Delete
twentytwenty.primaryMenu.init(); // Primary Menu.
[667] Fix | Delete
twentytwenty.touchEnabled.init(); // Add class to body if device is touch-enabled.
[668] Fix | Delete
} );
[669] Fix | Delete
[670] Fix | Delete
/* -----------------------------------------------------------------------------------------------
[671] Fix | Delete
Helper functions
[672] Fix | Delete
--------------------------------------------------------------------------------------------------- */
[673] Fix | Delete
[674] Fix | Delete
/* Toggle an attribute ----------------------- */
[675] Fix | Delete
[676] Fix | Delete
function twentytwentyToggleAttribute( element, attribute, trueVal, falseVal ) {
[677] Fix | Delete
if ( trueVal === undefined ) {
[678] Fix | Delete
trueVal = true;
[679] Fix | Delete
}
[680] Fix | Delete
if ( falseVal === undefined ) {
[681] Fix | Delete
falseVal = false;
[682] Fix | Delete
}
[683] Fix | Delete
if ( element.getAttribute( attribute ) !== trueVal ) {
[684] Fix | Delete
element.setAttribute( attribute, trueVal );
[685] Fix | Delete
} else {
[686] Fix | Delete
element.setAttribute( attribute, falseVal );
[687] Fix | Delete
}
[688] Fix | Delete
}
[689] Fix | Delete
[690] Fix | Delete
/**
[691] Fix | Delete
* Toggle a menu item on or off.
[692] Fix | Delete
*
[693] Fix | Delete
* @param {HTMLElement} target
[694] Fix | Delete
* @param {number} duration
[695] Fix | Delete
*/
[696] Fix | Delete
function twentytwentyMenuToggle( target, duration ) {
[697] Fix | Delete
var initialParentHeight, finalParentHeight, menu, menuItems, transitionListener,
[698] Fix | Delete
initialPositions = [],
[699] Fix | Delete
finalPositions = [];
[700] Fix | Delete
[701] Fix | Delete
if ( ! target ) {
[702] Fix | Delete
return;
[703] Fix | Delete
}
[704] Fix | Delete
[705] Fix | Delete
menu = target.closest( '.menu-wrapper' );
[706] Fix | Delete
[707] Fix | Delete
// Step 1: look at the initial positions of every menu item.
[708] Fix | Delete
menuItems = menu.querySelectorAll( '.menu-item' );
[709] Fix | Delete
[710] Fix | Delete
menuItems.forEach( function( menuItem, index ) {
[711] Fix | Delete
initialPositions[ index ] = { x: menuItem.offsetLeft, y: menuItem.offsetTop };
[712] Fix | Delete
} );
[713] Fix | Delete
initialParentHeight = target.parentElement.offsetHeight;
[714] Fix | Delete
[715] Fix | Delete
target.classList.add( 'toggling-target' );
[716] Fix | Delete
[717] Fix | Delete
// Step 2: toggle target menu item and look at the final positions of every menu item.
[718] Fix | Delete
target.classList.toggle( 'active' );
[719] Fix | Delete
[720] Fix | Delete
menuItems.forEach( function( menuItem, index ) {
[721] Fix | Delete
finalPositions[ index ] = { x: menuItem.offsetLeft, y: menuItem.offsetTop };
[722] Fix | Delete
} );
[723] Fix | Delete
finalParentHeight = target.parentElement.offsetHeight;
[724] Fix | Delete
[725] Fix | Delete
// Step 3: close target menu item again.
[726] Fix | Delete
// The whole process happens without giving the browser a chance to render, so it's invisible.
[727] Fix | Delete
target.classList.toggle( 'active' );
[728] Fix | Delete
[729] Fix | Delete
/*
[730] Fix | Delete
* Step 4: prepare animation.
[731] Fix | Delete
* Position all the items with absolute offsets, at the same starting position.
[732] Fix | Delete
* Shouldn't result in any visual changes if done right.
[733] Fix | Delete
*/
[734] Fix | Delete
menu.classList.add( 'is-toggling' );
[735] Fix | Delete
target.classList.toggle( 'active' );
[736] Fix | Delete
menuItems.forEach( function( menuItem, index ) {
[737] Fix | Delete
var initialPosition = initialPositions[ index ];
[738] Fix | Delete
if ( initialPosition.y === 0 && menuItem.parentElement === target ) {
[739] Fix | Delete
initialPosition.y = initialParentHeight;
[740] Fix | Delete
}
[741] Fix | Delete
menuItem.style.transform = 'translate(' + initialPosition.x + 'px, ' + initialPosition.y + 'px)';
[742] Fix | Delete
} );
[743] Fix | Delete
[744] Fix | Delete
/*
[745] Fix | Delete
* The double rAF is unfortunately needed, since we're toggling CSS classes, and
[746] Fix | Delete
* the only way to ensure layout completion here across browsers is to wait twice.
[747] Fix | Delete
* This just delays the start of the animation by 2 frames and is thus not an issue.
[748] Fix | Delete
*/
[749] Fix | Delete
requestAnimationFrame( function() {
[750] Fix | Delete
requestAnimationFrame( function() {
[751] Fix | Delete
/*
[752] Fix | Delete
* Step 5: start animation by moving everything to final position.
[753] Fix | Delete
* All the layout work has already happened, while we were preparing for the animation.
[754] Fix | Delete
* The animation now runs entirely in CSS, using cheap CSS properties (opacity and transform)
[755] Fix | Delete
* that don't trigger the layout or paint stages.
[756] Fix | Delete
*/
[757] Fix | Delete
menu.classList.add( 'is-animating' );
[758] Fix | Delete
menuItems.forEach( function( menuItem, index ) {
[759] Fix | Delete
var finalPosition = finalPositions[ index ];
[760] Fix | Delete
if ( finalPosition.y === 0 && menuItem.parentElement === target ) {
[761] Fix | Delete
finalPosition.y = finalParentHeight;
[762] Fix | Delete
}
[763] Fix | Delete
if ( duration !== undefined ) {
[764] Fix | Delete
menuItem.style.transitionDuration = duration + 'ms';
[765] Fix | Delete
}
[766] Fix | Delete
menuItem.style.transform = 'translate(' + finalPosition.x + 'px, ' + finalPosition.y + 'px)';
[767] Fix | Delete
} );
[768] Fix | Delete
if ( duration !== undefined ) {
[769] Fix | Delete
target.style.transitionDuration = duration + 'ms';
[770] Fix | Delete
}
[771] Fix | Delete
} );
[772] Fix | Delete
[773] Fix | Delete
// Step 6: finish toggling.
[774] Fix | Delete
// Remove all transient classes when the animation ends.
[775] Fix | Delete
transitionListener = function() {
[776] Fix | Delete
menu.classList.remove( 'is-animating' );
[777] Fix | Delete
menu.classList.remove( 'is-toggling' );
[778] Fix | Delete
target.classList.remove( 'toggling-target' );
[779] Fix | Delete
menuItems.forEach( function( menuItem ) {
[780] Fix | Delete
menuItem.style.transform = '';
[781] Fix | Delete
menuItem.style.transitionDuration = '';
[782] Fix | Delete
} );
[783] Fix | Delete
target.style.transitionDuration = '';
[784] Fix | Delete
target.removeEventListener( 'transitionend', transitionListener );
[785] Fix | Delete
};
[786] Fix | Delete
[787] Fix | Delete
target.addEventListener( 'transitionend', transitionListener );
[788] Fix | Delete
} );
[789] Fix | Delete
}
[790] Fix | Delete
[791] Fix | Delete
/**
[792] Fix | Delete
* Traverses the DOM up to find elements matching the query.
[793] Fix | Delete
*
[794] Fix | Delete
* @param {HTMLElement} target
[795] Fix | Delete
* @param {string} query
[796] Fix | Delete
* @return {NodeList} parents matching query
[797] Fix | Delete
*/
[798] Fix | Delete
function twentytwentyFindParents( target, query ) {
[799] Fix | Delete
var parents = [];
[800] Fix | Delete
[801] Fix | Delete
// Recursively go up the DOM adding matches to the parents array.
[802] Fix | Delete
function traverse( item ) {
[803] Fix | Delete
var parent = item.parentNode;
[804] Fix | Delete
if ( parent instanceof HTMLElement ) {
[805] Fix | Delete
if ( parent.matches( query ) ) {
[806] Fix | Delete
parents.push( parent );
[807] Fix | Delete
}
[808] Fix | Delete
traverse( parent );
[809] Fix | Delete
}
[810] Fix | Delete
}
[811] Fix | Delete
[812] Fix | Delete
traverse( target );
[813] Fix | Delete
[814] Fix | Delete
return parents;
[815] Fix | Delete
}
[816] Fix | Delete
[817] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function