<?php

/**
 * @package CPhotoPic Lite
 */
require_once get_template_directory() . "/pub/core/cphotopic-lite-customization.php";
require_once get_template_directory() . "/pub/lib/cphotopic-lite-style-functions.php";
require_once get_template_directory() . "/pub/lib/cphotopic-lite-setup-functions.php";
require_once get_template_directory() . "/pub/lib/cphotopic-lite-widget-functions.php";
require_once get_template_directory() . "/pub/lib/cphotopic-lite-page-functions.php";

/**
 * Fix skip link focus in IE11.
 *
 * This does not enqueue the script because it is tiny and because it is only for IE11,
 * thus it does not warrant having an entire dedicated blocking script being loaded.
 *
 * @link https://git.io/vWdr2
 */
function cphotopic_lite_skip_link_focus_fix() {
    echo '<script>
        /(trident|msie)/i.test(navigator.userAgent) && document.getElementById && window.addEventListener && window.addEventListener("hashchange", function () {
            var t, e = location.hash.substring(1);
            /^[A-z0-9_-]+$/.test(e) && (t = document.getElementById(e)) && (/^(?:a|select|input|button|textarea)$/i.test(t.tagName) || (t.tabIndex = -1), t.focus())
        }, !1);
    </script>';

    //menu dropdown accessibility
    echo '<script type="text/javascript">

        jQuery(document).ready(function () {
            jQuery(".nav").cphotopicliteaccessibleDropDown();
        });

        jQuery.fn.cphotopicliteaccessibleDropDown = function () {
            var el = jQuery(this);

            /* Make dropdown menus keyboard accessible */

            jQuery("a", el).focus(function () {
                jQuery(this).parents("li").addClass("hover");
            }).blur(function () {
                jQuery(this).parents("li").removeClass("hover");
            });
        }
    </script>';
}

add_action('wp_print_footer_scripts', 'cphotopic_lite_skip_link_focus_fix');

function cphotopic_lite_register_block_extras() {
    if (function_exists('register_block_style')) {
        register_block_style('core/button', array(
            'name'  => 'photo-cta',
            'label' => esc_html__('Photo CTA', 'cphotopic-lite'),
        ));
    }
    if (function_exists('register_block_pattern')) {
        register_block_pattern('cphotopic-lite/cta', array(
            'title'   => esc_html__('Call to action', 'cphotopic-lite'),
            'content' => '<!-- wp:buttons --><div class="wp-block-buttons"><!-- wp:button --><div class="wp-block-button"><a class="wp-block-button__link">View Gallery</a></div><!-- /wp:button --></div><!-- /wp:buttons -->',
        ));
    }
}
add_action('init', 'cphotopic_lite_register_block_extras');
