chart.js
1 month ago
chart.min.js
1 month ago
digital-files-chooser.js
1 month ago
fusewp.js
1 month ago
index.php
1 month ago
license.js
1 month ago
login-redirect.js
1 month ago
reports.js
1 month ago
reports.min.js
1 month ago
tax-rate-repeater.js
1 month ago
license.js
135 lines
| 1 | (function ($) { |
| 2 | /** |
| 3 | * Displays Connect error message and/or reloads the page if needed. |
| 4 | * |
| 5 | * @param {Object} response JSON response data. |
| 6 | * @param {string} response.message Error message. |
| 7 | * @param {boolean} response.reload Whether to reload the page. |
| 8 | */ |
| 9 | function onConnectError(response) { |
| 10 | var feedbackEl = document.getElementById( |
| 11 | 'ppress-connect-license-feedback' |
| 12 | ); |
| 13 | |
| 14 | var submitButtonEl = document.getElementById( |
| 15 | 'ppress-connect-license-submit' |
| 16 | ); |
| 17 | |
| 18 | // Toggle feedback. |
| 19 | if (response.message) { |
| 20 | feedbackEl.innerText = response.message; |
| 21 | feedbackEl.classList.remove('ppress-license-message--valid'); |
| 22 | feedbackEl.classList.add('ppress-license-message--invalid'); |
| 23 | feedbackEl.style.display = 'block'; |
| 24 | } else { |
| 25 | feedbackEl.style.display = 'none'; |
| 26 | } |
| 27 | |
| 28 | // Enable submit button again if the page is not reloading. |
| 29 | if (!response.reload) { |
| 30 | submitButtonEl.disabled = false; |
| 31 | submitButtonEl.innerText = submitButtonEl.dataset.connect; |
| 32 | } else { |
| 33 | setTimeout(function () { |
| 34 | window.location.reload(); |
| 35 | }, 2000); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Displays Connect error message and/or reloads or redirects the page if needed. |
| 41 | * |
| 42 | * @param {Object} response JSON response data. |
| 43 | * @param {string} response.message Error message. |
| 44 | * @param {boolean} response.reload Whether to reload the page. |
| 45 | * @param {string} response.url URL to redirect to. |
| 46 | */ |
| 47 | function onConnectSuccess(response) { |
| 48 | var feedbackEl = document.getElementById( |
| 49 | 'ppress-connect-license-feedback' |
| 50 | ); |
| 51 | |
| 52 | // Toggle feedback. |
| 53 | if (response.message) { |
| 54 | feedbackEl.innerText = response.message; |
| 55 | feedbackEl.classList.remove('ppress-license-message--invalid'); |
| 56 | feedbackEl.classList.add('ppress-license-message--valid'); |
| 57 | feedbackEl.style.display = 'block'; |
| 58 | } else { |
| 59 | feedbackEl.style.display = 'none'; |
| 60 | } |
| 61 | |
| 62 | // Redirect if the current page is not being reloaded. |
| 63 | if (!response.reload) { |
| 64 | window.location = response.url; |
| 65 | } else { |
| 66 | setTimeout(function () { |
| 67 | window.location.reload(); |
| 68 | }, 2000); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Submits the Lite Connect data. |
| 74 | */ |
| 75 | function onConnect() { |
| 76 | var licenseKeyEl = document.getElementById( |
| 77 | 'ppress-connect-license-key' |
| 78 | ); |
| 79 | |
| 80 | var nonceEl = document.getElementById('ppress-connect-license-nonce'); |
| 81 | |
| 82 | var submitButtonEl = document.getElementById( |
| 83 | 'ppress-connect-license-submit' |
| 84 | ); |
| 85 | |
| 86 | // Disable submit. |
| 87 | submitButtonEl.disabled = true; |
| 88 | submitButtonEl.innerText = submitButtonEl.dataset.connecting; |
| 89 | |
| 90 | // Get the URL. |
| 91 | wp.ajax.send('ppress_connect_url', { |
| 92 | data: { |
| 93 | nonce: nonceEl.value, |
| 94 | key: licenseKeyEl.value, |
| 95 | }, |
| 96 | // Handle success (redirect). |
| 97 | success: onConnectSuccess, |
| 98 | |
| 99 | // Handle error (show error). |
| 100 | error: onConnectError, |
| 101 | }); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Binds the Lite Connect form events. |
| 106 | */ |
| 107 | $(function () { |
| 108 | |
| 109 | var licenseKeyEl = document.getElementById( |
| 110 | 'ppress-connect-license-key' |
| 111 | ); |
| 112 | |
| 113 | if (!licenseKeyEl) return; |
| 114 | |
| 115 | var submitButtonEl = document.getElementById( |
| 116 | 'ppress-connect-license-submit' |
| 117 | ); |
| 118 | |
| 119 | // Start the process if the "Enter" key is pressed while the license input is focused. |
| 120 | licenseKeyEl.addEventListener('keypress', function (e) { |
| 121 | if (e.key !== 'Enter') return; |
| 122 | |
| 123 | e.preventDefault(); |
| 124 | onConnect(); |
| 125 | }); |
| 126 | |
| 127 | // Start the process if the submit button is clicked. |
| 128 | submitButtonEl.addEventListener('click', function (e) { |
| 129 | e.preventDefault(); |
| 130 | submitButtonEl.disabled = true; |
| 131 | onConnect(); |
| 132 | }); |
| 133 | }); |
| 134 | |
| 135 | })(jQuery); |