Skip to content

Commit

Permalink
Add support for youtu.be URLs, closes zen-audio-player#1
Browse files Browse the repository at this point in the history
  • Loading branch information
Shakeel Mohamed committed Apr 26, 2015
1 parent a3fc272 commit eaab652
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions js/everything.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ $(function() {
event.preventDefault();
var formValue = $("#query").val();
if (formValue) {
var shortUrlDomain = "youtu.be";
var url = head;
// YouTube video ID string
if (formValue.indexOf("youtube.com") === -1) {
url += formValue;
}

// YouTube video URL string, parse the v parameter
if (formValue.indexOf("youtube.com") !== -1) {
url += getParameterByName(formValue, "v");
}
else if (formValue.indexOf(shortUrlDomain) !== -1) {
var endPosition = formValue.indexOf("?") === -1 ? formValue.length : formValue.indexOf("?");
var offset = formValue.indexOf(shortUrlDomain) + shortUrlDomain.length + 1; // Skip over the slash also
url += formValue.substring(offset, endPosition);
}
else {
url += getParameterByName(formValue, "v");
// YouTube video ID string
url += formValue;
}

$("#player").attr("src", url + tail);
Expand Down

0 comments on commit eaab652

Please sign in to comment.