Skip to content

Commit

Permalink
Parameters support #2
Browse files Browse the repository at this point in the history
  • Loading branch information
vb committed Sep 25, 2016
1 parent 3ff7eeb commit bbe21d5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/lazyframe.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions src/lazyframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Lazyframe = () => {
title: undefined,
apikey: undefined,
initialized: false,
parameters: undefined,
y: undefined,
debounce: 250,
lazyload: true,
Expand All @@ -31,8 +32,8 @@ const Lazyframe = () => {
vine: (m) => (m && m[1].length === 11) ? m[1] : false
},
src: {
youtube: (s) => `https://www.youtube.com/embed/${s.id}/?autoplay=1`,
vimeo: (s) => `https://player.vimeo.com/video/${s.id}/?autoplay=1`,
youtube: (s) => `https://www.youtube.com/embed/${s.id}/?${s.parameters}`,
vimeo: (s) => `https://player.vimeo.com/video/${s.id}/?${s.parameters}`,
vine: (s) => `https://vine.co/v/${s.id}/embed/simple`
},
endpoints: {
Expand Down Expand Up @@ -121,9 +122,12 @@ const Lazyframe = () => {
const options = Object.assign({},
settings,
attr,
{y: el.offsetTop}
{
y: el.offsetTop,
parameters: extractParams(attr.src)
}
);

if (options.vendor) {
const match = options.src.match(constants.regex[options.vendor]);
options.id = constants.condition[options.vendor](match);
Expand All @@ -132,6 +136,20 @@ const Lazyframe = () => {
return options;

}

function extractParams(url) {
let params = url.split('?');

if (params[1]) {
params = params[1];
const hasAutoplay = params.indexOf('autoplay') !== -1;
return hasAutoplay ? params : params + '&autoplay=1';

} else {
return 'autoplay=1';
}

}

function useApi(settings) {

Expand Down

0 comments on commit bbe21d5

Please sign in to comment.