frayerjj-frontend 0.8.20 → 0.8.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/init.js +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frayerjj-frontend",
3
- "version": "0.8.20",
3
+ "version": "0.8.22",
4
4
  "description": "My base frontend for various projects",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/init.js CHANGED
@@ -106,7 +106,28 @@ export const init = (args) => {
106
106
  modal.confirm(
107
107
  el.getAttribute('confirm-msg') || 'Are you sure?',
108
108
  () => {
109
- location.href = el.getAttribute('href');
109
+ const href = el.getAttribute('href');
110
+ if (el.classList.contains('delete-link')) {
111
+ const form = document.createElement('form');
112
+ form.method = 'POST';
113
+ form.action = href;
114
+ const methodInput = document.createElement('input');
115
+ methodInput.type = 'hidden';
116
+ methodInput.name = '_method';
117
+ methodInput.value = 'DELETE';
118
+ form.appendChild(methodInput);
119
+ const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
120
+ if (csrfToken) {
121
+ const csrfInput = document.createElement('input');
122
+ csrfInput.type = 'hidden';
123
+ csrfInput.name = 'csrfmiddlewaretoken';
124
+ csrfInput.value = csrfToken;
125
+ form.appendChild(csrfInput);
126
+ }
127
+ document.body.appendChild(form);
128
+ form.submit();
129
+ } else
130
+ location.href = href;
110
131
  },
111
132
  () => {},
112
133
  el.getAttribute('confirm-title') || 'Confirm',