blocks
1 month ago
acceptjs-echeck-handler.js
1 month ago
acceptjs-handler.js
1 month ago
blocks-authorizenet.js
1 month ago
easyauthnet-authorizenet-admin.js
1 month ago
easyauthnet-review-ajax.js
1 month ago
googlepay-express.js
1 month ago
googlepay-handler.js
1 month ago
easyauthnet-authorizenet-admin.js
116 lines
| 1 | class EPAuthorizeNetAdmin { |
| 2 | setupEnvironmentSwitching() { |
| 3 | const $envSelector = jQuery('#woocommerce_easyauthnet_authorizenet_environment'); |
| 4 | |
| 5 | const sandboxFields = [ |
| 6 | '#woocommerce_easyauthnet_authorizenet_sandbox_api_login_id', |
| 7 | '#woocommerce_easyauthnet_authorizenet_sandbox_transaction_key', |
| 8 | '#woocommerce_easyauthnet_authorizenet_sandbox_signature_key' |
| 9 | ].map(sel => jQuery(sel).closest('tr')); |
| 10 | |
| 11 | const liveFields = [ |
| 12 | '#woocommerce_easyauthnet_authorizenet_live_api_login_id', |
| 13 | '#woocommerce_easyauthnet_authorizenet_live_transaction_key', |
| 14 | '#woocommerce_easyauthnet_authorizenet_live_signature_key' |
| 15 | ].map(sel => jQuery(sel).closest('tr')); |
| 16 | |
| 17 | const toggleFields = () => { |
| 18 | const val = ($envSelector.val() || '').toLowerCase(); |
| 19 | const isSandbox = (val === 'sandbox' || val === 'test'); |
| 20 | (isSandbox ? sandboxFields : liveFields).forEach($row => $row.show()); |
| 21 | (isSandbox ? liveFields : sandboxFields).forEach($row => $row.hide()); |
| 22 | }; |
| 23 | |
| 24 | $envSelector.on('change', toggleFields); |
| 25 | toggleFields(); // initial |
| 26 | } |
| 27 | |
| 28 | setupCollapsibles() { |
| 29 | const headerSel = 'h3.easyauthnet-authorizenet-collapsible-section'; |
| 30 | const storageKey = 'easyauthnet_last_opened_section'; |
| 31 | const updateSections = () => { |
| 32 | const $headers = jQuery(headerSel); |
| 33 | const isSingle = $headers.length === 1; |
| 34 | $headers.each((_, el) => { |
| 35 | const $el = jQuery(el); |
| 36 | $el.removeClass('active'); |
| 37 | $el.nextUntil(headerSel).hide(); |
| 38 | }); |
| 39 | const lastId = localStorage.getItem(storageKey); |
| 40 | if (lastId) { |
| 41 | const $last = jQuery(`#${lastId}`); |
| 42 | if ($last.length) { |
| 43 | $last.addClass('active').nextUntil(headerSel).show(); |
| 44 | return; |
| 45 | } |
| 46 | } |
| 47 | if (isSingle) { |
| 48 | return; |
| 49 | } |
| 50 | const $first = $headers.first(); |
| 51 | if ($first.length) { |
| 52 | $first.addClass('active').nextUntil(headerSel).show(); |
| 53 | if ($first.attr('id')) { |
| 54 | localStorage.setItem(storageKey, $first.attr('id')); |
| 55 | } |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | jQuery(headerSel).on('click', function () { |
| 60 | const $this = jQuery(this); |
| 61 | const isActive = $this.hasClass('active'); |
| 62 | jQuery(`${headerSel}.active`).removeClass('active').nextUntil(headerSel).hide(); |
| 63 | if (!isActive) { |
| 64 | $this.addClass('active').nextUntil(headerSel).show(); |
| 65 | if ($this.attr('id')) { |
| 66 | localStorage.setItem(storageKey, $this.attr('id')); |
| 67 | } |
| 68 | } else { |
| 69 | localStorage.removeItem(storageKey); |
| 70 | } |
| 71 | }); |
| 72 | |
| 73 | updateSections(); |
| 74 | } |
| 75 | |
| 76 | setupCopyAndRegister() { |
| 77 | jQuery(document).on('click', '.easyauthnet-register-btn', function () { |
| 78 | const url = jQuery(this).data('url'); |
| 79 | if (url) window.open(url, '_blank'); |
| 80 | }); |
| 81 | |
| 82 | jQuery(document).on('click', '.easyauthnet-copy-link', function () { |
| 83 | const $btn = jQuery(this); |
| 84 | const link = $btn.data('link'); |
| 85 | if (!link) return; |
| 86 | |
| 87 | navigator.clipboard.writeText(link).then(() => { |
| 88 | $btn.text('Copied!').prop('disabled', true); |
| 89 | setTimeout(() => { |
| 90 | $btn.text('Copy Link').prop('disabled', false); |
| 91 | }, 1500); |
| 92 | }); |
| 93 | }); |
| 94 | } |
| 95 | |
| 96 | hideEmptyTables() { |
| 97 | document.querySelectorAll('table.form-table').forEach((table) => { |
| 98 | if (table.querySelectorAll('tr').length === 0) { |
| 99 | table.style.display = 'none'; |
| 100 | } |
| 101 | }); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | jQuery(document).ready(function () { |
| 106 | const admin = new EPAuthorizeNetAdmin(); |
| 107 | admin.setupEnvironmentSwitching(); |
| 108 | admin.setupCollapsibles(); |
| 109 | admin.setupCopyAndRegister(); |
| 110 | }); |
| 111 | |
| 112 | document.addEventListener('DOMContentLoaded', function () { |
| 113 | const admin = new EPAuthorizeNetAdmin(); |
| 114 | admin.hideEmptyTables(); |
| 115 | }); |
| 116 |