diff --git a/class-visual-portfolio.php b/class-visual-portfolio.php index 56938c76..46c62ed9 100644 --- a/class-visual-portfolio.php +++ b/class-visual-portfolio.php @@ -216,6 +216,7 @@ private function include_dependencies() { require_once $this->plugin_path . 'classes/3rd/plugins/class-divi.php'; require_once $this->plugin_path . 'classes/3rd/plugins/class-elementor.php'; require_once $this->plugin_path . 'classes/3rd/plugins/class-ewww-image-optimizer.php'; + require_once $this->plugin_path . 'classes/3rd/plugins/class-fancybox.php'; require_once $this->plugin_path . 'classes/3rd/plugins/class-imagify.php'; require_once $this->plugin_path . 'classes/3rd/plugins/class-jetpack.php'; require_once $this->plugin_path . 'classes/3rd/plugins/class-lazy-loading-responsive-images.php'; diff --git a/classes/3rd/plugins/class-fancybox.php b/classes/3rd/plugins/class-fancybox.php new file mode 100644 index 00000000..5b5d9b0d --- /dev/null +++ b/classes/3rd/plugins/class-fancybox.php @@ -0,0 +1,64 @@ +registered[ $fancybox_handler ] ) ) { + return; + } + + wp_add_inline_script( + $fancybox_handler, + '(function($){ + if (!$) { + return; + } + + function escAttr(text) { + return text.replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/"/g, "'"); + } + + $(document).on("click", "[data-fancybox]", function (e) { + const $this = $(this); + const caption = $this.attr("data-caption"); + + if (caption) { + $this.attr("data-caption", escAttr(caption)); + } + }); + }(window.jQuery));', + 'before' + ); + } +} + +new Visual_Portfolio_Fancybox();