Created
September 22, 2014 13:45
-
-
Save chrisjhoughton/b73f8396d9b6484f83f0 to your computer and use it in GitHub Desktop.
Get the video embed code from either a Vimeo or Youtube URL. Depends on Mout (moutjs.com)
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
var getParam = require("mout/queryString/getParam"); | |
module.exports = function (url) { | |
if (!url) { | |
return ""; | |
} | |
// Youtube | |
if (url.indexOf("youtube.com") !== -1) { | |
// Get the id | |
var videoId = getParam(url, "v"); | |
if (videoId) { | |
return '<iframe width="620" height="400" src="//www.youtube.com/embed/'+videoId+'" frameborder="0" allowfullscreen></iframe>'; | |
} | |
} | |
// Vimeo | |
else if (url.indexOf("vimeo.com") !== -1) { | |
// get the id | |
// e.g. "http://vimeo.com/87110435" | |
var arr = url.split(/http:\/\/vimeo.com\//) | |
var videoId = arr[1]; | |
// insert to embed code | |
return '<iframe src="//player.vimeo.com/video/'+videoId+'" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment