I am making a jquery plugin which will embed videos from youtube and vimeo (and eventually other sites). Right now I have this code:
(function($) {
$.fn.embedFrame = function() {
var youtube = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
var vimeo = /(?:http?s?:\/\/)?(?:www\.)?(?:vimeo\.com)\/?(.+)/g;
this.filter("a").html(function() {
// CHECK IF THE LINK HREF MATCHES ANY OF THE ABOVE REGEX VARIABLE RULES
// IF THE HREF MATCHES, RETURN AN IFRAME EMBED OF THE VIDEO
});
return this;
};
}(jQuery));
I have a few questions:
- How can I check if the link
hrefmatches any of the regex rules? - Is there a better way to organize my code? I plan to add many more video sites in the future.
Thanks.