PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.4
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.4
2.4.3 2.4.4 2.4.2 2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 All 60 releases
easy-invoice / templates / admin / partials / confirm-helper.php

confirm-helper.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.3.4, at templates/admin/partials/confirm-helper.php

71 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Inline confirmation handler shared by addon pages.
4 *
5 * Hooks any element bearing [data-ei-confirm] (e.g. a delete-button inside a
6 * form) and replaces native window.confirm() with the project's custom
7 * EasyInvoiceConfirmation modal. Falls back to window.confirm() if the
8 * confirmation script is unavailable.
9 *
10 * Supported attributes:
11 * data-ei-confirm — message (required)
12 * data-ei-confirm-title — modal title (optional)
13 * data-ei-confirm-text — confirm button label (optional)
14 * data-ei-confirm-class — Tailwind classes for confirm button (optional)
15 */
16 if (!defined('ABSPATH')) {
17 exit;
18 }
19 ?>
20 <script>
21 (function () {
22 if (window.__eiConfirmHelperLoaded) return;
23 window.__eiConfirmHelperLoaded = true;
24
25 document.addEventListener('click', function (e) {
26 var btn = e.target && e.target.closest ? e.target.closest('[data-ei-confirm]') : null;
27 if (!btn) return;
28 if (btn.dataset.eiConfirmed === '1') {
29 // Re-entry after user confirmed — let the native action proceed.
30 btn.removeAttribute('data-ei-confirmed');
31 return;
32 }
33 e.preventDefault();
34 e.stopPropagation();
35
36 var message = btn.getAttribute('data-ei-confirm') || 'Are you sure?';
37 var title = btn.getAttribute('data-ei-confirm-title') || 'Confirm action';
38 var confirmText = btn.getAttribute('data-ei-confirm-text') || 'Confirm';
39 var confirmClass = btn.getAttribute('data-ei-confirm-class') || 'bg-red-600 hover:bg-red-700';
40
41 function proceed() {
42 btn.dataset.eiConfirmed = '1';
43 var form = btn.closest ? btn.closest('form') : null;
44 if (form) {
45 if (typeof form.requestSubmit === 'function') {
46 form.requestSubmit(btn);
47 } else {
48 form.submit();
49 }
50 } else if (btn.href) {
51 window.location.href = btn.href;
52 } else {
53 btn.click();
54 }
55 }
56
57 if (window.EasyInvoiceConfirmation && typeof window.EasyInvoiceConfirmation.show === 'function') {
58 window.EasyInvoiceConfirmation.show({
59 title: title,
60 message: message,
61 confirmText: confirmText,
62 confirmClass: confirmClass,
63 onConfirm: proceed
64 });
65 } else if (window.confirm(message)) {
66 proceed();
67 }
68 }, true);
69 })();
70 </script>
71