-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgrt-youtube-popup.js
58 lines (48 loc) · 1.65 KB
/
grt-youtube-popup.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*!
* GRT Youtube Popup - jQuery Plugin
* Version: 1.0
* Author: GRT107
*
* Copyright (c) 2017 GRT107
* Released under the MIT license
*/
(function ( $ ) {
$.fn.grtyoutube = function( options ) {
return this.each(function() {
// Get video ID
var getvideoid = $(this).attr("youtubeid");
// Default options
var settings = $.extend({
videoID: getvideoid,
autoPlay: true,
theme: "dark"
}, options );
// Convert some values
if(settings.autoPlay === true) { settings.autoPlay = 1 } else if(settings.autoPlay === false) { settings.autoPlay = 0 }
if(settings.theme === "dark") { settings.theme = "grtyoutube-dark-theme" } else if(settings.theme === "light") { settings.theme = "grtyoutube-light-theme" }
// Initialize on click
if(getvideoid) {
$(this).on( "click", function() {
$("body").append('<div class="grtyoutube-popup '+settings.theme+'">'+
'<div class="grtyoutube-popup-content">'+
'<span class="grtyoutube-popup-close"></span>'+
'<iframe class="grtyoutube-iframe" src="https://www.youtube.com/embed/'+settings.videoID+'?rel=0&wmode=transparent&autoplay='+settings.autoPlay+'&iv_load_policy=3" allowfullscreen frameborder="0" allow="autoplay; fullscreen"></iframe>'+
'</div>'+
'</div>');
});
}
// Close the box on click or escape
$(this).on('click', function (event) {
event.preventDefault();
$(".grtyoutube-popup-close, .grtyoutube-popup").click(function(){
$(".grtyoutube-popup").remove();
});
});
$(document).keyup(function(event) {
if (event.keyCode == 27){
$(".grtyoutube-popup").remove();
}
});
});
};
}( jQuery ));