File: /www/wwwroot/1.scey.cn/wp-content/plugins/hao-image-box/inc/hao-image-view.php
<?php
//加载 css
if (!function_exists('hao_image_box_enqueue_scripts')) {
function hao_image_box_enqueue_scripts()
{
wp_register_script('imagelightbox_js', HAO_IMAGE_BOX_PLUGIN_ASSETS_URI . '/js/imagelightbox.min.js', array('jquery'), '', true);
wp_register_style('imagelightbox_css', HAO_IMAGE_BOX_PLUGIN_ASSETS_URI . '/css/imagelightbox.css', array(), '', 'all');
if (is_singular()) {
wp_enqueue_script("jquery");
wp_enqueue_script('imagelightbox_js');
wp_enqueue_style('imagelightbox_css');
}
}
}
add_action('wp_enqueue_scripts', 'hao_image_box_enqueue_scripts');
if (!function_exists('hao_image_box_script')) {
function hao_image_box_script()
{
if (is_singular()) :
$image_options = get_option('hao_image_box_options');
if (isset($image_options) && is_array($image_options)) {
$container_box = hao_image_box_check_field($image_options, 'container_box', 'body');
$container_box = $container_box != '' ? $container_box : 'body';
$overlay_disply = hao_image_box_check_field($image_options, 'overlay_disply', '0');
$button_disply = hao_image_box_check_field($image_options, 'button_disply', '0');
$caption_disply = hao_image_box_check_field($image_options, 'caption_disply', '0');
$navigation_display = hao_image_box_check_field($image_options, 'navigation_display', '0');
$arrows_display = hao_image_box_check_field($image_options, 'arrows_display', '0');
$fullscreen_open = hao_image_box_check_field($image_options, 'fullscreen_open', '0');
} else {
$container_box = "body";
$overlay_disply = "0";
$button_disply = "0";
$caption_disply = "0";
$navigation_display = "0";
$arrows_display = "0";
$fullscreen_open = "0";
} ?>
<script>
jQuery(document).ready(function($) {
var selecter = "<?php echo $container_box; ?>" + " img";
$(selecter).each(function(index, img) {
var src = $(img).attr('src');
if (($(img).parent()[0].tagName).toLowerCase() != 'a') {
var aa = $('<a></a>');
aa.attr('href', src);
aa.attr('data-hzt', 'hzt');
$(img).wrap(aa[0]);
}
});
$('a[data-hzt="hzt"]').imageLightbox({
activity: true,
overlay: <?php echo $overlay_disply == "1" ? "true" : "false" ?>,
button: <?php echo $button_disply == "1" ? "true" : "false" ?>,
caption: <?php echo $caption_disply == "1" ? "true" : "false" ?>,
navigation: <?php echo $navigation_display == "1" ? "true" : "false" ?>,
arrows: <?php echo $arrows_display == "1" ? "true" : "false" ?>,
fullscreen: <?php echo $fullscreen_open == "1" ? "true" : "false" ?>,
quitOnDocClick: true,
history: true,
});
});
</script>
<?php endif;
}
}
add_action('wp_footer', 'hao_image_box_script');
if (!function_exists('hao_image_box_check_field')) {
function hao_image_box_check_field($options, $field, $default)
{
return isset($options[$field]) ? sanitize_text_field($options[$field]) : $default;
}
}