Browse code

Initial commit

Benjamin Roth authored on16/03/2023 20:22:35
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,106 @@
1
+<?php $this->extend('block_searchable'); ?>
2
+<?php $this->block('content'); ?>
3
+    <!-- indexer::stop -->
4
+    <div class="<?php echo $this->class; ?> <?php echo $this->tableless ? 'tableless' : 'tableform'; ?> block" <?php echo $this->cssID; ?><?php if ($this->style) : ?> style="<?php echo $this->style; ?>" <?php endif; ?>>
5
+        <?php if ($this->headline) : ?>
6
+        <<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
7
+<?php endif; ?>
8
+    <form novalidate
9
+          action="<?php echo $this->action; ?>" <?php if ($this->formId) : ?> id="<?php echo $this->formId; ?>" <?php endif; ?>
10
+          method="<?php echo $this->method; ?>"
11
+          enctype="<?php echo $this->enctype; ?>" <?php echo $this->attributes; ?><?php echo $this->novalidate; ?>>
12
+        <div class="formbody row">
13
+            <?php if ($this->method != 'get') : ?>
14
+                <input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formSubmit; ?>">
15
+                <input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">
16
+                <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $this->maxFileSize; ?>">
17
+            <?php endif; ?>
18
+            <?php echo $this->hidden; ?>
19
+            <?php if (!$this->tableless) : ?>
20
+                <table>
21
+                    <?php echo $this->fields; ?>
22
+                </table>
23
+            <?php else : echo $this->fields;
24
+            endif; ?>
25
+        </div>
26
+    </form>
27
+    <script>
28
+        (function () {
29
+            var form = document.querySelector('input[name="FORM_SUBMIT"][value="<?= $this->formSubmit; ?>"]').form;
30
+            if (!form) {
31
+                return;
32
+            }
33
+            var triggeredButton = null;
34
+
35
+            function request(method, uri, body, callback) {
36
+                var body = body || null;
37
+                var request = new XMLHttpRequest();
38
+                request.open(method, uri, true);
39
+                request.setRequestHeader('Accept', 'text/html');
40
+                request.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
41
+                request.setRequestHeader('Contao-Ajax-Form', '<?= $this->formSubmit; ?>');
42
+                form.classList.add('ajax-loading');
43
+                request.onload = function () {
44
+                    form.classList.remove('ajax-loading');
45
+                    callback.apply(this);
46
+                    var event = new Event('ajax_change');
47
+                    form.dispatchEvent(event);
48
+                    window.dispatchEvent(event);
49
+                };
50
+                request.send(body)
51
+            }
52
+
53
+            function addButtonEvents(form) {
54
+                var buttons = form.querySelectorAll('input[type="submit"],button[type="submit"]');
55
+                for (var i = 0; i < buttons.length; i++) {
56
+                    buttons[i].addEventListener('click', function (e) {
57
+                        triggeredButton = e.currentTarget;
58
+                    }, {passive: true});
59
+                }
60
+            }
61
+
62
+            function updateContent(form, data, action) {
63
+                var action = action || form.action;
64
+                if ('true' === data) {
65
+                    return;
66
+                }
67
+                form.action = action;
68
+                form.innerHTML = data;
69
+                addButtonEvents(form);
70
+                $(form).find(".widget-text input, .widget-textarea textarea").each(function (index) {
71
+                    $(this).parent("div").addClass("form-floating");
72
+                    $("<label>" + $(this).attr("placeholder") + "</label>").insertAfter(this);
73
+                });
74
+
75
+                $(form).find(".formbody").each(function (index) {
76
+                    $(this).addClass("row");
77
+                });
78
+
79
+                $('html, body').animate({
80
+                    scrollTop: $(".ce_form").offset().top - 125
81
+                }, 1000);
82
+            }
83
+
84
+            form.addEventListener('submit', function (e) {
85
+                e.preventDefault();
86
+                var formData = new FormData(form);
87
+                if (triggeredButton) {
88
+                    formData.append(triggeredButton.name, triggeredButton.value);
89
+                }
90
+                request('POST', form.action, formData, function () {
91
+                    var location = this.getResponseHeader('X-Ajax-Location');
92
+                    if (!location) {
93
+                        updateContent(form, this.responseText);
94
+                        return;
95
+                    }
96
+                    request('GET', location, null, function () {
97
+                        updateContent(form, this.responseText, location);
98
+                    });
99
+                });
100
+            }, {passive: true});
101
+            addButtonEvents(form);
102
+        })();
103
+    </script>
104
+    </div>
105
+    <!-- indexer::continue -->
106
+<?php $this->endblock(); ?>
0 107
\ No newline at end of file