diff --git a/contrib/views_slideshow_cycle/js/views_slideshow_cycle.js b/contrib/views_slideshow_cycle/js/views_slideshow_cycle.js index 3e72ed5..c865b6d 100644 --- a/contrib/views_slideshow_cycle/js/views_slideshow_cycle.js +++ b/contrib/views_slideshow_cycle/js/views_slideshow_cycle.js @@ -19,7 +19,6 @@ settings.opts = { speed:settings.speed, - timeout:settings.timeout, delay:settings.delay, sync:settings.sync, random:settings.random, @@ -60,6 +59,14 @@ cleartypeNoBg:(settings.cleartypenobg)? true : false } + // Check if the timeout mode is set to dynamic + if (settings.timeout_mode == 'dynamic') { + settings.opts.timeoutFn = Drupal.viewsSlideshowCycle.timeoutDynamic; + } + else { + settings.opts.timeout = settings.timeout; + } + // Set the starting slide if we are supposed to remember the slide if (settings.remember_slide) { var startSlide = readCookie(settings.vss_id); @@ -434,6 +441,16 @@ $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle(options.slideNum); }; + // Callback for timeoutFn + Drupal.viewsSlideshowCycle.timeoutDynamic = function(currSlideElement, nextSlideElement, opts, isForward) { + var index = opts.currSlide; + // Get the id of the slideshow to load the settings + var fullId = '#' + $(currSlideElement).parents('.views_slideshow_cycle_main').attr('id'); + var settings = Drupal.settings.viewsSlideshowCycle[fullId]; + // Return the timeout + return settings.timeout_dynamic_items[index]; + } + // Verify that the value is a number. function IsNumeric(sText) { var ValidChars = "0123456789"; diff --git a/contrib/views_slideshow_cycle/theme/views_slideshow_cycle.theme.inc b/contrib/views_slideshow_cycle/theme/views_slideshow_cycle.theme.inc index 59ae2fa..7ac2c2e 100644 --- a/contrib/views_slideshow_cycle/theme/views_slideshow_cycle.theme.inc +++ b/contrib/views_slideshow_cycle/theme/views_slideshow_cycle.theme.inc @@ -95,8 +95,6 @@ function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame(&$va // Load our cycle css drupal_add_css($module_path . '/views_slideshow_cycle.css', 'file'); - drupal_add_js(array('viewsSlideshowCycle' => array('#views_slideshow_cycle_main_' . $vss_id => $settings)), 'setting'); - // Add hover intent library if ($settings['pause']) { if (module_exists('libraries')) { @@ -141,11 +139,18 @@ function _views_slideshow_cycle_preprocess_views_slideshow_cycle_main_frame(&$va $items[] = $item; if (count($items) == $items_per_slide || $count == (count($rows)-1)) { $rendered_rows .= theme(views_theme_functions('views_slideshow_cycle_main_frame_row', $vars['view'], $vars['view']->display[$vars['view']->current_display]), array('vss_id' => $vss_id, 'items' => $items, 'count' => $slideshow_count, 'view' => $vars['view'])); + if ($settings['timeout_mode'] == 'dynamic') { + // Remove non number digits and cast to int + $timeout_time = (int) preg_replace('/[^0-9]/', '', $view->render_field($settings['timeout_dynamic_field'], $count)); + $settings['timeout_dynamic_items'][$slideshow_count] = $timeout_time; + } $items = array(); $slideshow_count++; } } + drupal_add_js(array('viewsSlideshowCycle' => array('#views_slideshow_cycle_main_' . $vss_id => $settings)), 'setting'); + $vars['rendered_rows'] = $rendered_rows; } diff --git a/contrib/views_slideshow_cycle/views_slideshow_cycle.views_slideshow.inc b/contrib/views_slideshow_cycle/views_slideshow_cycle.views_slideshow.inc index 15f5217..7b33179 100644 --- a/contrib/views_slideshow_cycle/views_slideshow_cycle.views_slideshow.inc +++ b/contrib/views_slideshow_cycle/views_slideshow_cycle.views_slideshow.inc @@ -42,7 +42,9 @@ function views_slideshow_cycle_views_slideshow_option_definition() { // Transition 'effect' => array('default' => 'fade'), 'transition_advanced' => array('default' => 0), + 'timeout_mode' => array('default' => 'static'), 'timeout' => array('default' => 5000), + 'timeout_dynamic_field' => array('default' => ''), 'speed' => array('default' => 700), //normal 'delay' => array('default' => 0), 'sync' => array('default' => 1), @@ -141,6 +143,27 @@ function views_slideshow_cycle_views_slideshow_slideshow_type_form(&$form, &$for '#markup' => '
', ); + // Timeout Mode option + $form['views_slideshow_cycle']['timeout_mode'] = array( + '#type' => 'radios', + '#title' => t('Timeout Mode'), + '#description' => t('Select the timeout Mode for the slides. Static will apply one value to all slides. Dynamic will allow the user to specify a row field to be used as a timeout value.'), + '#default_value' => $view->options['views_slideshow_cycle']['timeout_mode'], + '#options' => array( + 'static' => t('Static'), + 'dynamic' => t('Dynamic'), + ), + '#states' => array( + 'visible' => array( + ':input[name="style_options[views_slideshow_cycle][transition_advanced]"]' => array('checked' => TRUE), + ), + ), + ); + // Need to wrap this so it indents correctly. + $form['views_slideshow_cycle']['timeout_mode_wrapper'] = array( + '#markup' => '
', + ); + // For static timeouts, we just show the timeout textfield $form['views_slideshow_cycle']['timeout'] = array( '#type' => 'textfield', '#title' => t('Timer delay'), @@ -149,9 +172,33 @@ function views_slideshow_cycle_views_slideshow_slideshow_type_form(&$form, &$for '#states' => array( 'visible' => array( ':input[name="style_options[views_slideshow_cycle][transition_advanced]"]' => array('checked' => TRUE), + ':input[name="style_options[views_slideshow_cycle][timeout_mode]"]' => array('value' => 'static'), ), ), ); + // Get the field options for the dynamic timeout + foreach ($view->display->handler->get_handlers('field') as $field => $handler) { + $options[$field] = $handler->ui_name(); + } + // If dynamic is chosen as the timeout type + $form['views_slideshow_cycle']['timeout_dynamic_field'] = array( + '#type' => 'radios', + '#title' => t('Timeout Field'), + '#description' => t('The field that has the timeout value (in milliseconds). The field should be a number field, but as long as the value of the field is a number, it will work.'), + '#options' => $options, + '#default_value' => $view->options['views_slideshow_cycle']['timeout_dynamic_field'], + '#states' => array( + 'visible' => array( + ':input[name="style_options[views_slideshow_cycle][transition_advanced]"]' => array('checked' => TRUE), + ':input[name="style_options[views_slideshow_cycle][timeout_mode]"]' => array('value' => 'dynamic'), + ), + ), + ); + // Need to wrap this so it indents correctly. + $form['views_slideshow_cycle']['timeout_mode_wrapper_close'] = array( + '#markup' => '
', + ); + $form['views_slideshow_cycle']['speed'] = array( '#type' => 'textfield', '#title' => t('Speed'),