Answer the question
In order to leave comments, you need to log in
How to write an element selection condition in a JS script (Drupal 6)?
Good afternoon!
There is a script that adds the "colorbox" class and the "rel" attribute with the "gal" parameter to all photos that are on the page so that they open through the Colorbox plugin.
Script:
jQuery(document).ready(function($) {
$("a[href$='.jpeg'], a[href$='.jpg'], a[href$='.JPEG'], a[href$='.JPG']")
.addClass('colorbox')
.attr('rel', 'gal')
.colorbox();
})(jQuery);
There is also a code that calls this script, it is registered in the theme file "template.php".
Code:
drupal_add_js('themes/zen/js/colorbox-open.js');
There is also the Image resize filter module, which basically does almost the same thing. But there is one problem, both methods prescribe a class and attribute to all photos, regardless of their number on the page. Therefore, if there are pages with photos in two blocks, they will all be combined into one gallery.
The question is how to write a condition so that the attribute is assigned only if there are more than one photo on the page.
Answer the question
In order to leave comments, you need to log in
var tmp=$("a[href$='.jpeg'], a[href$='.jpg'], a[href$='.JPEG'], a[href$='.JPG']");
if(tmp.length>1){
tmp.addClass('colorbox').attr('rel', 'gal').colorbox();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question