-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.php
45 lines (42 loc) · 1.6 KB
/
logic.php
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
<?php
require_once 'utils.php';
use function Custom_Modal\Utility\{feature_absolute_dir, feature_dir};
add_shortcode('modal', function ($atts, $content = null) {
// Custom Slider CSS
wp_enqueue_style('custom_modal-style', feature_dir('custom_modal.css'), array (), filemtime(feature_absolute_dir('custom_modal.css')));
$attr = shortcode_atts([
'id' => 'modal'
], $atts);
ob_start();
?>
<div id="<?= $attr['id'] ?>" class="modal">
<div class="modal-backdrop">
<div class="modal-content">
<div class="modal-head">
<button class="m-0" data-close="modal">✕</button>
</div>
<div class="modal-body">
<?= do_shortcode($content) ?>
</div>
</div>
</div>
</div>
<script>
window.onload = function() {
document.querySelector("[data-toggle='#<?= $attr['id'] ?>']").addEventListener("click", function () {
const target = this.getAttribute("data-toggle");
console.log(target);
document.getElementById("<?= $attr['id'] ?>").classList = "modal open";
});
document
.getElementById("<?= $attr['id'] ?>").querySelector("[data-close]").addEventListener("click", function () {
const target = this.getAttribute("data-toggle");
document.getElementById("<?= $attr['id'] ?>").classList = "modal";
})
}
</script>
<?php
$res = ob_get_contents();
ob_end_clean();
return $res;
});