Last active
January 1, 2016 19:59
-
-
Save stefansundin/8194147 to your computer and use it in GitHub Desktop.
Google Gadget to embed YouTube videos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Module> | |
<ModulePrefs title="YouTube iframe embed" author="Stefan Sundin" width="640" height="390"></ModulePrefs> | |
<UserPref name="id" datatype="string" default_value="" /> | |
<UserPref name="width" datatype="string" default_value="" /> | |
<UserPref name="height" datatype="string" default_value="" /> | |
<UserPref name="args" datatype="string" default_value="" /> | |
<Content type="html"> | |
<![CDATA[ | |
<script type="text/javascript"> | |
var prefs = new gadgets.Prefs(); | |
var width = prefs.getString("width"); | |
var height = prefs.getString("height"); | |
var args = prefs.getString("args"); | |
var video_id = prefs.getString("id"); | |
//IE | |
if (!window.innerWidth && document.body.offsetWidth) { | |
window.innerWidth = document.body.offsetWidth; | |
window.innerHeight = document.body.offsetHeight; | |
} | |
if (width == "") { | |
if (window.innerWidth) { | |
width = window.innerWidth; | |
height = window.innerHeight; | |
} | |
else { | |
width = 640; | |
height = 390; | |
} | |
} | |
var iframe = document.createElement("iframe"); | |
iframe.setAttribute("class", "youtube-player"); | |
iframe.setAttribute("type", "text/html"); | |
iframe.setAttribute("seamless", "seamless"); | |
iframe.setAttribute("frameborder", 0); | |
iframe.setAttribute("width", width); | |
iframe.setAttribute("height", height); | |
iframe.setAttribute("src", "https://www.youtube.com/embed/"+video_id+(args?"?"+args:"")); | |
document.body.appendChild(iframe); | |
/* Developer notes: | |
https://gist.github.com/stefansundin/8194147 | |
Example use (Google Project Hosting): | |
<wiki:gadget border="0" url="https://gist.githubusercontent.com/stefansundin/8194147/raw/youtube-iframe.xml" up_id="LLtxSkoWKfc" width="640" height="390" /> | |
<wiki:gadget border="0" url="https://gist.githubusercontent.com/stefansundin/8194147/raw/youtube-iframe.xml" up_id="LLtxSkoWKfc" width="1280" height="750" up_args="start=8" /> | |
<wiki:gadget border="0" url="https://gist.githubusercontent.com/stefansundin/8194147/raw/youtube-iframe.xml" up_id="LLtxSkoWKfc" width="1280" height="750" up_args="start=8&rel=0" /> | |
width/height combinations and resulting default quality: | |
560x345 (320p) | |
640x390 (320p) | |
853x510 (480p) | |
1280x750 (720p) | |
1920x1110 (1080p) | |
You can also use parameters up_width=1280 up_height=750 to override detection code. | |
You can specify the parameter "args" if you want to give the player additional arguments. | |
List of available arguments here: https://developers.google.com/youtube/player_parameters | |
One useful argument is "start" which specifies where in the video to start playing. | |
Separate arguments with "&". | |
*/ | |
</script> | |
]]> | |
</Content> | |
</Module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment