forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganization-create-turbo-helper-js.diff
67 lines (66 loc) · 2.42 KB
/
organization-create-turbo-helper-js.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
diff --git a/assets/app.js b/assets/app.js
index 6a303d4..be6a7b8 100644
--- a/assets/app.js
+++ b/assets/app.js
@@ -11,26 +11,4 @@ import './styles/app.css';
// start the Stimulus application
import './bootstrap';
-import { Modal } from 'bootstrap';
-
-document.addEventListener('turbo:before-cache', () => {
- if (document.body.classList.contains('modal-open')) {
- const modalEl = document.querySelector('.modal');
- const modal = Modal.getInstance(modalEl);
- modalEl.classList.remove('fade');
- modal._backdrop._config.isAnimated = false;
- modal.hide();
- modal.dispose();
- }
-
- // internal way to see if sweetalert2 has been imported yet
- if (__webpack_modules__[require.resolveWeak('sweetalert2')]) {
- // because we know it's been imported, this will run synchronously
- import(/* webpackMode: 'weak' */'sweetalert2').then((Swal) => {
- if (Swal.default.isVisible()) {
- Swal.default.getPopup().style.animationDuration = '0ms'
- Swal.default.close();
- }
- })
- }
-});
+import './turbo/turbo-helper';
diff --git a/assets/turbo/turbo-helper.js b/assets/turbo/turbo-helper.js
new file mode 100644
index 0000000..0dc9fd3
--- /dev/null
+++ b/assets/turbo/turbo-helper.js
@@ -0,0 +1,29 @@
+import { Modal } from 'bootstrap';
+
+const TurboHelper = class {
+ constructor() {
+ document.addEventListener('turbo:before-cache', () => {
+ if (document.body.classList.contains('modal-open')) {
+ const modalEl = document.querySelector('.modal');
+ const modal = Modal.getInstance(modalEl);
+ modalEl.classList.remove('fade');
+ modal._backdrop._config.isAnimated = false;
+ modal.hide();
+ modal.dispose();
+ }
+
+ // internal way to see if sweetalert2 has been imported yet
+ if (__webpack_modules__[require.resolveWeak('sweetalert2')]) {
+ // because we know it's been imported, this will run synchronously
+ import(/* webpackMode: 'weak' */'sweetalert2').then((Swal) => {
+ if (Swal.default.isVisible()) {
+ Swal.default.getPopup().style.animationDuration = '0ms'
+ Swal.default.close();
+ }
+ })
+ }
+ });
+ }
+}
+
+export default new TurboHelper();