Changing title lengths on window size change

Changing title lengths on window size change

I am trying to change the video title lengths when the size of the window is below 1400 pixels (to prevent word wrapping with the long titles) but for some reason it appends all the featured links TWICE and doesn't correctly erase the entire DIV to regenerate when the window size is changed. 

http://jordan.rave5.com/tmpstuff/ Live preview of issue

Here is the window size control: 

  1. // Control Header Size & Youtube Player
  2. $(window).load(function() {

  3. resizeDiv();
  4. appendFeaturedVideos();

  5. $(window).resize(function() { 
  6. resizeDiv(); 
  7. appendFeaturedVideos();
  8. });
  9. });


and here is the function in question:

  1. // Get youtube info
  2. function appendFeaturedVideos() {
  3. $('#featured-video-links').empty();
  4. $.get('http://jordan.rave5.com/tmpstuff/featVideos.txt',function(data){
  5. var lineArray=data.split('\n'),
  6. slideList=[],
  7. count = lineArray.length;
  8. for(i = 0; i < count; i++) {
  9. var videoUrl = 'http://www.youtube.com/embed/' + lineArray[i].trim() + '?fs=1',
  10. feedUrl = 'http://gdata.youtube.com/feeds/api/videos?q=' + lineArray[i].trim() + '&max-results=1&v=2&alt=jsonc';
  11. $.getJSON(feedUrl, function(response) {
  12. var videoUrl = 'http://www.youtube.com/embed/' + response.id,
  13. likeCount = '',
  14. viewCount = '';
  15. if ( response.data.items[0].viewCount == undefined ) {
  16. if ( response.data.items[0].likeCount != undefined ) {
  17. likeCount = 'Likes: ' + response.data.items[0].likeCount;
  18. }
  19. viewCount = likeCount;
  20. } else {
  21. if ( response.data.items[0].likeCount != undefined ) {
  22. likeCount = 'Likes: ' + response.data.items[0].likeCount + '&nbsp;&nbsp;&nbsp;';
  23. }
  24. viewCount = '<div class="feat-vid-views">' + likeCount + ' Views: ' + response.data.items[0].viewCount + '</div>';
  25. }
  26. var videoTitle = response.data.items[0].title;
  27. if ( $(window).width() <= 1400 ) {
  28. videoTitle = videoTitle.substring(0,23) + '...';
  29. }
  30. $('#featured-video-links').append('<div class="featured-video-link" onclick="changeYoutube(\'' + response.data.items[0].id + '\');"><img src="' + response.data.items[0].thumbnail.sqDefault + '" alt="' + response.data.items[0].title + '" /><div class="feat-vid-info"><div class="feat-vid-title"><span class="feat-vid-title-text">' + videoTitle + '</span> ' + viewCount + '</div><div class="feat-vid-author"><span class="feat-vid-duration">' + secondsToTime(response.data.items[0].duration) + '</span>By <a href="http://youtube.com/' + response.data.items[0].uploader + '">' + response.data.items[0].uploader + '</a><div></div></div>');
  31. });
  32. }
  33. });
  34. }