PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.4
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.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.4.4, at templates/admin/partials/confirm-helper.php

76 lines 2.9 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 var isSubmit = btn.tagName === 'BUTTON' ? (btn.type || 'submit') === 'submit' : (btn.tagName === 'INPUT' && btn.type === 'submit');
45 if (btn.tagName === 'A' && btn.href) {
46 // A link inside a form (a row action in a bulk-action table)
47 // still just follows its href.
48 window.location.href = btn.href;
49 } else if (form && isSubmit) {
50 if (typeof form.requestSubmit === 'function') {
51 form.requestSubmit(btn);
52 } else {
53 form.submit();
54 }
55 } else {
56 // type="button" and similar: re-fire the click; the marker
57 // above lets the element's own handler run this time.
58 btn.click();
59 }
60 }
61
62 if (window.EasyInvoiceConfirmation && typeof window.EasyInvoiceConfirmation.show === 'function') {
63 window.EasyInvoiceConfirmation.show({
64 title: title,
65 message: message,
66 confirmText: confirmText,
67 confirmClass: confirmClass,
68 onConfirm: proceed
69 });
70 } else if (window.confirm(message)) {
71 proceed();
72 }
73 }, true);
74 })();
75 </script>
76