Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Adds support for vimeo videos
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krienbühl committed Mar 18, 2016
1 parent 249c28f commit 5b07b9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions onegov/town/assets/js/videoframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

var expressions = [
/https?:\/\/(www\.youtube\.com)\/watch\?v=([^&]+)/i,
/https?:\/\/(www\.vimeo\.com)\/([0-9]+)/i
/https?:\/\/([w]{0,3}\.?vimeo\.com).*?\/([0-9]+)/i
];

var getVideoId = function(url) {
Expand All @@ -25,6 +25,20 @@ var getVideoId = function(url) {
return null;
};

var rgb2hex = function(rgb) {
if (rgb.search("rgb") === -1) {
return rgb;
} else {
match = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/);

function hex(x) {
return ("0" + parseInt(x, 10).toString(16)).slice(-2);
}

return "#" + hex(match[1]) + hex(match[2]) + hex(match[3]);
}
};

var getVideoUrl = function(host, id) {
if (host.match(/youtube\.com/gi)) {
var origin = window.location.protocol +
Expand All @@ -35,7 +49,8 @@ var getVideoUrl = function(host, id) {
}

if (host.match(/vimeo\.com/gi)) {
return "https://player.vimeo.com/video/" + id;
var color = rgb2hex($('a:first').css('color')).replace('#', '');
return "https://player.vimeo.com/video/" + id + '?badge=0&byline=0&portrait=0&title=0&color=' + color;
}

return null;
Expand Down
3 changes: 2 additions & 1 deletion onegov/town/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def annotate_html(html):
condition = ' or '.join(
'starts-with(@href, "{}")'.format(url) for url in {
'https://www.youtube.com',
'https://www.vimeo.com'
'https://www.vimeo.com',
'https://vimeo',
}
)

Expand Down

0 comments on commit 5b07b9e

Please sign in to comment.