jarvis
Members-
Posts
543 -
Joined
-
Last visited
Everything posted by jarvis
-
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
You've been more than helpful, thanks. Will continue to try & work out what the issue is -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Thats ok, sorry! I just can't see why it wont work, especially as you say your one does! Just frustrating as I never thought this would turn out to be such a mare! I do really appreciate your help though, especially as you're at work! :-) -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Here's my complete js just incase I've missed something: //------------------------------------------------- // youtube playlist jquery plugin // Created by [email protected] // www.geckonewmedia.com // // v1.1 - updated to allow fullscreen // - thanks Ashraf for the request //------------------------------------------------- jQuery.fn.ytplaylist = function(options) { // default settings var options = jQuery.extend( { holderId: 'ytvideo', playerHeight: '258', playerWidth: '399', addThumbs: false, thumbSize: 'small', showInline: false, autoPlay: true, showRelated: true, allowFullScreen: false },options); return this.each(function() { var selector = $(this); var autoPlay = ""; var showRelated = "&rel=0"; var fullScreen = ""; if(options.autoPlay) autoPlay = "&autoplay=1"; if(options.showRelated) showRelated = "&rel=1"; if(options.allowFullScreen) fullScreen = "&fs=1"; //throw a youtube player in function play(optionVars) { var options = optionVars.split('|'); var id = options[0]; var urlType = options[1]; //alert(options); //alert(urlType); var html = ''; html += '<object height="'+options.playerHeight+'" width="'+options.playerWidth+'">'; html += '<param name="movie" value="http://www.'+urlType+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"> </param>'; html += '<param name="wmode" value="transparent"> </param>'; if(options.allowFullScreen) { html += '<param name="allowfullscreen" value="true"> </param>'; } html += '<embed src="http://www.'+urlType+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"'; if(options.allowFullScreen) { html += ' allowfullscreen="true" '; } html += 'type="application/x-shockwave-flash" wmode="transparent" height="'+options.playerHeight+'" width="'+options.playerWidth+'"></embed>'; html += '</object>'; return html; }; //grab a youtube id from a (clean, no querystring) url (thanks to http://jquery-howto.blogspot.com/2009/05/jyoutube-jquery-youtube-thumbnail.html) function youtubeid(url) { var ytid = url.match("[\\?&]v=([^]*)"); var regex = /(facebook|youtube)/i; var type = regex.exec(url); ytid = ytid[1]; return ytid + '|' + type[0]; }; //load inital video var firstVid = selector.children("li:first-child").addClass("currentvideo").children("a").attr("href"); $("#"+options.holderId+"").html(play(youtubeid(firstVid))); //load video on request selector.children("li").children("a").click(function() { if(options.showInline) { $("li.currentvideo").removeClass("currentvideo"); $(this).parent("li").addClass("currentvideo").html(play(youtubeid($(this).attr("href")))); } else { $("#"+options.holderId+"").html(play(youtubeid($(this).attr("href")))); $(this).parent().parent("ul").find("li.currentvideo").removeClass("currentvideo"); $(this).parent("li").addClass("currentvideo"); } return false; }); //do we want thumns with that? if(options.addThumbs) { selector.children().each(function(i){ var replacedText = $(this).text(); if(options.thumbSize == 'small') { var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/2.jpg"; } else { var thumbUrl = "http://img.youtube.com/vi/"+youtubeid($(this).children("a").attr("href"))+"/0.jpg"; } $(this).children("a").empty().html("<img src='"+thumbUrl+"' alt='"+replacedText+"' />"+replacedText).attr("title", replacedText); }); } }); }; Odd yours works and mine wont so guessing I've not set something perhaps? -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Hmmm, so where am I going wrong? The facebook vids I'm using should be ok but I am logged in. Can I email you the scripts I'm using to see if I've missed something? -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Sorry, you 've lost me. :-( The alert wont work if I use it in the current file or a new one -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Forgot to add, it has a js error: html is undefined -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
That doesn't do anything either: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script> alert(html); </script> </head> <body> </body> </html> Appreciate this! I feel such a noob -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Erm you mean in a new html doc right? On its own with nothing else?? -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Ok created a new js file called temp, added the above. Added it as an include but nothing happens. I'm guessing something should? Thanks -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
No, no changes. It's odd then as I see what it should do, it should return in the URL that alert, i.e. facebook or youtube. Pretty cool but odd it won't work. Hmmm.... -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Like so: var id = options[0]; var urlType = options[1]; //alert(options); alert(urlType); That returns facebook or youtube without the vid id -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Sorry, when you say after its definition? Where do you mean :-( embarassed -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Hi, It's showing the video ID then facebook or youtube (depending which video I click) Thanks -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Thanks Andy-H I've tried it but to no avail. I notice the embed code has '+urlType+' However, I can't see that in your code as a variable. Should it be there? -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Thanks TeNDoLLA but I'm not sure how best to use that? Sorry to sound daft! What if a link was given a class value, i.e. facebook or youtube. Could I then get the class from the link and use that instead? -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
It's purely been done that way so we can style the page how we want, give the effect we're after and equally, it's going to be a dynamic list, so the client can upload the facebook or youtube URL. This way seemed the best option (at the time!). The code we have seems simple enough, I really didnt think it'd be this cumbersome trying to detect a facebook or youtube link you see :-( -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Thanks again WebStyles and Andy-H. Here's the webpage: <!-- main loading area --> <div id="ytvideo"></div> <!-- /main loading area --> <!-- youtube library holder --> <div class="yt_holder"> <div class="yt_holder_title">More films</div> <!-- video library --> <ul class="demo"> <li><a href="http://www.facebook.com/#!/video/video.php?v=123">Video 1</a></li> <li><a href="http://www.facebook.com/#!/video/video.php?v=456">Video 2</a></li> <li><a href="http://www.facebook.com/#!/video/video.php?v=789">Video 3</a></li> <li><a href="http://www.youtube.com/watch?v=w0ffwDYo00Q">Video 4</a></li> </ul> <!-- video library --> </div> <!-- /youtube library holder --> At the top of the page is the following js include: <script src="js/jquery.youtubeplaylist.js" type="text/javascript"></script> <script type="text/ecmascript"> $(function() { $("ul.demo").ytplaylist({addThumbs:true, autoPlay: false, holderId: 'ytvideo'}); }); </script> The js file jquery.youtubeplaylist.js has the following: jQuery.fn.ytplaylist = function(options) { // default settings var options = jQuery.extend( { holderId: 'ytvideo', playerHeight: '258', playerWidth: '399', addThumbs: false, thumbSize: 'small', showInline: false, autoPlay: true, showRelated: true, allowFullScreen: false },options); return this.each(function() { var selector = $(this); var theURL = document.getElementById("ytvideo").innerHTML; var autoPlay = ""; var showRelated = "&rel=0"; var fullScreen = ""; if(options.autoPlay) autoPlay = "&autoplay=1"; if(options.showRelated) showRelated = "&rel=1"; if(options.allowFullScreen) fullScreen = "&fs=1"; //throw a youtube player in function play(id) { var html = ''; html += '<object height="'+options.playerHeight+'" width="'+options.playerWidth+'">'; html += '<param name="movie" value="http://www.'+theURL+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"> </param>'; html += '<param name="wmode" value="transparent"> </param>'; if(options.allowFullScreen) { html += '<param name="allowfullscreen" value="true"> </param>'; } html += '<embed src="http://www.'+theURL+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"'; if(options.allowFullScreen) { html += ' allowfullscreen="true" '; } html += 'type="application/x-shockwave-flash" wmode="transparent" height="'+options.playerHeight+'" width="'+options.playerWidth+'"></embed>'; html += '</object>'; return html; }; //grab a youtube id from a (clean, no querystring) url (thanks to http://jquery-howto.blogspot.com/2009/05/jyoutube-jquery-youtube-thumbnail.html) function youtubeid(url) { var ytid = url.match("[\\?&]v=([^&#]*)"); ytid = ytid[1]; return ytid; }; //load inital video var firstVid = selector.children("li:first-child").addClass("currentvideo").children("a").attr("href"); $("#"+options.holderId+"").html(play(youtubeid(firstVid))); //load video on request selector.children("li").children("a").click(function() { if(options.showInline) { $("li.currentvideo").removeClass("currentvideo"); $(this).parent("li").addClass("currentvideo").html(play(youtubeid($(this).attr("href")))); } else { $("#"+options.holderId+"").html(play(youtubeid($(this).attr("href")))); $(this).parent().parent("ul").find("li.currentvideo").removeClass("currentvideo"); $(this).parent("li").addClass("currentvideo"); } return false; }); I know that the container with id=ytvideo will remain empty at all times and is just a reference point for the js (above). I somehow need to grab the URL of the selected video in order to determine if it's a facebook URL or youtube URL. That way I can get the code to update the flash player in the js code. Otherwise I can only get it to work with one or other due to this line: html += '<embed src="http://www.youtube.com/v/'+id+autoPlay+showRelated+fullScreen+'"'; Does that help? Thanks, your patience & assistance is really REALLY appreciated!! :-) -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Thanks WebStyles but doesn't <div id="ytvideo"></div> have the URL as it's got a holderID? Perhaps my understanding of how it works is wrong. The demo: http://geckohub.com/jquery/youtubeplaylist/ may explain what I mean? Sorry :-( -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Thanks TeNDoLLA but it's not getting the main URL it's from one within the page - sorry, I should've made that clear. It's so I can use this: http://www.geckonewmedia.com/blog/2009/8/14/jquery-youtube-playlist-plugin---youtubeplaylist but for facebook and youtube. However, I'm trying to make it dynamic with a php cms hence why I'm on this forum :-) I think it may be more js though :-( -
get info from URL and set as a javascript variable
jarvis replied to jarvis's topic in PHP Coding Help
Thanks Webstyles, I think that makes sense! I've set a div: <div id="ytvideo"></div> This shows the video selected from a list of videos in the main player. I've then added this line to my seperate js file: var theURL = document.getElementById("ytvideo").innerHTML; Then I altered the 2 lines in my emved code like so: html += '<param name="movie" value="http://www.'+theURL+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"> </param>'; AND html += '<embed src="http://www.'+theURL+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"'; This seperate file is called from the other doc <script src="js/jquery.youtubeplaylist.js" type="text/javascript"></script> Sadly, it doesn't seem to work. Is is because it's a seperate js doc or will that line you kindly recommended retrieve the info regardless? TIA -
Hi All, Im trying to use PHP to get some info from URLs, once I have the data, I wish to set it in a seperate javascript file as a variable. Firstly, is this even possible? My links are like so: http://www.facebook.com/#!/video/video.php?v= http://www.youtube.com/watch?v= I wish to use PHP to get the link type, either facebook or youtube. Like so: var URLtype = ""; So I can then build a dynamic flash media player but need it for this line: html += '<embed src="http://www.'+URLtype+'.com/v/'+id+autoPlay+showRelated+fullScreen+'"'; I hope someone can help as I can't seem to work it out :-( TIA jarvis
-
Thanks cyberRobot. Will also review my code for $Banner_Image_[$i] as it doesn't need to be assigned twice Thanks
-
Holy cow! Yeah that solved it! So I know & understand, why is that? Would rather learn for next time than rely on others to bail me out Thanks
-
Thanks cyberRobot, I'll tidy it after. I'm trying to apply the above code to this loop as well: <?php $Banner_Image = get_post_meta($post->ID, 'Banner_Image', true); ?> <?php if ($Banner_Image!='') : ?> <li class="item1"> <?php $Banner_Image = get_post_meta($post->ID, 'Banner_Image', true); echo wp_get_attachment_image($Banner_Image, 'large'); ?> </li> <?php endif; ?> <?php $Banner_Image_2 = get_post_meta($post->ID, 'Banner_Image_2', true); ?> <?php if ($Banner_Image_2!='') : ?> <li class="item2"> <?php $Banner_Image_2 = get_post_meta($post->ID, 'Banner_Image_2', true); echo wp_get_attachment_image($Banner_Image_2, 'large'); ?> </li> <?php endif; ?> This is what I've amended it to: <?php for ($i=1; $i<6; $i++) { $Banner_Image_[$i] = get_post_meta($post->ID, "Banner_Image_$i", true); if ($Banner_Image_[$i]!='') :?> <li class="item<?php echo $i; ?>"> <?php $Banner_Image_[$i] = get_post_meta($post->ID, 'Banner_Image_$i', true); echo wp_get_attachment_image($Banner_Image_[$i], 'large'); ?> </li> <?php endif; } ?> I thought I was being smug, instead, I think my code has officially b**ch slapped me as it won't show the images :-( Have I missed something obvious? Thanks again everyone
-
Hi, Needed a slight amend but thanks to your code, it now works. Here's the final code: <?php for ($i=1; $i<6; $i++) { $Banner_Image_[$i] = get_post_meta($post->ID, "Banner_Image_$i", true); if ($Banner_Image_[$i]!='') :?> <a href="javascript:goto('.item<?php echo $i; ?>')"><?php echo $i; ?></a> <?php endif; } ?> Thanks again!