mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-09 04:11:10 +01:00
66 lines
9.2 KiB
JavaScript
66 lines
9.2 KiB
JavaScript
|
/******/ (function() { // webpackBootstrap
|
||
|
/******/ "use strict";
|
||
|
var __webpack_exports__ = {};
|
||
|
|
||
|
;// CONCATENATED MODULE: ./node_modules/micromodal/dist/micromodal.es.js
|
||
|
function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function t(e){return function(e){if(Array.isArray(e))return o(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return o(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return o(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function o(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,n=new Array(t);o<t;o++)n[o]=e[o];return n}var n,i,a,r,s,l=(n=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],i=function(){function o(e){var n=e.targetModal,i=e.triggers,a=void 0===i?[]:i,r=e.onShow,s=void 0===r?function(){}:r,l=e.onClose,c=void 0===l?function(){}:l,d=e.openTrigger,u=void 0===d?"data-micromodal-trigger":d,f=e.closeTrigger,h=void 0===f?"data-micromodal-close":f,v=e.openClass,g=void 0===v?"is-open":v,m=e.disableScroll,b=void 0!==m&&m,y=e.disableFocus,p=void 0!==y&&y,w=e.awaitCloseAnimation,E=void 0!==w&&w,k=e.awaitOpenAnimation,M=void 0!==k&&k,A=e.debugMode,C=void 0!==A&&A;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),this.modal=document.getElementById(n),this.config={debugMode:C,disableScroll:b,openTrigger:u,closeTrigger:h,openClass:g,onShow:s,onClose:c,awaitCloseAnimation:E,awaitOpenAnimation:M,disableFocus:p},a.length>0&&this.registerTriggers.apply(this,t(a)),this.onClick=this.onClick.bind(this),this.onKeydown=this.onKeydown.bind(this)}var i,a,r;return i=o,(a=[{key:"registerTriggers",value:function(){for(var e=this,t=arguments.length,o=new Array(t),n=0;n<t;n++)o[n]=arguments[n];o.filter(Boolean).forEach((function(t){t.addEventListener("click",(function(t){return e.showModal(t)}))}))}},{key:"showModal",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(this.activeElement=document.activeElement,this.modal.setAttribute("aria-hidden","false"),this.modal.classList.add(this.config.openClass),this.scrollBehaviour("disable"),this.addEventListeners(),this.config.awaitOpenAnimation){var o=function t(){e.modal.removeEventListener("animationend",t,!1),e.setFocusToFirstNode()};this.modal.addEventListener("animationend",o,!1)}else this.setFocusToFirstNode();this.config.onShow(this.modal,this.activeElement,t)}},{key:"closeModal",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=this.modal;if(this.modal.setAttribute("aria-hidden","true"),this.removeEventListeners(),this.scrollBehaviour("enable"),this.activeElement&&this.activeElement.focus&&this.activeElement.focus(),this.config.onClose(this.modal,this.activeElement,e),this.config.awaitCloseAnimation){var o=this.config.openClass;this.modal.addEventListener("animationend",(function e(){t.classList.remove(o),t.removeEventListener("animationend",e,!1)}),!1)}else t.classList.remove(this.config.openClass)}},{key:"closeModalById",value:function(e){this.modal=document.getElementById(e),this.modal&&this.closeModal()}},{key:"scrollBehaviour",value:function(e){if(this.config.disableScroll){var t=document.querySelector("body");switch(e){case"enable":Object.assign(t.style,{overflow:""});break;case"disable":Object.assign(t.style,{overflow:"hidden"})}}}},{key:"addEventListeners",value:function(){this.modal.addEventListener("touchstart",this.onClick),this.modal.addEventListener("click",this.onClick),document.addEventListener("keydown",this.onKeydown)
|
||
|
|
||
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/block-library/build-module/navigation/view-modal.js
|
||
|
/**
|
||
|
* External dependencies
|
||
|
*/
|
||
|
// Responsive navigation toggle.
|
||
|
|
||
|
function navigationToggleModal(modal) {
|
||
|
const dialogContainer = modal.querySelector(`.wp-block-navigation__responsive-dialog`);
|
||
|
const isHidden = 'true' === modal.getAttribute('aria-hidden');
|
||
|
modal.classList.toggle('has-modal-open', !isHidden);
|
||
|
dialogContainer.toggleAttribute('aria-modal', !isHidden);
|
||
|
|
||
|
if (isHidden) {
|
||
|
dialogContainer.removeAttribute('role');
|
||
|
dialogContainer.removeAttribute('aria-modal');
|
||
|
} else {
|
||
|
dialogContainer.setAttribute('role', 'dialog');
|
||
|
dialogContainer.setAttribute('aria-modal', 'true');
|
||
|
} // Add a class to indicate the modal is open.
|
||
|
|
||
|
|
||
|
const htmlElement = document.documentElement;
|
||
|
htmlElement.classList.toggle('has-modal-open');
|
||
|
}
|
||
|
|
||
|
window.addEventListener('load', () => {
|
||
|
micromodal_es.init({
|
||
|
onShow: navigationToggleModal,
|
||
|
onClose: navigationToggleModal,
|
||
|
openClass: 'is-menu-open'
|
||
|
}); // Close modal automatically on clicking anchor links inside modal.
|
||
|
|
||
|
const navigationLinks = document.querySelectorAll('.wp-block-navigation-item__content');
|
||
|
navigationLinks.forEach(function (link) {
|
||
|
var _link$getAttribute, _link$attributes;
|
||
|
|
||
|
// Ignore non-anchor links and anchor links which open on a new tab.
|
||
|
if (!((_link$getAttribute = link.getAttribute('href')) !== null && _link$getAttribute !== void 0 && _link$getAttribute.startsWith('#')) || ((_link$attributes = link.attributes) === null || _link$attributes === void 0 ? void 0 : _link$attributes.target) === '_blank') {
|
||
|
return;
|
||
|
} // Find the specific parent modal for this link
|
||
|
// since .close() won't work without an ID if there are
|
||
|
// multiple navigation menus in a post/page.
|
||
|
|
||
|
|
||
|
const modal = link.closest('.wp-block-navigation__responsive-container');
|
||
|
const modalId = modal === null || modal === void 0 ? void 0 : modal.getAttribute('id');
|
||
|
link.addEventListener('click', () => {
|
||
|
// check if modal exists and is open before trying to close it
|
||
|
// otherwise Micromodal will toggle the `has-modal-open` class
|
||
|
// on the html tag which prevents scrolling
|
||
|
if (modalId && modal.classList.contains('has-modal-open')) {
|
||
|
micromodal_es.close(modalId);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|
||
|
/******/ })()
|
||
|
;
|