-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathiframe.js
More file actions
executable file
·30 lines (30 loc) · 1.5 KB
/
iframe.js
File metadata and controls
executable file
·30 lines (30 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var YtIframe = (function() {
"use strict";
var YtIframe = function (config) {
config.https = config.https || false;
config.width = config.width || 560;
config.height = config.height || 315;
config.cookie = (config.cookie === false) ? false : true;
// build src attribute for iframe, create iframe element and populate it with attributes regarding the config options
var videoSource = (false === config.https) ? 'http://' : 'https://';
videoSource += (false === config.cookie) ? 'www.youtube-nocookie.com/embed/' : 'www.youtube.com/embed/';
videoSource += (-1 === config.videoHash.indexOf('youtube')) ? config.videoHash : config.videoHash.split('v=')[1].split('&')[0];
var iframe = document.createElement('iframe');
iframe.setAttribute('width', parseInt(config.width, 10));
iframe.setAttribute('height', parseInt(config.height, 10));
iframe.setAttribute('src', videoSource);
iframe.setAttribute('frameBorder', 0);
iframe.setAttribute('allowFullScreen', '');
return iframe;
};
return function (config) {
// check if str or obj given, set default values if values are missing
if ('undefined' == typeof config)
return false;
if ('string' == typeof config)
config = {videoHash: config};
if ('object' == typeof config && !config.videoHash)
return false;
return new YtIframe(config);
};
})();