1 line
No EOL
2.2 KiB
JavaScript
1 line
No EOL
2.2 KiB
JavaScript
(()=>{"use strict";const e=window.wc.__experimentalInteractivity;var o=function(e){return e[e.ESC=27]="ESC",e[e.LEFT_ARROW=37]="LEFT_ARROW",e[e.RIGHT_ARROW=39]="RIGHT_ARROW",e}(o||{});(0,e.store)({state:{},effects:{woocommerce:{watchForChangesOnAddToCartForm:e=>{const o=document.querySelector(`form[data-product_id="${e.context.woocommerce.productId}"]`);if(!o)return;const c=new MutationObserver((function(o){for(const c of o){const o=c.target.getAttribute("current-image");"attributes"===c.type&&o&&e.context.woocommerce.visibleImagesIds.includes(o)&&(e.context.woocommerce.selectedImage=o)}}));return c.observe(o,{attributes:!0}),()=>{c.disconnect()}},keyboardAccess:e=>{const{context:c,actions:t}=e;let m=!0;document.addEventListener("keydown",(n=>{var i;m&&null!==(i=c.woocommerce)&&void 0!==i&&i.isDialogOpen&&(m=!1,requestAnimationFrame((()=>{m=!0})),n.keyCode===o.ESC&&t.woocommerce.dialog.handleCloseButtonClick(e),n.keyCode===o.LEFT_ARROW&&t.woocommerce.handlePreviousImageButtonClick(e),n.keyCode===o.RIGHT_ARROW&&t.woocommerce.handleNextImageButtonClick(e))}))}}},selectors:{woocommerce:{isSelected:({context:e})=>(null==e?void 0:e.woocommerce.selectedImage)===(null==e?void 0:e.woocommerce.imageId),pagerDotFillOpacity(e){const{context:o}=e;return(null==o?void 0:o.woocommerce.selectedImage)===(null==o?void 0:o.woocommerce.imageId)?1:.2},isDialogOpen:({context:e})=>e.woocommerce.isDialogOpen}},actions:{woocommerce:{thumbnails:{handleClick:({context:e})=>{e.woocommerce.selectedImage=e.woocommerce.imageId}},dialog:{handleCloseButtonClick:({context:e})=>{e.woocommerce.isDialogOpen=!1,e.woocommerce.selectedImage=e.woocommerce.firstMainImageId}},handleSelectImage:({context:e})=>{e.woocommerce.selectedImage=e.woocommerce.imageId},handleNextImageButtonClick:e=>{const{context:o}=e,c=o.woocommerce[o.woocommerce.isDialogOpen?"dialogVisibleImagesIds":"visibleImagesIds"],t=c.indexOf(o.woocommerce.selectedImage),m=Math.min(t+1,c.length-1);o.woocommerce.selectedImage=c[m]},handlePreviousImageButtonClick:e=>{const{context:o}=e,c=o.woocommerce[o.woocommerce.isDialogOpen?"dialogVisibleImagesIds":"visibleImagesIds"],t=c.indexOf(o.woocommerce.selectedImage),m=Math.max(t-1,0);o.woocommerce.selectedImage=c[m]}}}})})(); |