InterOcean Designs
« YouTube Thumbnail Links in Posts »

Welcome Guest. Please Login or Register.
May 18, 2013, 6:41am




InterOcean Designs :: ProBoards Codes :: ProBoard Code Database :: YouTube Thumbnail Links in Posts
Page 1 of 3 » Jump to page   Go    [Search This Thread] [Share Topic] [Print]
 AuthorTopic: YouTube Thumbnail Links in Posts (Read 1,678 times)
SubDevo
Co-Admin
Code Support
member is offline

[avatar]

Creator of LSD...


[homepage]

Joined: Mar 2009
Gender: Male
Posts: 2,594
Location: MI, USA
Karma: 102
 YouTube Thumbnail Links in Posts
« Thread Started on Aug 13, 2011, 3:42am »

YouTube Thumbnail Links in Posts by SubDevo
Tested in IE, FF, Opera, Safari and Chrome.

This code will convert posted YouTube video URL text links into a clickable thumbnail image link.
The actual thumbnail image for the video is automatically added. Clicking the image will play the video in a popup window. If you want to watch the video on YouTube, click the small "YouTube" logo image.
This is what you will see when you post a YouTube video URL text link...

http://www.youtube.com/watch?v=LpxIj1sW37E http://www.youtube.com/watch_popup?v=1ZUQ59UjCR0

You have a choice of the default background image (shown above), a "black" version or create your own! They can be found at the bottom of this post with instructions for adding your own custom background.

"Hey! Isn't this against PB TOS?"

Not at all. This code is simply converting the YouTube video text link into an image link. No custom UBBC is needed or used. It does not block, remove, change or move any PB ads or modify an embedded video that has been added with the YouTube UBBC. It does not convert any links that the user has already made into an image or is using custom text for the link.

Enjoy!!! :)
SubDevo

More info:
The image is added inline. That means you can put them right next to each other in the same row.
If the code is removed, all YouTube links go back to normal text links.
The code also has a CSS section. Be careful when changing any of the values in it. I took great care to make sure it looks exactly the same in all the browsers I tested this code in.
If you wish to use your own images, read the "Advanced" section below the code posts.

Variables: There is only one...

var ytLogo="http://i53.tinypic.com/2h4jkzk.png"; // Logo Image URL
Enter the URL to your own logo image. This will be the link to watch on YouTube.

Location: Global Footer
Code:
<style type="text/css">
/* YouTube Thumbnail Links by SubDevo CSS */
.yt_container {
&nbsp; &nbsp;display: inline-block;
&nbsp; &nbsp;background: url(http://i52.tinypic.com/6hkrp4.png) no-repeat;
&nbsp; &nbsp;text-align: center;
&nbsp; &nbsp;height: 137px;
&nbsp; &nbsp;width: 144px;
&nbsp; &nbsp;margin-bottom: 5px;
}
.yt_thumb {
&nbsp; &nbsp;position: relative;
&nbsp; &nbsp;top: 8px;
&nbsp; &nbsp;height: 90px;
&nbsp; &nbsp;border: 0px;
}
.yt_logo {
&nbsp; &nbsp;position: relative;
&nbsp; &nbsp;top: 8px;
&nbsp; &nbsp;right: 0px;
&nbsp; &nbsp;border: 0px;
}
</style>

<script type="text/javascript">
/* YouTube Thumbnail Links in Posts by SubDevo */
/* Global Footer - Please leave this header intact. Do not repost. */
/* [url]http://interoceandesigns.com[/url] or [url]http://lsdp.proboards.com[/url] */

var ytLogo="http://i53.tinypic.com/2h4jkzk.png"; // Logo Image URL

if(/(calendar|pm|pre)view|search2|display/i.test(pb_action)){
&nbsp; &nbsp;var n=document.getElementsByTagName("font"),a,b,e,f,i,m,t="_blank",yt,x=-1;
&nbsp; &nbsp;yt=/(http:\/\/www.youtube\.com\/watch)(_popup)?\?v=(.+?)($|&)/i;
&nbsp; &nbsp;while(n[++x]){
&nbsp; &nbsp;&nbsp; &nbsp;if(n[x].innerHTML.indexOf("google_ad_section")!=-1){
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;a=n[x].getElementsByTagName("a");i=-1;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;while(a[++i]){ m=a[i];
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if(yt.test(m.href)&&yt.test(m.innerHTML)){
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;e=RegExp.$1; f=RegExp.$3; b=document.createElement("span");
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;m.innerHTML="<img class='yt_thumb' src='http://img.youtube.com/vi/"+f+"/default.jpg' "+
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;"title='Watch in Popup' \/>"; f="?v="+f; m.href=e+"_popup"+f; m.target=t;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if(document.uniqueID){b.style.marginRight="5px";}
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;b.className="yt_container"; m.parentNode.insertBefore(b,m); b.appendChild(m);
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;b.innerHTML+="<br><div style='text-align: right;'><a href='"+
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;e+f+"' target='+t+' ><img class='yt_logo' src='"+ytLogo+
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;"' title='Watch on YouTube' /><\/a><\/div>";
}}}}}
</script>

Some of you may want a larger thumbnail. This is about 33% larger. Be aware that the image is resized on the fly and the quality of the resized image is dependent upon the browser and version the user is viewing with. IE7 has the worst resize algorithm and it doesn't look that great. Just something to keep in mind.
Use this image as the logo image in var ytLogo in the code: http://i55.tinypic.com/2mp0t3p.png

And replace the CSS portion with this:

<style type="text/css">
/* YouTube Thumbnail Links by SubDevo CSS */
.yt_container {
   display: inline-block;
   background: url(http://i51.tinypic.com/90vbzp.png) no-repeat;
   text-align: center;
   height: 190px;
   width: 200px;
   margin-bottom: 5px;
}
.yt_thumb {
   position: relative;
   top: 8px;
   height: 125px;
   border: 0px;
}
.yt_logo {
   position: relative;
   top: 8px;
   right: 0px;
   border: 0px;
}
</style>


Advanced:

You may use your own image for the background of the thumbnail and also for the logo.
The background URL is put into the CSS. The Logo image URL goes into the script (code).

.yt_container

This affects the entire thumbnail.
The background image goes here and also the height and width of the image used.
Putting a border statement here will surround the entire thumbnail.

.yt_thumb

This affects the actual YouTube thumbnail image.
Use higher values for "top" to move it down.
Keep the height set to 90 for the default YouTube thumbnail image size. Anything larger than 90 will stretch the image and the quality of it will lessen.
Changing border from "0" will put a border around the actual YouTube thumbnail.

.yt_logo

This affects the small logo image that you set in the code.
Use higher values for "top" to move it down.
Use higher values for "right" to move it to the LEFT.
Changing border from "0" will put a border around the logo image.

For reference:

Small Background:
Default: http://i52.tinypic.com/6hkrp4.png
Black: http://i51.tinypic.com/20jigrn.png
Logo: http://i53.tinypic.com/2h4jkzk.png

Large Background:
Default: http://i51.tinypic.com/90vbzp.png
Black: http://i51.tinypic.com/2znr1mx.png
Logo: http://i55.tinypic.com/2mp0t3p.png

Examples:

[image] [image]
« Last Edit: Aug 16, 2011, 10:34am by SubDevo »Link to Post - Back to Top  IP: Logged

[image] [image]
[image]
Why are you looking at my signature, [ME]?
Speed
Moderator
v5 Theme Support
member is offline

[avatar]

The Vortex


[homepage]

Joined: Apr 2011
Gender: Male
Posts: 5,571
Location: In The Vortex Of IOD
Karma: 215
 Re: YouTube Thumbnail Links in Posts
« Reply #1 on Aug 13, 2011, 11:39am »

Awesome!



EDIT

SubDevo, if you have time check out my test board, youtube test thread.
« Last Edit: Aug 13, 2011, 1:34pm by Speed »Link to Post - Back to Top  IP: Logged

[image]
[image]
WARNING FOR [ME]! DO NOT CLICK HERE!
aRMY83
Elite Member
IOD Supporter
member is offline

[avatar]

It's me!


[homepage]

Joined: Mar 2010
Gender: Male
Posts: 1,077
Location: Just a Stone's Throw Away!
Karma: 40
 Re: YouTube Thumbnail Links in Posts
« Reply #2 on Aug 13, 2011, 1:46pm »

Nice code SubDevo, real nice!

@Speed.... Nice youtube test thread and now ya got me thinking... [image]
Link to Post - Back to Top  IP: Logged

[image]

[image]
Speed
Moderator
v5 Theme Support
member is offline

[avatar]

The Vortex


[homepage]

Joined: Apr 2011
Gender: Male
Posts: 5,571
Location: In The Vortex Of IOD
Karma: 215
 Re: YouTube Thumbnail Links in Posts
« Reply #3 on Aug 13, 2011, 2:08pm »

Thanks aRMY83!

haa haa thinking about?????
Link to Post - Back to Top  IP: Logged

[image]
[image]
WARNING FOR [ME]! DO NOT CLICK HERE!
aRMY83
Elite Member
IOD Supporter
member is offline

[avatar]

It's me!


[homepage]

Joined: Mar 2010
Gender: Male
Posts: 1,077
Location: Just a Stone's Throw Away!
Karma: 40
 Re: YouTube Thumbnail Links in Posts
« Reply #4 on Aug 13, 2011, 3:50pm »


Aug 13, 2011, 2:08pm, Speed wrote:
Thanks aRMY83!

haa haa thinking about?????


Placing all my youtube's in one thread w/titles above each vid.
Link to Post - Back to Top  IP: Logged

[image]

[image]
SubDevo
Co-Admin
Code Support
member is offline

[avatar]

Creator of LSD...


[homepage]

Joined: Mar 2009
Gender: Male
Posts: 2,594
Location: MI, USA
Karma: 102
 Re: YouTube Thumbnail Links in Posts
« Reply #5 on Aug 13, 2011, 8:40pm »

Now you guys are getting it! Yeah Speed. That is pretty cool. I would put a space between each link to make them separate, but that is just me. ;)

I love this little code! Multiple vids per post! Pages load fast! NO ads! And it still looks like the youtube embed with the thumbnail image! 8-)
« Last Edit: Aug 13, 2011, 8:40pm by SubDevo »Link to Post - Back to Top  IP: Logged

[image] [image]
[image]
Why are you looking at my signature, [ME]?
Speed
Moderator
v5 Theme Support
member is offline

[avatar]

The Vortex


[homepage]

Joined: Apr 2011
Gender: Male
Posts: 5,571
Location: In The Vortex Of IOD
Karma: 215
 Re: YouTube Thumbnail Links in Posts
« Reply #6 on Aug 13, 2011, 11:01pm »

Props for the code SubDevo!
Thanks
Link to Post - Back to Top  IP: Logged

[image]
[image]
WARNING FOR [ME]! DO NOT CLICK HERE!
OJ
Moderator
member is offline

[avatar]

[yim] [msn]
[homepage]

Joined: Nov 2010
Gender: Male
Posts: 976
Location: California
Karma: 53
 Re: YouTube Thumbnail Links in Posts
« Reply #7 on Aug 14, 2011, 5:44am »

Awesome code bro! This looks very cool!

Umm, I know you said not to do this, but I would like to change the sizes of the thumbnails to 200px width, and 190px height. I tried doing it on my own, but it's too confusing. Could you help me out?

Also, I just noticed that the code wont work if you try to use other bb codes with it. :-/
I tried centering it, and when I did, it showed me the link rather than the thumbnail. Would you be able to fix this?


Ok so after trial and error, I figured out that for you to be able to use bb with this, you would need to leave a space between the link and the bb tag, like so:

[center] YouTube URL [/center]

instead of how you would normally do this:

[center]YouTube URL[/center]
« Last Edit: Aug 14, 2011, 5:57am by OJ »Link to Post - Back to Top  IP: Logged

[image]
SubDevo
Co-Admin
Code Support
member is offline

[avatar]

Creator of LSD...


[homepage]

Joined: Mar 2009
Gender: Male
Posts: 2,594
Location: MI, USA
Karma: 102
 Re: YouTube Thumbnail Links in Posts
« Reply #8 on Aug 14, 2011, 7:50am »

Hey everybody! Grab the code again if you are using it. I made a small change since I noticed that IE didn't put a space between the videos and also some "old" thumbnails are a bit larger than the rest and it pushed the small YouTube logo down too far. Both have been fixed. I would not have noticed these if it weren't for Speed Demon's test post. ;)



It's not the code that doesn't work without a space, it is the way PB parses for URLs in a post.
PB won't convert it to a link unless there is a space before http: (even without this code) unless it is at the beginning of a line. This includes a link in a sentence (without UBBC).

This will be a link
http://www.google.com/
No link here because no space beforehttp://www.google.com/
So with UBBC, you need to just put a space before, after is not necessary.



I guessed it. I KNEW you would be the first to ask to make it bigger! I just KNEW IT!

I enlarged the background image and the small YouTube log that I'm currently using.
It isn't as nice as it could be...
And we'll have to resize the thumbnail image on the fly. Which looks like crap in IE7!
Hopefully IE8 is better and other browsers should look "acceptable". IE has the worst resize algorithm.
This is the reason for the size that I decided upon.
Give this a shot. I might add this to the original post for a larger option or maybe just leave it here.
I'm not happy with it...

Code removed and added to the original code post.
« Last Edit: Aug 30, 2011, 9:41pm by SubDevo »Link to Post - Back to Top  IP: Logged

[image] [image]
[image]
Why are you looking at my signature, [ME]?
OJ
Moderator
member is offline

[avatar]

[yim] [msn]
[homepage]

Joined: Nov 2010
Gender: Male
Posts: 976
Location: California
Karma: 53
 Re: YouTube Thumbnail Links in Posts
« Reply #9 on Aug 14, 2011, 11:30am »

Haha! You're starting to know me Sub. ;D

I changed the background, and I think it looks pretty good: Clicky

I looked at all browsers (except Opera), and they look the same too.

The only thing though, I would like to know if you could move the Youtube log, a bit to the left and a bit lower? I want it to be in the middle of the text.
« Last Edit: Aug 14, 2011, 11:31am by OJ »Link to Post - Back to Top  IP: Logged

[image]
SubDevo
Co-Admin
Code Support
member is offline

[avatar]

Creator of LSD...


[homepage]

Joined: Mar 2009
Gender: Male
Posts: 2,594
Location: MI, USA
Karma: 102
 Re: YouTube Thumbnail Links in Posts
« Reply #10 on Aug 14, 2011, 12:38pm »

Add the Yellow to this line:

"<a href='"+e+f+"' target='+t+' ><img class='yt_logo' src='http://i55.tinypic"+

Now add this to the class:

img.yt_logo {
   top: 20px;
   right: 8px;
}


I would change the top value first in .youtube_thumb img to about 18px to get the thumbnail with even black borders around it. Then position the logo. But, if you move it, you will have to redo your background image because it will cover up xtreme elites.
« Last Edit: Aug 15, 2011, 1:40am by SubDevo »Link to Post - Back to Top  IP: Logged

[image] [image]
[image]
Why are you looking at my signature, [ME]?
OJ
Moderator
member is offline

[avatar]

[yim] [msn]
[homepage]

Joined: Nov 2010
Gender: Male
Posts: 976
Location: California
Karma: 53
 Re: YouTube Thumbnail Links in Posts
« Reply #11 on Aug 14, 2011, 1:02pm »

Ok so I added the class, but it doesn't seem to move the logo when I change the values. No matter what I put in. :-/
Link to Post - Back to Top  IP: Logged

[image]
Speed
Moderator
v5 Theme Support
member is offline

[avatar]

The Vortex


[homepage]

Joined: Apr 2011
Gender: Male
Posts: 5,571
Location: In The Vortex Of IOD
Karma: 215
 Re: YouTube Thumbnail Links in Posts
« Reply #12 on Aug 14, 2011, 1:35pm »


Aug 14, 2011, 7:50am, SubDevo wrote:
Hey everybody! Grab the code again if you are using it. I made a small change since I noticed that IE didn't put a space between the videos and also some "old" thumbnails are a bit larger than the rest and it pushed the small YouTube logo down too far. Both have been fixed. I would not have noticed these if it weren't for Speed Demon's test post. ;)






I was going to ask you about that, good catch and fix, works perfect.

Thank you

Link to Post - Back to Top  IP: Logged

[image]
[image]
WARNING FOR [ME]! DO NOT CLICK HERE!
SubDevo
Co-Admin
Code Support
member is offline

[avatar]

Creator of LSD...


[homepage]

Joined: Mar 2009
Gender: Male
Posts: 2,594
Location: MI, USA
Karma: 102
 Re: YouTube Thumbnail Links in Posts
« Reply #13 on Aug 15, 2011, 12:56am »


Aug 14, 2011, 1:02pm, OJ wrote:
Ok so I added the class, but it doesn't seem to move the logo when I change the values. No matter what I put in. :-/

GAAHH! I forgot the dot . before the class name! But that isn't the only issue. It needed higher specificity. Grag the CSS again from my previous post.

Speed, It wouldn't have been fixed as fast, if you hadn't had that test post. The "no space" only happens in IE. And it would have been a long time till someone brought up the positioning issue since those larger thumbnail sizes are rare (older videos). ;)
« Last Edit: Aug 15, 2011, 7:13am by SubDevo »Link to Post - Back to Top  IP: Logged

[image] [image]
[image]
Why are you looking at my signature, [ME]?
Speed
Moderator
v5 Theme Support
member is offline

[avatar]

The Vortex


[homepage]

Joined: Apr 2011
Gender: Male
Posts: 5,571
Location: In The Vortex Of IOD
Karma: 215
 Re: YouTube Thumbnail Links in Posts
« Reply #14 on Aug 15, 2011, 9:24am »


Aug 15, 2011, 12:56am, SubDevo wrote:


Speed, It wouldn't have been fixed as fast, if you hadn't had that test post. The "no space" only happens in IE. And it would have been a long time till someone brought up the positioning issue since those larger thumbnail sizes are rare (older videos). ;)


cool, I am glad it worked out the way it did!
Link to Post - Back to Top  IP: Logged

[image]
[image]
WARNING FOR [ME]! DO NOT CLICK HERE!
Page 1 of 3 » Jump to page   Go    [Search This Thread] [Share Topic] [Print]

Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!
Terms of Service | Privacy Policy | Notice | FTC Disclosure | Report Abuse | Mobile