Created
May 19, 2015 18:55
-
-
Save grobertson/6bf3d759b99313f13af5 to your computer and use it in GitHub Desktop.
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
$('#id_video_id').live('paste', function() { | |
var onFail = function(found) { | |
alert('Unsupported video service or invalid URL'); | |
console.log(found); | |
} | |
var element = this; | |
var parser = document.createElement('a'); | |
setTimeout(function () { | |
parser.href = $(element).val(); | |
var videoId = new String(); | |
if (parser.hostname === "youtu.be") { | |
videoId = parser.pathname.replace('/', ''); | |
$(element).val(videoId); | |
$("#id_service").val('Y'); | |
}else if(parser.hostname === "youtube.com" || parser.hostname === "www.youtube.com" ) { | |
var matches = parser.search.match(/v\=([A-Za-z0-9\-]+)/); | |
if (matches[1]) { | |
videoId = matches[1]; | |
$(element).val(videoId); | |
$("#id_service").val('Y'); | |
} else { | |
onFail(parser.href); | |
} | |
} else { | |
onFail(parser.href); | |
} | |
}, 300); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment