PageSourceSearch

https://www.samesfordcc.com/v9/media/js/jqueryyoutubechannel/v1.0.0/jquery.youtube.channel.js

js samesfordcc.com collected 2026-09-24 12:20:20 UTC 5,041 bytes, 171 lines download raw bytes

1/**
2 *	Plugin which renders the YouTube channel videos list to the page
3 *	@author:  H. Yankov (hristo.yankov at gmail dot com)
4 *	@version: 1.0.0 (Nov/27/2009)
5 *	http://yankov.us
6 */
7
8/*
9 * Heavily modified from original version by ddcrandallm:
10 *	- cleaned up source to eliminate globals
11 *	- code passes JSLint
12 *	- removed baked-in HTML widths for more flexibility
13 *	- removed unnecessary (empty) table cells from YouTube markup service
14 *  - added feature to change player URL
15 *  - added optional callback method "afterLoad"
16 */
17
18(function () {
19	 var window = this,
20		$ = window.jQuery,
21		__mainDiv,
22		__preLoaderHTML,
23		__opts,
24		__jQueryYouTubeChannelReceiveData = function (data) {
25			$.each(data.feed.entry, function(i,e) {
26				if (e && e.content && e.content.$t) {
27					__mainDiv.append(e.content.$t);
28				}
29			});
30	
31			// Mark the first div in the list
32			$(__mainDiv).find("div:first").addClass("firstVideo");
33	
34			// Now hide objects depending on the settings and fix the img style
35			$(__mainDiv).find("div").width('').each(function () {
36				$('table', this).css({
37					tableLayout: 'fixed',
38					width: '100%'
39				});
40		
41				// Do we need to remove borders from image?
42				if (__opts.removeBordersFromImage) {
43					$(this).find("table > tbody > tr:first > td:first > div").css("border", "0px");
44					$(this).find("table > tbody > tr:first > td:first > div > a > img").css("border", "0px");
45				}
46		
47				// Open in new tab?
48				if (__opts.linksInNewWindow) {
49					$(this).find("table > tbody > tr:first > td:first > div > a").attr("target", "_blank");
50					$(this).find("table > tbody > tr:first > td:eq(1) > div > a").attr("target", "_blank");
51				}
52	
53				// Hide the video length
54				if (__opts.hideVideoLength) {
55					$(this).find("table > tbody > tr:last > td:first").hide();
56				}
57		
58				var additionalInfo = $(this).find("table > tbody > tr:first > td:last");
59		
60				if (__opts.hideFrom) {
61					$(additionalInfo).find("div:eq(0)").hide();
62				}
63		
64				if (__opts.hideViews) {
65					$(additionalInfo).find("div:eq(1)").hide();
66				}
67		
68				if (__opts.hideRating) {
69					$(additionalInfo).find("div:eq(2)").hide();
70				}
71			
72				if (__opts.hideNumberOfRatings) {
73					$(additionalInfo).find("div:eq(3)").hide();
74				}
75			
76				// Always hide the additional categories
77				$(this).find("table > tbody > tr:last > td:last").hide();
78		
79				// remove widths set in HTML by YouTube
80				$('*', this).removeAttr('width');
81		
82				// set colspan
83				$('tbody > tr:first > td:eq(1), tbody > tr:eq(1) > td:eq(0)', this).attr('colspan', '2');
84		
85				// remove last cell?
86				if (__opts.hideViews && __opts.hideRating && __opts.hideNumberOfRatings) {
87					$('tr > td:eq(2)', this).remove();
88				}
89				
90				// update links to optionally specified alternate URL
91				// in videoLinkUrl setting
92				if (__opts.videoLinkUrl) {
93					$('a[href*="watch?v="]').each(function () {
94						var href = __opts.videoLinkUrl,
95							videoId = $(this).attr('href').toString().match(/v=([^&$]*)/),
96							html = $(this).html(),
97							style = $(this).attr('style'),
98							linkString = 'a style="' + style + '"';
99						
100						videoId =
101							(videoId && videoId.length && videoId[1]) ?
102							videoId[1] :
103							null;
104						
105						if (!videoId) {
106							href = $(this).attr('href');
107						}
108						
109						linkString += ' href="' + href.replace('|videoId|', videoId) + '"';
110						
111						if (__opts.videoLinkClasses) {
112							linkString += ' class="' + __opts.videoLinkClasses + '"';
113						}
114						if (__opts.videoLinkAttributes) {
115							linkString += ' ' + __opts.videoLinkAttributes;
116						}
117						
118						linkString = '<' + linkString + '>' + html + '</a>';
119						
120						$(this).replaceWith(linkString);
121					});
122				}
123			});
124			// Remove the preloader and show the content
125			$(__preLoaderHTML).remove();
126			__mainDiv.show();
127			
128			// trigger callback
129			if ($.isFunction(__opts.afterLoad)) {
130				__opts.afterLoad();
131			}
132		};
133
134	$.fn.youTubeChannel = function(options) {
135		var videoDiv = $(this);
136
137		$.fn.youTubeChannel.defaults = {
138			userName: null,
139			loadingText: "Loading...",
140			linksInNewWindow: true,
141			hideVideoLength: false,
142			hideFrom: true,
143			hideViews: true,
144			hideRating: true,
145			hideNumberOfRatings: true,
146			removeBordersFromImage: true,
147			videoLinkUrl: null,
148			videoLinkClasses: null,
149			videoLinkAttributes: null,
150			afterLoad: null
151		};
152			
153		__opts = $.extend({}, $.fn.youTubeChannel.defaults, options);
154	
155		return this.each(function() {
156			if (__opts.userName) {
157				videoDiv.append("<div class=\"channel_div\"></div>");
158				__mainDiv = $(".channel_div", videoDiv);
159				__mainDiv.hide();
160			
161				__preLoaderHTML = $("<p class=\"loader\">" + __opts.loadingText + "</p>");
162				videoDiv.append(__preLoaderHTML);
163			
164				// TODO: Error handling!
165				$.getScript(window.location.protocol + "//gdata.youtube.com/feeds/base/users/" + __opts.userName + "/uploads?alt=json-in-script&callback=__jQueryYouTubeChannelReceiveData");
166			}
167		});
168	};
169	
170	window.__jQueryYouTubeChannelReceiveData = __jQueryYouTubeChannelReceiveData;
171}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.