Some images are not available for some congress-people, which shows broken links in browsers, using Chromium on Ubuntu.

Patch provided for 6.x-3.3 as that was version using, issue may exist from Drupal 7 also.

The patch that will be sent below, adds javascript to deal with this issue in the Drupal 6 version which loads only for the congress view.

Comments

darrell_ulm’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new1.21 KB

Here is the patch to remove broken images from the congress search view, attached.

dalin’s picture

Version: 6.x-3.3 » 7.x-1.x-dev
Assigned: Unassigned » darrell_ulm
Category: bug » task
Status: Patch (to be ported) » Needs work

I don't think I like this approach.
Rather than use JS to hide the image, how about altering cd_sunlight_handler_field_congress_picture->render() so that alt text is not added if the image URL starts with 'http://bioguide.congress.gov/'

P.S. You now have commit access. Can you re-roll the patch, then post here, then I'll get you to commit it to both the D6 and D7 branches.

darrell_ulm’s picture

Ah, didn't notice that the URLs were actually different. Yeah, that'll work. I'll get on it asap.

darrell_ulm’s picture

Version: 7.x-1.x-dev » 6.x-3.x-dev
Status: Needs work » Patch (to be ported)
StatusFileSize
new2.67 KB

This patch attached here is for 6.x-3.x-dev,

Do you want another one for 7.x-x.x-dev?

I'll need to get it installed in my test Drupal7 instance

dalin’s picture

Status: Patch (to be ported) » Needs work

With that patch you actually removed some important functionality that needs to apply even if the images come directly from bioguide (see the inline comments). Instead I think we need to actually set the alt text to '' if the image is coming directly from bioguide.

Do you want another one for 7.x-x.x-dev?

Nope, once we get it right you can apply to both branches.

darrell_ulm’s picture

Hmmm, however, thinking about this, the link provided, for example:
http://bioguide.congress.gov/bioguide/photo/M/M001153.jpg = good one
http://bioguide.congress.gov/bioguide/photo/R/R000591.jpg = not good one
Could be completely valid, but there is no way to know if the external server cannot get this image.

It possibilities are,

  1. good: The data is in the cache already
  2. good: The data is not in the cache, so external link is used, and it could be OK eventually http://bioguide.congress.gov/bioguide/photo/M/M001153.jpg
  3. bad: The data is not in the cache, and there is no image at the external link. (the case we seem to have, but 2) is possible) http://bioguide.congress.gov/bioguide/photo/R/R000591.jpg

I'm not sure one can make an assumption about the difference between 2. and 3. until an attempt to load the image at the browser render time, and I'm not sure you can do that without a little Javascript.

Thanks!

darrell_ulm’s picture

OK, new patch attached

I think I see what you mean now, and this is possible w/ the correct options on theme('image' for the specific cases.

dalin’s picture

Less code duplication == better.

How about something like

      if (strpos($image_url, "http://bioguide.congress.gov") === 0) {
        $alt = NULL;
      }
darrell_ulm’s picture

Before I roll a patch, I had to do modify the getsize param or it didn't work.

Let's go minimal, this one works.

      $getsize = strpos($image_url, "http://bioguide.congress.gov") === 0;
      return theme('image', $image_url, $alt, $title, $attributes, $getsize);

In fact, the $alt param does not seem to affect the image breaking, on Chromimum at least, perhaps it works for other browsers. The getsize parameter seems to be the important one.

darrell_ulm’s picture

OK, here is a patch of the last comment for D6 dev, attached.

dalin’s picture

Looking at theme_image, I don't think that's what you want:
http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_image/6
That will result in _no_ image being displayed (since it's from an external domain).

I think we need to back up and figure out what we're trying to accomplish:

1) There needs to be dimensions set somewhere so that the layout doesn't break.
2) We need alt text where possible to maintain accessibility.
3) Don't show image placeholders in webkit browsers (I think that's what you're after).

So if all the above are true then I think we need to:
1) wrap the image in divs to do a manual scale/crop (possibly only if the image is external):
http://www.advomatic.com/blogs/jack-haas/faking-imagecache-external-imag...
but using inline styles rather than a stylesheet
2) Add the JS to remove broken images.

darrell_ulm’s picture

Hmm, a little more complex,

However, also another option it to provide our own placeholder image, a grey box with the name of the congress-person, and or "no image" text, something like that. Then it should always be there so theming can deal with it as they wish.

We could add a class to the missing image class = "cd_sunlight-missing-image"

Would that work to preserve the formatting? Then themer's could always hide or swap out our place-holder missing image.

Just some ideas. Thanks!

dalin’s picture

But you don't know if the image is missing or not. The image may be coming directly from bioguide because the admin set that in the field settings, or because the server was unable to connect to the bioguide site to pull the image locally (servers that are unable to connect to the outside world is a common issue).

darrell_ulm’s picture

Ah, that's true. OK, I'll chug away on #11

http://drupal.org/node/1901276#comment-7014042
when I get a chance.

Thank you!

darrell_ulm’s picture

Status: Needs work » Patch (to be ported)
StatusFileSize
new2.94 KB

Dalin, patch attached.

Create div around theme('img'.

Jquery to remove broken images, only for the sunlight module views, nothing else, and replaces background w/ greybox, + ALT text when image missing.

Thanks

darrell_ulm’s picture

Status: Patch (to be ported) » Needs review

Updated to the correct status for patch at:
http://drupal.org/files/cd_sunlight-d6_replace_remove_missing_images_Jqu...
for update in #15

dalin’s picture

Status: Needs review » Needs work

A few thoughts:

- Rather than using $(this) multiple times you could do something like this:

var $this = $(this),
  alt = $this.attr("alt");

- We shouldn't be hard-coding colour values. Instead add a class.

$this.parent().addClass('img-error');

- You can also chain some actions:

$this.parent()
  .addClass('img-error')
  // Add the alt text into the container when image is missing.
  .append('<span class="cd-sunlight-img-alt">' + alt + '</span>');

- Also use hyphens for class/id names rather than underscores.

- This line is the most perplexing, but has no code comments:

$(this).attr("src", $(this).attr("src"));

What does it do? If it is unnecessary then the .each() loop could be completely removed, leaving just

$(".cd_sunlight_picture img").error(function(index)
  ...

- Just a note that we'll need to change this for the D7 version to use behaviours:

$(document).ready(function(){ 

- We shouldn't switch on view-name, but rather the type of view (node, file, congress) so that if people create other views this code is still applied.

if ($view->name == "Congress")

- These sizes seems rather arbitrary. Shouldn't we use the calculated height/width? If not we'll at least need some code comments.
$attributes['style'] = 'height: 250px; width:auto;';
return '<div class="cd_sunlight_picture" style=" height:250px; width: 167px;">' . $themed_image . "</div>";

darrell_ulm’s picture

Yeah, these things make sense, I slapped it together in a few minutes Friday. I forgot that I even rolled the patch. :D

Glad you're cool on going the Javascript route now, I think given the params, it may be the only reasonable way to handle it.

This is a good point:

We shouldn't switch on view-name,

I'll get to this again when I have a few minutes.