Home »
FUDforum Development »
Plugins and Code Hacks »
simple embed hack for youtube/polls/etc
simple embed hack for youtube/polls/etc [message #161885] |
Tue, 16 February 2010 20:41 |
|
This is a little fud forum hack I setup a while ago, I'm afraid I'm terribly behind keeping my fudforum upto date since the last time I tried an update things went badly. So it's not a plugin just some javascript for you to copypasta.
Here is a jqueery based hack that turns links posted in any forum msgs into appropriate embedded content. The content is chosen based on the link, so a link to a youtube video page turns into a youtube video embed, that sort of thing. Look at the code to see what sites are supported and add your own to support more, the available sites below are just what I needed.
Its horribly hacky and horribly simple and horribly useful
Make sure jquery is included, eg <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> and add something like this into your main site template, personally I include the code as a separate js file but you could just copypasta the code below.
You can for instance see a polldady poll working here http://www.wetgenes.com/forum/index.php?t=msg&th=2430&start=0&r id=2
Hope its helpful to someone.
<script type="text/javascript">
// hit up jquery to update links into embeded things when document is ready
function expand_links()
{
$(".MsgR3 a").each(
function()
{
var width="600";
var height="450";
var link=$(this).attr("href");
var linktype="unknown";
var tail;
var dots;
var aa;
var vid;
var box;
var megaupload;
if(!link) { return; }
dots=link.split(".");
tail=dots[dots.length-1];
tail=tail.toLowerCase();
if( tail=="png" || tail=="gif" || tail=="jpg" )
{
linktype="image";
}
if(dots[1])
{
switch( dots[1].toLowerCase() )
{
case "youtube":
vid=link.split("v=")[1];
if(vid)
{
vid=vid.substr(0,11); // there are 11 chars in a you tube id
linktype="youtube";
}
break;
case "veoh":
vid=link.split("permalinkId=")[1];
if(vid)
{
vid=vid.split("&")[0]; // the id before the &
vid=vid.split("\"")[0]; // the id before the "
vid=vid.split("'")[0]; // the id before the '
linktype="veoh";
}
break;
case "polldaddy":
if(tail=="js")
{
poll=link.split(".js")[0];
poll=poll.split("/p/")[1];
}
else
{
poll=link.split("/");
poll=poll[poll.length-1] ? poll[poll.length-1] : poll[poll.length-2];
}
if(poll)
{
linktype="polldaddy";
}
break;
}
}
switch(linktype)
{
case "polldaddy":
$(this).before("<a name=\"pd_a_"+poll+"\" style=\"display: inline; padding: 0px; margin: 0px;\"></a><div class=\"PDS_Poll\" id=\"PDI_container"+poll+"\"></div><script type=\"text/javascript\" charset=\"utf-8\" src=\"http://static.polldaddy.com/p/"+poll+".js\"></script><br />");
break;
case "image":
$(this).before("<img src=\""+link+"\" width=\""+width+"\" /><br />");
break;
case "youtube":
$(this).before(
'<object width="'+width+'" height="'+height+'"><param name="movie" value="http://www.youtube.com/v/'+vid+'&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'+vid+'&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object>'
+"<br />"
);
break;
case "veoh" :
$(this).before(
'<embed src="http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.4.3.1006&permalinkId='+vid+'&player=videodetailsembedded&videoAutoPlay=0&id=anonymous" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'" ></embed>'
+"<br />"
);
break;
}
});
}
// init if we have jquery available
if($)
{
$(document).ready(expand_links);
}
</script>
|
|
|
Goto Forum:
Current Time: Sat Nov 23 19:16:50 GMT 2024
Total time taken to generate the page: 0.04650 seconds