Hello.
I was about to TRY to write my own view style to impliment Jquery Cycle, just a syou did. I'm sure glad you did. Looks great, but took me a bit to get it working....
YOU SEE...
Using Views 2, and D6, I have a view set up to display on node teasers (via views_embed_view($view_id, $display_id, $args) in my node.tpl.php) and it takes in one argument for the node title. Well, it ends up, the same view with different arguments is displayed on one page. Your function template_preprocess_views_view_rotator(&$vars) is not set up to differentiate between these view instances, and does not give a unique ID attribute to each one. Hence the javascript is broken.
SO ...
I took the liberty to add another variable to the $vars['views_rotator_id'] string. I added the view's first argument to the end of this string. I dunno if this is a good permanent solution ... but that's what I did to make this work for me.
I'm not going to submit a patch yet, but here's what I ended up changing (two lines with "MANI") :
function template_preprocess_views_view_rotator(&$vars) {
drupal_add_css(drupal_get_path('module', 'views_rotator') .'/views-rotator.css');
$view = $vars['view'];
$options = $view->style_plugin->options;
// MANI -- clean up the view's first argument for use in an ID attribute
$arg_id = strtolower(str_replace(array('][', '_', ' '), '-', $view->args[0]));
// MANI -- add the new variable to the end of our ID attribute, to make it more unique
$vars['views_rotator_id'] = 'views-rotator-'. $view->name .'-'. $view->current_display . '-' . $arg_id;
drupal_add_js(drupal_get_path('module', 'views_rotator') .'/views-rotator.js');
$view_settings['fx'] = 'fade';
$view_settings['timeout'] = check_plain($options['timeout']) * 1000;
$view_settings['speed'] = check_plain($options['speed']) * 1000;
$view_settings['pause'] = check_plain($options['pause']);
$view_settings['cleartype'] = 1;
if (!empty($options['back_next_buttons'])) {
$view_settings['next'] = '#'. $vars['views_rotator_id'] .'-views-rotator-next';
$view_settings['prev'] = '#'. $vars['views_rotator_id'] .'-views-rotator-prev';
}
if (empty($options['height'])) {
$view_settings['height'] = 'auto';
$view_settings['auto_height'] = 1;
}
drupal_add_js(array('views_rotator' => array($vars['views_rotator_id'] => $view_settings)), 'setting');
}
Thanks for making this module. It's JUST what the doctor ordered.
M.M.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | views_rotator_class_js.patch | 480 bytes | q0rban |
| #5 | views_rotator_class.patch | 887 bytes | q0rban |
Comments
Comment #1
mfer commentedInteresting use case. You're solution it's a good fix because most people won't use an argument for this.
Any other ideas on solving this well? In a way that provides a consistent id for themers to use?
Comment #2
manimejia commentedI actually think THIS would be a better implementation of my fix ...
(adds ALL arguments to the ID, but if none adds nothing)
add to views_rotator.module at line 29.
Comment #3
mfer commentedA more appropriate solution would be to add a counter. It shouldn't be based on arguments. If you have the exact same view on a page more than once the problem would still creep in. Yet, when it comes to theming there would still be a problem because the counter would change.
Also, the code above won't work.
Do you know how other situations like this operate?
Comment #4
q0rban commentedWhy not just use classes instead of using an ID, as views does everywhere else?
Comment #5
q0rban commentedpatch implements #4
Comment #6
q0rban commentedwhoops, js needs to be patched as well... This patch is only for the js file, you'll still need the above patch.