Skip to content

Commit

Permalink
Merge branch 'embed-default-protocol' of https://github.com/flugsio/q…
Browse files Browse the repository at this point in the history
…uill into flugsio-embed-default-protocol
  • Loading branch information
jhchen committed Jun 21, 2017
2 parents 2bafa85 + dfdc03a commit 0b2af05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions test/unit/theme/base/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ describe('BaseTooltip', function() {
expect(this.container.querySelector('.ql-video').src).toContain('https://www.youtube.com/embed/QHH3iSeDBLo');
});

it('uses https as default youtube video url protocol', function() {
insertVideo(this.tooltip, 'youtube.com/watch?v=QHH3iSeDBLo');
expect(this.container.querySelector('.ql-video').src).toContain('https://www.youtube.com/embed/QHH3iSeDBLo');
});

it('converts vimeo video url to embedded', function() {
insertVideo(this.tooltip, 'http://vimeo.com/47762693');
expect(this.container.querySelector('.ql-video').src).toContain('http://player.vimeo.com/video/47762693/');
Expand All @@ -48,6 +53,11 @@ describe('BaseTooltip', function() {
expect(this.container.querySelector('.ql-video').src).toContain('https://player.vimeo.com/video/47762693/');
});

it('uses https as default vimeo video url protocol', function() {
insertVideo(this.tooltip, 'vimeo.com/47762693');
expect(this.container.querySelector('.ql-video').src).toContain('https://player.vimeo.com/video/47762693/');
});

function insertVideo(tooltip, url) {
tooltip.textbox.value = url;
tooltip.root.setAttribute('data-mode', 'video');
Expand Down
10 changes: 5 additions & 5 deletions themes/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ class BaseTooltip extends Tooltip {


function extractVideoUrl(url) {
let match = url.match(/^(https?):\/\/(?:(?:www|m)\.)?youtube\.com\/watch.*v=([a-zA-Z0-9_-]+)/) ||
url.match(/^(https?):\/\/(?:(?:www|m)\.)?youtu\.be\/([a-zA-Z0-9_-]+)/);
let match = url.match(/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtube\.com\/watch.*v=([a-zA-Z0-9_-]+)/) ||
url.match(/^(?:(https?):\/\/)?(?:(?:www|m)\.)?youtu\.be\/([a-zA-Z0-9_-]+)/);
if (match) {
return match[1] + '://www.youtube.com/embed/' + match[2] + '?showinfo=0';
return (match[1] || 'https') + '://www.youtube.com/embed/' + match[2] + '?showinfo=0';
}
if (match = url.match(/^(https?):\/\/(?:www\.)?vimeo\.com\/(\d+)/)) { // eslint-disable-line no-cond-assign
return match[1] + '://player.vimeo.com/video/' + match[2] + '/';
if (match = url.match(/^(?:(https?):\/\/)?(?:www\.)?vimeo\.com\/(\d+)/)) { // eslint-disable-line no-cond-assign
return (match[1] || 'https') + '://player.vimeo.com/video/' + match[2] + '/';
}
return url;
}
Expand Down

0 comments on commit 0b2af05

Please sign in to comment.