/** * Generate a JavaScript-friendly string of an object containing the slider arguments. * @since 1.0.0 * @param array $args Arguments for this slideshow. * @param array $extra Additional, contextual arguments to use when generating the slider JavaScript. * @return string A JavaScript-friendly string of arguments. */ private function generate_slider_settings_javascript($id, $args, $extra = array()) { $args_output = '{'; $args_output .= 'namespace: "wooslider-"' . "\n"; // Animation if (isset($args['animation']) && in_array($args['animation'], WooSlider_Utils::get_supported_effects())) { $args_output_array['animation'] = '"' . $args['animation'] . '"'; $args_output_array['useCSS'] = 'false'; } // Direction if ($args['animation'] == 'slide' && isset($args['direction']) && in_array($args['direction'], array('horizontal', 'vertical'))) { $args_output_array['direction'] = '"' . $args['direction'] . '"'; } // Slideshow Speed if (isset($args['slideshow_speed']) && is_numeric($args['slideshow_speed']) && floatval($args['slideshow_speed']) > 0) { $args_output_array['slideshowSpeed'] = $args['slideshow_speed'] * 1000; } // Animation Duration if (isset($args['animation_duration']) && is_numeric($args['animation_duration']) && floatval($args['animation_duration']) > 0) { $args_output_array['animationSpeed'] = $args['animation_duration'] * 1000; } // Checkboxes. $options = array('direction_nav' => 'directionNav', 'keyboard_nav' => 'keyboard', 'mousewheel_nav' => 'mousewheel', 'playpause' => 'pausePlay', 'animation_loop' => 'animationLoop', 'pause_on_action' => 'pauseOnAction', 'pause_on_hover' => 'pauseOnHover', 'smoothheight' => 'smoothHeight', 'touch' => 'touch'); if (isset($extra['thumbnails']) && ($extra['thumbnails'] == 2 || $extra['thumbnails'] == 'carousel')) { $args_output_array['controlNav'] = 'false'; } else { if (isset($extra['thumbnails']) && ($extra['thumbnails'] == 'true' || $extra['thumbnails'] == 'thumbnails' || $extra['thumbnails'] == 1)) { $args_output_array['controlNav'] = '"thumbnails"'; } else { $options['control_nav'] = 'controlNav'; } } if (isset($extra['thumbnails']) && ($extra['thumbnails'] == 2 || $extra['thumbnails'] == 'carousel')) { $args_output_array['slideshow'] = 'false'; } else { if (isset($args['autoslide']) && ($args['autoslide'] == 'true' && $args['autoslide'] != 'false' || $args['autoslide'] == 1)) { $args_output_array['slideshow'] = 'true'; } else { $args_output_array['slideshow'] = 'false'; } } $args_output_array['video'] = 'true'; // Process the checkboxes. foreach ($options as $k => $v) { $status = 'false'; if (isset($args[$k]) && ($args[$k] == 'true' && $args[$k] != 'false' || $args[$k] == 1)) { $status = 'true'; } $args_output_array[esc_js($v)] = $status; } // Text fields. $options = array('prev_text' => array('key' => 'prevText', 'default' => __('Previous', 'wooslider')), 'next_text' => array('key' => 'nextText', 'default' => __('Next', 'wooslider')), 'play_text' => array('key' => 'playText', 'default' => __('Play', 'wooslider')), 'pause_text' => array('key' => 'pauseText', 'default' => __('Pause', 'wooslider'))); // Process the text fields. foreach ($options as $k => $v) { if (isset($args[$k]) && $args[$k] != $v['default']) { $args_output_array[esc_js($v['key'])] = '"' . esc_js($args[$k]) . '"'; } } //change this now that we're using hooks if (isset($extra['thumbnails']) && ($extra['thumbnails'] == 2 || $extra['thumbnails'] == 'carousel')) { $args_output_array['sync'] = '"#carousel-' . esc_js(sanitize_key($id)) . '"'; } // CSS Selector fields. $options = array('as_nav_for' => array('key' => 'asNavFor', 'default' => '')); // Process the CSS selector fields. foreach ($options as $k => $v) { if (isset($extra[$k]) && $extra[$k] != $v['default']) { $args_output_array[esc_js($v['key'])] = esc_js('#' . $extra[$k]); } } //Make this slider a carousel, override smootheight and animation if (isset($extra['carousel']) && ($extra['carousel'] == 'true' && $extra['carousel'] != 'false' || $extra['carousel'] == 1)) { $args_output_array['animation'] = '"slide"'; $args_output_array['smoothheight'] = 'false'; $args_output_array['itemWidth'] = 300; $args_output_array['minItems'] = 3; $args_output_array['maxItems'] = 3; //$args_output_array['move'] = 0; } //loop through array, create string of arguments $args_output_array = apply_filters('wooslider_modify_javascript', $args_output_array); foreach ($args_output_array as $k => $v) { $args_output .= ', ' . esc_js($k) . ': ' . htmlspecialchars_decode(esc_js($v)); } // Callback API //Fires when the slider loads the first slide $start = ''; $start = apply_filters('wooslider_callback_start', $start, $id, $args, $extra); $start = apply_filters('wooslider_callback_start_' . sanitize_key($id), $start, $id, $args, $extra); if (isset($args['slider_type']) && '' != $args['slider_type']) { $start = apply_filters('wooslider_callback_start_type_' . sanitize_key($args['slider_type']), $start, $id, $args, $extra); } $args_output .= ', start: function(slider){' . $start . '}'; // Fires asynchronously with each slider animation $before = ''; $before = apply_filters('wooslider_callback_before', $before, $id, $args, $extra); $before = apply_filters('wooslider_callback_before_' . sanitize_key($id), $before, $id, $args, $extra); if (isset($args['slider_type']) && '' != $args['slider_type']) { $before = apply_filters('wooslider_callback_before_type_' . sanitize_key($args['slider_type']), $before, $id, $args, $extra); } $args_output .= ', before: function(slider){' . $before . '}'; // Fires after each slider animation completes $after = ''; $after = apply_filters('wooslider_callback_after', $after, $id, $args, $extra); $after = apply_filters('wooslider_callback_after_' . sanitize_key($id), $after, $id, $args, $extra); if (isset($args['slider_type']) && '' != $args['slider_type']) { $after = apply_filters('wooslider_callback_after_type_' . sanitize_key($args['slider_type']), $after, $id, $args, $extra); } $args_output .= ', after: function(slider){' . $after . '}'; // Fires when the slider reaches the last slide (asynchronous) $end = ''; $end = apply_filters('wooslider_callback_end', $end, $id, $args, $extra); $end = apply_filters('wooslider_callback_end_' . sanitize_key($id), $end, $id, $args, $extra); if (isset($args['slider_type']) && '' != $args['slider_type']) { $end = apply_filters('wooslider_callback_end_type_' . sanitize_key($args['slider_type']), $end, $id, $args, $extra); } $args_output .= ', end: function(slider){' . $end . '}'; // Fires after a slide is added $added = ''; $added = apply_filters('wooslider_callback_added', $added, $id, $args, $extra); $added = apply_filters('wooslider_callback_added_' . sanitize_key($id), $added, $id, $args, $extra); if (isset($args['slider_type']) && '' != $args['slider_type']) { $added = apply_filters('wooslider_callback_added_type_' . sanitize_key($args['slider_type']), $added, $id, $args, $extra); } $args_output .= ', added: function(slider){' . $added . '}'; // Fires after a slide is removed $removed = ''; $removed = apply_filters('wooslider_callback_removed', $removed, $id, $args, $extra); $removed = apply_filters('wooslider_callback_removed_' . sanitize_key($id), $removed, $id, $args, $extra); if (isset($args['slider_type']) && '' != $args['slider_type']) { $removed = apply_filters('wooslider_callback_removed_type_' . sanitize_key($args['slider_type']), $removed, $id, $args, $extra); } $args_output .= ', removed: function(slider){' . $removed . '}'; // End the arguments output $args_output .= '}'; return $args_output; }
/** * Generate a JavaScript-friendly string of an object containing the slider arguments. * @since 1.0.0 * @param array $args Arguments for this slideshow. * @param array $extra Additional, contextual arguments to use when generating the slider JavaScript. * @return string A JavaScript-friendly string of arguments. */ private function generate_slider_settings_javascript($args, $extra = array()) { // Begin the arguments output $args_output = '{'; $args_output .= 'namespace: "wooslider-"' . "\n"; // Animation if (isset($args['animation']) && in_array($args['animation'], WooSlider_Utils::get_supported_effects())) { $args_output .= ', animation: \'' . $args['animation'] . '\''; } // Direction if ($args['animation'] == 'slide' && isset($args['direction']) && in_array($args['direction'], array('horizontal', 'vertical'))) { $args_output .= ', direction: \'' . $args['direction'] . '\''; } // Slideshow Speed if (isset($args['slideshow_speed']) && is_numeric($args['slideshow_speed']) && floatval($args['slideshow_speed']) > 0) { $args_output .= ', slideshowSpeed: ' . $args['slideshow_speed'] * 1000; } // Animation Duration if (isset($args['animation_duration']) && is_numeric($args['animation_duration']) && floatval($args['animation_duration']) > 0) { $args_output .= ', animationSpeed: ' . $args['animation_duration'] * 1000; } // Checkboxes. $options = array('autoslide' => 'slideshow', 'direction_nav' => 'directionNav', 'keyboard_nav' => 'keyboard', 'mousewheel_nav' => 'mousewheel', 'playpause' => 'pausePlay', 'randomize' => 'randomize', 'animation_loop' => 'animationLoop', 'pause_on_action' => 'pauseOnAction', 'pause_on_hover' => 'pauseOnHover', 'smoothheight' => 'smoothHeight', 'touch' => 'touch'); if (isset($extra['thumbnails']) && ($extra['thumbnails'] == 'true' || $extra['thumbnails'] == 1)) { $args_output .= ', controlNav: "thumbnails"' . "\n"; } else { $options['control_nav'] = 'controlNav'; } // Process the checkboxes. foreach ($options as $k => $v) { $status = 'false'; if (isset($args[$k]) && ($args[$k] == 'true' && $args[$k] != 'false' || $args[$k] == 1)) { $status = 'true'; } $args_output .= ', ' . esc_js($v) . ': ' . $status; } // Text fields. $options = array('prev_text' => array('key' => 'prevText', 'default' => __('Previous', 'wooslider')), 'next_text' => array('key' => 'nextText', 'default' => __('Next', 'wooslider')), 'play_text' => array('key' => 'playText', 'default' => __('Play', 'wooslider')), 'pause_text' => array('key' => 'pauseText', 'default' => __('Pause', 'wooslider'))); // Process the text fields. foreach ($options as $k => $v) { if (isset($args[$k]) && $args[$k] != $v['default']) { $args_output .= ', ' . esc_js($v['key']) . ': \'' . esc_js($args[$k]) . '\''; } } // End the arguments output $args_output .= '}'; return $args_output; }