artpolikarpov / fotorama

A simple, stunning, powerful jQuery gallery.
http://fotorama.io
Other
1.58k stars 380 forks source link

Non-image slides cause "Uncaught TypeError" #556

Open CrystalFyre opened 4 years ago

CrystalFyre commented 4 years ago

In version 4.6.3, you could mix content in a Fotorama slider. IMGs, then . This worked fine.

In version 4.6.4, any HTML slides (non images or anchor links), now trip up the script. Uncaught TypeError: Cannot read property 'attr' of null

The function "getDimensions", close to line 1207 in "fotorama.min.js", now attempts to check for attributes for "alt" and "title" of a child element, but the function that calls this, sends a null as the object, so checking for attributes on a null element cause it to crash.

  function getDimensions ($img, $child, imgData) {
    var separateThumbFLAG = imgData.thumb && imgData.img !== imgData.thumb,
        width = numberFromMeasure(imgData.width || $img.attr('width')),
        height = numberFromMeasure(imgData.height || $img.attr('height')),
        alt    = $child.attr('alt'),
        title  = $child.attr('title');

        if (alt)   { $.extend(imgData, { alt: alt }); }
        if (title) { $.extend(imgData, { title: title }); }

    $.extend(imgData, {
      width: width,
      height: height,
      thumbratio: getRatio(imgData.thumbratio || (numberFromMeasure(imgData.thumbwidth || ($child && $child.attr('width')) || separateThumbFLAG || width) / numberFromMeasure(imgData.thumbheight || ($child && $child.attr('height')) || separateThumbFLAG || height)))
    });

The two lines, "alt = $child.atr('alt')" and 'title = $child.attr('title')" trigger this error. HTML slides are sent to "getDimensions" with a Null child. There should be a check in place to make sure a child exists, before attempting to get their attributes.

(My apologies, this is my first time submitting an issue. I hope this is okay?)

CrystalFyre commented 4 years ago

Like this...

        alt    = ($child) ? $child.attr('alt') : null,
        title  = ($child) ? $child.attr('title') : null;

I've temporarily patched my script.