← All changes
|
includes/widgets/Off_Canvas_Content/Off_Canvas_Content.php
+13
-12
51.1.38
→
51.1.87
View file →
| @@ -577,16 +577,16 @@ | ||
| 577 | 577 | $this_ID = $this->get_id(); |
| 578 | 578 | $class_ID = 'king-addons-off-canvas-' . $this_ID; |
| 579 | 579 | $overlay_ID = 'king-addons-off-canvas-overlay-' . $this_ID; |
| 580 | 580 | |
| 581 | + $class_selector_js = esc_attr(wp_json_encode('.' . $class_ID)); | |
| 582 | + $overlay_selector_js = esc_attr(wp_json_encode('.' . $overlay_ID)); | |
| 583 | + | |
| 581 | 584 | if (!empty($settings['kng_off_canvas_template'])) { |
| 582 | 585 | |
| 583 | 586 | echo '<div class="king-addons-off-canvas-overlay ' . |
| 584 | 587 | esc_attr($overlay_ID) . '" onclick="'; |
| 585 | - echo "document.querySelector('." . | |
| 586 | - esc_attr($class_ID) . "').classList.toggle('king-addons-off-canvas-active'); document.querySelector('." . | |
| 587 | - esc_attr($overlay_ID) . "').style.opacity = '0'; document.body.style.pointerEvents = 'none'; setTimeout(function () {document.querySelector('." . | |
| 588 | - esc_attr($overlay_ID) . "').style.display = 'none'; document.body.style.pointerEvents = '';}, 300);"; | |
| 588 | + echo "document.querySelector(" . $class_selector_js . ").classList.toggle('king-addons-off-canvas-active'); document.querySelector(" . $overlay_selector_js . ").style.opacity = '0'; document.body.style.pointerEvents = 'none'; setTimeout(function () {document.querySelector(" . $overlay_selector_js . ").style.display = 'none'; document.body.style.pointerEvents = '';}, 300);"; | |
| 589 | 589 | echo '"></div>'; |
| 590 | 590 | |
| 591 | 591 | echo '<div class="king-addons-off-canvas ' . |
| 592 | 592 | esc_attr($class_ID) . ' king-addons-off-canvas-position-' . |
| @@ -599,12 +599,9 @@ | ||
| 599 | 599 | if ('' != $settings['kng_off_canvas_close_btn_icon']['value']) { |
| 600 | 600 | |
| 601 | 601 | echo '<div class="king-addons-off-canvas-close-button king-addons-off-canvas-close-button-' . |
| 602 | 602 | esc_attr($this_ID) . '" onclick="'; |
| 603 | - echo "document.querySelector('." . | |
| 604 | - esc_attr($class_ID) . "').classList.toggle('king-addons-off-canvas-active'); document.querySelector('." . | |
| 605 | - esc_attr($overlay_ID) . "').style.opacity = '0'; document.body.style.pointerEvents = 'none'; setTimeout(function () {document.querySelector('." . | |
| 606 | - esc_attr($overlay_ID) . "').style.display = 'none'; document.body.style.pointerEvents = '';}, 300);"; | |
| 603 | + echo "document.querySelector(" . $class_selector_js . ").classList.toggle('king-addons-off-canvas-active'); document.querySelector(" . $overlay_selector_js . ").style.opacity = '0'; document.body.style.pointerEvents = 'none'; setTimeout(function () {document.querySelector(" . $overlay_selector_js . ").style.display = 'none'; document.body.style.pointerEvents = '';}, 300);"; | |
| 607 | 604 | echo '">'; |
| 608 | 605 | |
| 609 | 606 | Icons_Manager::render_icon($settings['kng_off_canvas_close_btn_icon']); |
| 610 | 607 | echo '</div>'; |
| @@ -626,12 +623,9 @@ | ||
| 626 | 623 | if ('' == $settings['kng_off_canvas_disable_btn']) { |
| 627 | 624 | |
| 628 | 625 | echo '<button class="king-addons-off-canvas-button king-addons-off-canvas-button-' . |
| 629 | 626 | esc_attr($this_ID) . '" onclick="'; |
| 630 | - echo "document.querySelector('." . | |
| 631 | - esc_attr($class_ID) . "').classList.toggle('king-addons-off-canvas-active'); document.querySelector('." . | |
| 632 | - esc_attr($overlay_ID) . "').style.display = 'block'; document.body.style.pointerEvents = 'none'; setTimeout(function () {document.querySelector('." . | |
| 633 | - esc_attr($overlay_ID) . "').style.opacity = '1';}, 1); setTimeout(function () {document.body.style.pointerEvents = '';}, 300);"; | |
| 627 | + echo "document.querySelector(" . $class_selector_js . ").classList.toggle('king-addons-off-canvas-active'); document.querySelector(" . $overlay_selector_js . ").style.display = 'block'; document.body.style.pointerEvents = 'none'; setTimeout(function () {document.querySelector(" . $overlay_selector_js . ").style.opacity = '1';}, 1); setTimeout(function () {document.body.style.pointerEvents = '';}, 300);"; | |
| 634 | 628 | echo '">' . |
| 635 | 629 | esc_html($settings['kng_off_canvas_btn_text']) . '</button>'; |
| 636 | 630 | |
| 637 | 631 | } |
| @@ -643,8 +637,15 @@ | ||
| 643 | 637 | document.addEventListener('DOMContentLoaded', function () { |
| 644 | 638 | |
| 645 | 639 | const offCanvas = document.querySelector('." . esc_js($class_ID) . "'); |
| 646 | 640 | const overlay = document.querySelector('." . esc_js($overlay_ID) . "'); |
| 641 | + | |
| 642 | + // With no template picked the widget prints a placeholder instead of | |
| 643 | + // the panel markup, so these lookups come back empty. Bail out rather | |
| 644 | + // than throwing on insertBefore and losing the handlers below. | |
| 645 | + if (!offCanvas || !overlay) { | |
| 646 | + return; | |
| 647 | + } | |
| 647 | 648 | |
| 648 | 649 | // Moves all off-canvases to right after the <body> opens |
| 649 | 650 | document.body.insertBefore(overlay, document.body.firstChild); |
| 650 | 651 | document.body.insertBefore(offCanvas, document.body.firstChild); |