-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.playlist.js
73 lines (48 loc) · 2.22 KB
/
jquery.playlist.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
/*
* jQuery Playlist Plugin
*
* Author: Cameron Skene
* Description: List any YouTube Playlist
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($){
jQuery.fn.playlist = function(options) {
defaults = {
id: "D1D23519DF6539EC",
orderBy: "position",
startIndex: "1",
maxResults: "20",
thumbSize: "hqDefault"
};
o = $.extend(defaults, options);
return this.each(function() {
var elem = $(this);
$.getJSON("https://gdata.youtube.com/feeds/api/playlists/"+o.id+"?v=2&alt=jsonc&orderby="+o.orderBy+"&start-index="+o.startIndex+"&max-results="+o.maxResults+"&callback=?",function(data) {
var data = data.data;
var author = data.author;
var title = data.title;
var items = data.items;
var html = [];
html.push("<h2>"+author+"</h2>");
html.push("<h3>"+title+"</h3>");
html.push("<ol>");
$.each(items, function(index, value) {
var item = items[index];
var itemThumb = item.video.thumbnail[o.thumbSize],
itemTitle = item.video.title,
itemURL = item.video.player["default"];
html.push("<li>");
html.push("<h4 class='item-title'>");
html.push(itemTitle);
html.push("</h4>");
html.push('<a href="'+itemURL+'"><img src="'+itemThumb+'" alt=""/></a>');
})
html.push("</ol>");
elem.append(html.join(''));
})
})
};
})(jQuery);