Hi. This module is very nice! I like it.

I have a offer that this module supports handling empty imagefields.
I need this functionality, so I HACK the code. My HACK is below.

function theme_jquery_slideshow_formatter($element) {
  static $rendered;
  if (!$rendered) {
      $rendered = TRUE;
      $nid = $element['#item']['nid'];
      $node = node_load($element['#item']['nid']);
      $field_name = $element['#field_name'];

      if($node->{$field_name}){
        $jq_slideshow_id = 'jq-slideshow-'. $nid .'-'. $field_name;
        
        # render CSS files
        $formatter = $element['#formatter'];
        $dets = explode('__', $formatter);
        $preset = $dets[1];
        _jquery_slideshow_get_settings($jq_slideshow_id, $preset);

        # render output HTML
        $output = '<div class="jquery_slideshow" id="'. $jq_slideshow_id .'">';
        foreach ($node->{$field_name} as $image) {
          if($image){
            $output .= theme('imagecache', $preset, $image['filepath'], $image['data']['alt'], $image['data']['title']);        
          }
        }
        $output .= '</div>';
      }
  }
  return $output;
}

If possible, I want next version of Jquery_slideshow to include this codes.

I'm sorry for my poor English.
Thank you.

CommentFileSizeAuthor
#13 jquery_slideshow_emtpy.patch839 bytesimclean
#3 diff.txt1.5 KBptaro

Comments

ptaro’s picture

Title: handling for empty imagefileds » handling empty imagefileds
nvoyageur’s picture

Can you provide a diff file? It's easier to identify your changes....

Thanks,
Shane

ptaro’s picture

StatusFileSize
new1.5 KB

I'm sorry for my late reply !

Here is a diff file.

Thank you.

nateb’s picture

This is appreciated. Certainly helpful.

nvoyageur’s picture

Title: handling empty imagefileds » handling empty imagefields
tobedeleted’s picture

Will this be rolled in to an official release any time soon?

nvoyageur’s picture

When I release the next version of the module I'll try to incorporate these changes. It looks like there is some interest in this functionality although it still baffles me why you would have blank imagefields.

Arban’s picture

subscribe

mcurry’s picture

subscribe

@nvoyager:

it still baffles me why you would have blank imagefields

I'm not sure if we're talking about the same things here, but in my case, I have a content type with an image field that allows up to three images uploaded. If the user uploads less than three (perfectly valid choice, the imagefield module allows it), then there are 'blank' image fields in the database, and the slide show displays a 'broken image' in the place of the 'empty' imagefields, which makes the slide show look a bit strange.

So it's not that I want a blank image field, it's that the user has the option to not upload every possible image. In that case, the slide show should not try to display the 'empty' imagefields (and it does, at least on my install). Not sure if this is a problem with imagefield or the slide show module; I'm not yet up on how CCK/imagefield does its thing.

I did notice that this wasn't a problem on my 5.x installation with the same set-up (CCK, ImageField, JQuery Slideshow)

edit: I just applied the OP's patch and it seems to fix the problem I described. Everything is working just fine now.

mcurry’s picture

Category: feature » bug

I'm changing this to a bug report since a valid imagefield configuration seems to trigger incorrect behavior. (See my prior post for details.)

nvoyageur’s picture

The latest version 2.x-dev should support blank/missing images. Please test this out.

mradcliffe’s picture

Version: 6.x-1.2 » 6.x-2.x-dev

I tested this out tonight with the 2.x development branch, but it is still loading imagefield that does not contain any data.

imclean’s picture

StatusFileSize
new839 bytes

Very handy module, thanks! I also needed to support an empty imagefield. This is simply so the field can be left empty if required. The client can then add 1 or more images if they so choose, or if the content layout needs more room the images can be removed.

In my case, using the current dev version only the js required modification. It now checks that there actually is an id before processing.

mcurry’s picture

I downloaded the 6.x-2 version from github:
http://github.com/nvoyageur/Jquery-Slideshow/downloads

And the problem persists, even if I apply imclean's patch @ comment #13.

What is the correct version of Jquery Slideshow for Drupal 6?

mcurry’s picture

Ah, I see the problem now. The formatter code needs to supress all divs if the image is null:

function theme_jquery_slideshow_formatter($element) {
  // ...

          foreach ($node->{$field_name} as $image) {
            if ($image) {
              $output .= '<div class="jqs-slide">';

Here's a diff against the 6.x-2.x-dev build taken from drupal.org (https://drupal.org/node/688166) -- note the location of the if ($image) { logic:

 diff -uw /tmp/jquery_slideshow/jquery_slideshow.module jquery_slideshow.module --- /tmp/jquery_slideshow/jquery_slideshow.module       2010-01-18 05:36:47.000000000 -0800
+++ jquery_slideshow.module     2010-09-17 09:37:01.000000000 -0700
@@ -76,9 +76,10 @@
           $output = '<div class="jquery_slideshow" id="'. $jq_slideshow_id .'">';

           foreach ($node->{$field_name} as $image) {
+            if ($image) {
+
             $output .= '<div class="jqs-slide">';

-            if ($image) {
               $output .= theme('imagecache', $preset, $image['filepath'], $image['data']['alt'], $image['data']['title']);
               $output .= '<div class="jqs-bottom">';
               if (!empty($image['data']['title']) && (variable_get('jquery_slideshow_inlinetitle', 'Yes') == 'Yes')) 
@@ -88,9 +89,9 @@
                 $output .= "</div> <!-- /jqs-field-count -->";
               }
               $output .= '</div> <!-- /jqs-bottom -->';
-            }
             $output .= '</div> <!-- /jqs-slide -->';
           }
+          }
           $output .= '</div> <!-- /jquery-slideshow -->';
           if (variable_get('jquery_slideshow_showcontrols', 'Yes') == 'Yes' && (1 < count($node->{$field_name}))) {
             $output .= '<ul class="jqs-controls">

Of course, this mod breaks the "n of nn" display, since the count is wrong now -- the simple fix requires that the count is calculated ahead of time based on similar logic. I'll work on a fix for that and submit a proper patch.

kevinquillen’s picture

I had an issue where if a node does not have any images, jquery slideshow still tries to do stuff, which broke the whole page.

Here is my quick fix around that issue:

    // code above omitted...
    // Line ~81
   
    if ($image) {
              $output .= theme('imagecache', $preset, $image['filepath'], $image['data']['alt'], $image['data']['title']);
              $output .= '<div class="jqs-bottom">';
              if (!empty($image['data']['title']) && (variable_get('jquery_slideshow_inlinetitle', 'Yes') == 'Yes'))
                $output .= '<div class="jqs-field-title">' . $image['data']['title'] . '</div>';
              if (variable_get('jquery_slideshow_displaycount', 'Yes') == 'Yes') {
                $output .= '<div class="jqs-field-count">' . ++$cur_image . t(' of ') . count($node->{$field_name});
                $output .= "</div> <!-- /jqs-field-count -->";
              }
              $output .= '</div> <!-- /jqs-bottom -->';
              $display = TRUE;
            }
            $output .= '</div> <!-- /jqs-slide -->';
          }
          $output .= '</div> <!-- /jquery-slideshow -->';
          if (variable_get('jquery_slideshow_showcontrols', 'Yes') == 'Yes' && (1 < count($node->{$field_name}))) {
            $output .= '<ul class="jqs-controls">
            <li class="jqs-prev-slide"><a href="#" id="jqs-prev-slide">' . t('Prev') . '</a></li>
            <li class="jqs-next-slide"><a href="#" id="jqs-next-slide">' . t('Next') . '</a></li>
            </ul>';
          }
        }
        if ($display) {
 	  _jquery_slideshow_get_settings($jq_slideshow_id, $preset);
          drupal_add_css(drupal_get_path('module', 'jquery_slideshow') . '/jquery_slideshow.css' );
          return $output;
        }      

If there was at least 1 image then it will add the js and css and return the output. Otherwise it won't do anything, and my page was fine. There is probably a more efficient way to do this, but I needed to fix this fast on a live site.