Edit File by line
/home/barbar84/public_h.../wp-conte.../themes/twentyni.../js
File: priority-menu.js
(function() {
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Debounce.
[3] Fix | Delete
*
[4] Fix | Delete
* @param {Function} func
[5] Fix | Delete
* @param {number} wait
[6] Fix | Delete
* @param {boolean} immediate
[7] Fix | Delete
*/
[8] Fix | Delete
function debounce(func, wait, immediate) {
[9] Fix | Delete
'use strict';
[10] Fix | Delete
[11] Fix | Delete
var timeout;
[12] Fix | Delete
wait = (typeof wait !== 'undefined') ? wait : 20;
[13] Fix | Delete
immediate = (typeof immediate !== 'undefined') ? immediate : true;
[14] Fix | Delete
[15] Fix | Delete
return function() {
[16] Fix | Delete
[17] Fix | Delete
var context = this, args = arguments;
[18] Fix | Delete
var later = function() {
[19] Fix | Delete
timeout = null;
[20] Fix | Delete
[21] Fix | Delete
if (!immediate) {
[22] Fix | Delete
func.apply(context, args);
[23] Fix | Delete
}
[24] Fix | Delete
};
[25] Fix | Delete
[26] Fix | Delete
var callNow = immediate && !timeout;
[27] Fix | Delete
[28] Fix | Delete
clearTimeout(timeout);
[29] Fix | Delete
timeout = setTimeout(later, wait);
[30] Fix | Delete
[31] Fix | Delete
if (callNow) {
[32] Fix | Delete
func.apply(context, args);
[33] Fix | Delete
}
[34] Fix | Delete
};
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Prepends an element to a container.
[39] Fix | Delete
*
[40] Fix | Delete
* @param {Element} container
[41] Fix | Delete
* @param {Element} element
[42] Fix | Delete
*/
[43] Fix | Delete
function prependElement(container, element) {
[44] Fix | Delete
if (container.firstChild.nextSibling) {
[45] Fix | Delete
return container.insertBefore(element, container.firstChild.nextSibling);
[46] Fix | Delete
} else {
[47] Fix | Delete
return container.appendChild(element);
[48] Fix | Delete
}
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Shows an element by adding a hidden className.
[53] Fix | Delete
*
[54] Fix | Delete
* @param {Element} element
[55] Fix | Delete
*/
[56] Fix | Delete
function showButton(element) {
[57] Fix | Delete
// classList.remove is not supported in IE11.
[58] Fix | Delete
element.className = element.className.replace('is-empty', '');
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Hides an element by removing the hidden className.
[63] Fix | Delete
*
[64] Fix | Delete
* @param {Element} element
[65] Fix | Delete
*/
[66] Fix | Delete
function hideButton(element) {
[67] Fix | Delete
// classList.add is not supported in IE11.
[68] Fix | Delete
if (!element.classList.contains('is-empty')) {
[69] Fix | Delete
element.className += ' is-empty';
[70] Fix | Delete
}
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Returns the currently available space in the menu container.
[75] Fix | Delete
*
[76] Fix | Delete
* @returns {number} Available space
[77] Fix | Delete
*/
[78] Fix | Delete
function getAvailableSpace( button, container ) {
[79] Fix | Delete
return container.offsetWidth - button.offsetWidth - 22;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Returns whether the current menu is overflowing or not.
[84] Fix | Delete
*
[85] Fix | Delete
* @returns {boolean} Is overflowing
[86] Fix | Delete
*/
[87] Fix | Delete
function isOverflowingNavivation( list, button, container ) {
[88] Fix | Delete
return list.offsetWidth > getAvailableSpace( button, container );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Set menu container variable.
[93] Fix | Delete
*/
[94] Fix | Delete
var navContainer = document.querySelector('.main-navigation');
[95] Fix | Delete
var breaks = [];
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Let’s bail if we our menu doesn't exist.
[99] Fix | Delete
*/
[100] Fix | Delete
if ( ! navContainer ) {
[101] Fix | Delete
return;
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Refreshes the list item from the menu depending on the menu size.
[106] Fix | Delete
*/
[107] Fix | Delete
function updateNavigationMenu( container ) {
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Let’s bail if our menu is empty.
[111] Fix | Delete
*/
[112] Fix | Delete
if ( ! container.parentNode.querySelector('.main-menu[id]') ) {
[113] Fix | Delete
return;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
// Adds the necessary UI to operate the menu.
[117] Fix | Delete
var visibleList = container.parentNode.querySelector('.main-menu[id]');
[118] Fix | Delete
var hiddenList = visibleList.parentNode.nextElementSibling.querySelector('.hidden-links');
[119] Fix | Delete
var toggleButton = visibleList.parentNode.nextElementSibling.querySelector('.main-menu-more-toggle');
[120] Fix | Delete
[121] Fix | Delete
if ( isOverflowingNavivation( visibleList, toggleButton, container ) ) {
[122] Fix | Delete
[123] Fix | Delete
// Record the width of the list.
[124] Fix | Delete
breaks.push( visibleList.offsetWidth );
[125] Fix | Delete
// Move last item to the hidden list.
[126] Fix | Delete
prependElement( hiddenList, ! visibleList.lastChild || null === visibleList.lastChild ? visibleList.previousElementSibling : visibleList.lastChild );
[127] Fix | Delete
// Show the toggle button.
[128] Fix | Delete
showButton( toggleButton );
[129] Fix | Delete
[130] Fix | Delete
} else {
[131] Fix | Delete
[132] Fix | Delete
// There is space for another item in the nav.
[133] Fix | Delete
if ( getAvailableSpace( toggleButton, container ) > breaks[breaks.length - 1] ) {
[134] Fix | Delete
// Move the item to the visible list.
[135] Fix | Delete
visibleList.appendChild( hiddenList.firstChild.nextSibling );
[136] Fix | Delete
breaks.pop();
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
// Hide the dropdown btn if hidden list is empty.
[140] Fix | Delete
if (breaks.length < 2) {
[141] Fix | Delete
hideButton( toggleButton );
[142] Fix | Delete
}
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
// Recur if the visible list is still overflowing the nav.
[146] Fix | Delete
if ( isOverflowingNavivation( visibleList, toggleButton, container ) ) {
[147] Fix | Delete
updateNavigationMenu( container );
[148] Fix | Delete
}
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Run our priority+ function as soon as the document is `ready`.
[153] Fix | Delete
*/
[154] Fix | Delete
document.addEventListener( 'DOMContentLoaded', function() {
[155] Fix | Delete
[156] Fix | Delete
updateNavigationMenu( navContainer );
[157] Fix | Delete
[158] Fix | Delete
// Also, run our priority+ function on selective refresh in the customizer.
[159] Fix | Delete
var hasSelectiveRefresh = (
[160] Fix | Delete
'undefined' !== typeof wp &&
[161] Fix | Delete
wp.customize &&
[162] Fix | Delete
wp.customize.selectiveRefresh &&
[163] Fix | Delete
wp.customize.navMenusPreview.NavMenuInstancePartial
[164] Fix | Delete
);
[165] Fix | Delete
[166] Fix | Delete
if ( hasSelectiveRefresh ) {
[167] Fix | Delete
// Re-run our priority+ function on Nav Menu partial refreshes.
[168] Fix | Delete
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function ( placement ) {
[169] Fix | Delete
[170] Fix | Delete
var isNewNavMenu = (
[171] Fix | Delete
placement &&
[172] Fix | Delete
placement.partial.id.includes( 'nav_menu_instance' ) &&
[173] Fix | Delete
'null' !== placement.container[0].parentNode &&
[174] Fix | Delete
placement.container[0].parentNode.classList.contains( 'main-navigation' )
[175] Fix | Delete
);
[176] Fix | Delete
[177] Fix | Delete
if ( isNewNavMenu ) {
[178] Fix | Delete
updateNavigationMenu( placement.container[0].parentNode );
[179] Fix | Delete
}
[180] Fix | Delete
});
[181] Fix | Delete
}
[182] Fix | Delete
});
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Run our priority+ function on load.
[186] Fix | Delete
*/
[187] Fix | Delete
window.addEventListener( 'load', function() {
[188] Fix | Delete
updateNavigationMenu( navContainer );
[189] Fix | Delete
});
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Run our priority+ function every time the window resizes.
[193] Fix | Delete
*/
[194] Fix | Delete
var isResizing = false;
[195] Fix | Delete
window.addEventListener( 'resize',
[196] Fix | Delete
debounce( function() {
[197] Fix | Delete
if ( isResizing ) {
[198] Fix | Delete
return;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
isResizing = true;
[202] Fix | Delete
setTimeout( function() {
[203] Fix | Delete
updateNavigationMenu( navContainer );
[204] Fix | Delete
isResizing = false;
[205] Fix | Delete
}, 150 );
[206] Fix | Delete
} )
[207] Fix | Delete
);
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Run our priority+ function.
[211] Fix | Delete
*/
[212] Fix | Delete
updateNavigationMenu( navContainer );
[213] Fix | Delete
[214] Fix | Delete
})();
[215] Fix | Delete
[216] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function