0

This code has worked for 6 months, then all of a sudden it started throwing this code. It is for a Tumblr theme that we had to create a work around for an issue with iframe youtube videos.

The line that is apparently throwing the error is:

if(theVidURL.indexOf('youtu.be') >= 0)

Error: TypeError: theVidURL is undefined

Here is the rest of the code:

function replaceThumbnailImg(){
    // var classes = $('article.video').attr('class').split(' ');
        articles = $('article.video');
        articles.each(function(){

            var headers = $(this).find('header');
            var theVidURL = $(this).find('.source_link').attr('href');

            var theVidURLArray = null;

            if(theVidURL.indexOf('youtu.be') >= 0){
                theVidURLArray = theVidURL.split('.be/');
                if(typeof theVidURLArray[1]!='undefined'){theVidURLArray = theVidURLArray[1].split('/');}

            } else {
                theVidURLArray = theVidURL.split('v=');

                if(typeof theVidURLArray[1]!='undefined'){theVidURLArray = theVidURLArray[1].split('&');}
                    theVidURLArray = theVidURLArray[0].split('?');
                }
        if(theVidURL.indexOf('youtu') >= 0){ 
            headers.each(function(){
                    theThumbURL = 'http://img.youtube.com/vi/'+theVidURLArray[0]+'/0.jpg';

                    $(this).html('<img src="'+theThumbURL+'" />');
                });
        }
            // $('header').html('');
        });
    }       
4

0 回答 0