-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.youtube.js
84 lines (72 loc) · 2.78 KB
/
jquery.youtube.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* jQuery Embiggen plugin
*
* Author: Cameron Skene
* Description: Embed YouTube videos using YouTubes iframe or object/embed methods.
* URL: https://github.com/camskene/jquery-youtube
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($){
$.fn.youtube = function(options) {
var defaults = {
iframe: true,
videoID: "",
width: "480",
height: "390",
play: "0",
loop: "0",
link: "external",
controls: "1",
autohide: "1"
};
var o = $.extend(defaults, options);
var videoDIV = "yt-" + o.videoID;
var height;
if(o.autohide === "1") {
height = o.height - 30;
}
if(o.autohide === "0") {
height = o.height;
}
if( (o.autohide === "0") && (o.iframe === false) ) {
height = o.height - 5;
}
return this.each(function() {
if (o.iframe === true) {
$(this).html('<iframe id="'+videoDIV+'" width="'+o.width+'" height="'+height+'" src="http://www.youtube.com/embed/' + o.videoID + '?enablejsapi=1&version=3&wmode=transparent&rel=0&autohide='+o.autohide+'&showinfo=0&controls='+o.controls+'&autoplay='+o.play+'" frameborder="0" allowfullscreen></iframe>');
}
if (o.iframe === false) {
$(this).html('<div id="' + videoDIV + '">')
var flashvars = {
hd: "1",
fs: "1",
fmt: "18",
egm: "0",
loop: o.loop,
autoplay: o.play,
showinfo: "0",
autohide: o.autohide,
showsearch: "0",
enablejsapi: "1",
playerapiid: this.id,
wmode: "transparent"
};
var params = {
wmode: "transparent",
allowscriptaccess: "always",
allowfullscreen: "true",
allownetworking: o.link
};
var attributes = {
id: videoDIV,
name: videoDIV
};
// All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
swfobject.embedSWF("http://www.youtube.com/v/" + o.videoID +"&rel=0&version=1", videoDIV, o.width, height, "8", false, flashvars, params, attributes);
}
})
};
}) (jQuery);