From 15c5b4867eb14e0918f3e0ee71d54e2d8ff3a3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Ko=CC=88nemann?= Date: Fri, 13 May 2016 17:38:25 +0200 Subject: [PATCH] Moving slider script options from footer.php to inc/enqueue.php and js/slider_settings.js --- footer.php | 30 ------------------------------ inc/enqueue.php | 21 +++++++++++++++++++++ js/slider_settings.js | 24 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 js/slider_settings.js diff --git a/footer.php b/footer.php index dfd5851..40b0bfd 100644 --- a/footer.php +++ b/footer.php @@ -40,36 +40,6 @@ - - - - - - diff --git a/inc/enqueue.php b/inc/enqueue.php index 32a3e50..17145c7 100644 --- a/inc/enqueue.php +++ b/inc/enqueue.php @@ -17,3 +17,24 @@ function understrap_scripts() { add_action( 'wp_enqueue_scripts', 'understrap_scripts' ); +/** +*Loading slider script conditionally +**/ + +if ( is_active_sidebar( 'hero' ) ): +add_action("wp_enqueue_scripts","understrap_slider"); + +function understrap_slider(){ + if ( is_front_page() ) { + $data = array( + "timeout"=>get_theme_mod( 'understrap_theme_slider_time_setting', 5000 ), + "items"=>get_theme_mod( 'understrap_theme_slider_count_setting', 1 ) + ); + + + wp_enqueue_script("understrap-slider-script", get_stylesheet_directory_uri() . '/js/slider_settings.js', array(), '0.4.3'); + wp_localize_script( "understrap-slider-script", "understrap_slider_variables", $data ); + } +} +endif; + diff --git a/js/slider_settings.js b/js/slider_settings.js new file mode 100644 index 0000000..e3c8ace --- /dev/null +++ b/js/slider_settings.js @@ -0,0 +1,24 @@ + + jQuery(document).ready(function() { + var owl = jQuery('.owl-carousel'); + owl.owlCarousel({ + items:(understrap_slider_variables.items), + loop:true, + autoplay:true, + autoplayTimeout:(understrap_slider_variables.timeout), + animateOut: 'fadeOut', + animateIn: 'fadeIn', + nav: false, + dots: true, + autoplayHoverPause:true, + margin:0, + autoHeight:true + }); + + jQuery('.play').on('click',function(){ + owl.trigger('autoplay.play.owl',[1000]) + }); + jQuery('.stop').on('click',function(){ + owl.trigger('autoplay.stop.owl') + }); + });