Created
February 3, 2014 18:53
-
-
Save krasimir/8789934 to your computer and use it in GitHub Desktop.
Convert YouTube link to an iframe
This file contains 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 filterTextArea = function(text) { | |
text = text.replace(/(<([^>]+)>)/ig, ''); | |
var re = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?([\w\-]{10,12})(?:&feature)?(?:[\w\-]{0})?/g; | |
var iframe = '<iframe width="640" height="360" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>'; | |
text = iframe.replace('$1', text.split(re)[1]); | |
return text; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment