aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSam Potts <sam@selz.com>2016-11-02 16:59:28 +1100
committerGitHub <noreply@github.com>2016-11-02 16:59:28 +1100
commit10561d6c83dec922dda5b8e347bdb555ab6c8556 (patch)
tree4fd0a51799797dc8e15e8cbe6a75e93901b8bbed /src
parenta3ed3093429d5306a89566215207d42a476392d8 (diff)
parent0ef87f93a6e93abbdcf4cc7d949ed6938ab79e11 (diff)
downloadplyr-10561d6c83dec922dda5b8e347bdb555ab6c8556.tar.lz
plyr-10561d6c83dec922dda5b8e347bdb555ab6c8556.tar.xz
plyr-10561d6c83dec922dda5b8e347bdb555ab6c8556.zip
Merge pull request #408 from gurupras/urlparser
Added logic to parse youtube video id
Diffstat (limited to 'src')
-rw-r--r--src/js/plyr.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js
index dd14f767..4ebb060a 100644
--- a/src/js/plyr.js
+++ b/src/js/plyr.js
@@ -3259,6 +3259,19 @@
}
}
+ // Taken from https://gist.github.com/takien/4077195
+ function parseYoutubeVideoId(url) {
+ var videoId;
+ url = url.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
+ if(url[2] !== undefined) {
+ videoId = url[2].split(/[^0-9a-z_\-]/i);
+ videoId = videoId[0];
+ } else {
+ videoId = url;
+ }
+ return videoId;
+ }
+
// Setup a player
function _init() {
// Bail if the element is initialized
@@ -3287,6 +3300,12 @@
plyr.type = media.getAttribute('data-type');
plyr.embedId = media.getAttribute('data-video-id');
+ switch(plyr.type) {
+ case 'youtube':
+ plyr.embedId = parseYoutubeVideoId(plyr.embedId);
+ break;
+ }
+
// Clean up
media.removeAttribute('data-type');
media.removeAttribute('data-video-id');