rendering-methods.js
44 lines
| 1 | jQuery( $ => { |
| 2 | const Modal = { |
| 3 | instance: false, |
| 4 | handleClick: ( e ) => { |
| 5 | e.preventDefault(); |
| 6 | Modal.open(); |
| 7 | }, |
| 8 | open: ( options = {} ) => { |
| 9 | Modal.instance = yith.ui.modal( { |
| 10 | ...yithWcwlRenderingMethods.modals.updateRenderingMethod, |
| 11 | classes: { |
| 12 | main: 'yith-wcwl-rendering-methods-modal', |
| 13 | title: 'yith-wcwl-rendering-methods-modal__title', |
| 14 | content: 'yith-wcwl-rendering-methods-modal__content', |
| 15 | footer: 'yith-wcwl-rendering-methods-modal__footer', |
| 16 | }, |
| 17 | onClose: () => (Modal.instance = false), |
| 18 | ...options |
| 19 | } ) |
| 20 | }, |
| 21 | close: () => { |
| 22 | Modal?.instance?.close(); |
| 23 | Modal.instance = false; |
| 24 | }, |
| 25 | openFromReactOnlyOptionNotice: () => { |
| 26 | Modal.open( { |
| 27 | title: yithWcwlRenderingMethods.i18n.reactOnlyOptionModalTitle |
| 28 | } ) |
| 29 | } |
| 30 | }, |
| 31 | initReactOnlyOptionsButtons = () => { |
| 32 | $( '.yith-plugin-fw__panel__option.yith-wcwl-react-only-option' ).each( ( i, el ) => { |
| 33 | const $optionRow = $( el ); |
| 34 | if ( ! $optionRow?.next()?.hasClass( 'yith-wcwl-react-only-option' ) ) { |
| 35 | $optionRow.append( yithWcwlRenderingMethods.templates.reactOnlyOptionNotice ); |
| 36 | } |
| 37 | } ) |
| 38 | } |
| 39 | |
| 40 | $( document ).on( 'click', 'a#yith-wcwl-open-rendering-methods-modal', Modal.open ); |
| 41 | $( document ).on( 'click', 'a#yith-wcwl-rendering-method-close-modal', Modal.close ); |
| 42 | $( document ).on( 'click', '.yith-wcwl-react-only-option__notice a', Modal.openFromReactOnlyOptionNotice ); |
| 43 | initReactOnlyOptionsButtons(); |
| 44 | } ); |