jQuery Google Search Videobar

A jQuery plugin that sets a div or span to show a Google Search Videobar. If you find this plugin useful please vote for it on the jQuery site.

The current version is 1.0.1 and is available under the GPL and MIT licences. For more detail see the documentation reference page.

Introduction

The Google Search Videobar functionality can easily be added to a division. It displays a set of video links based on provided search terms. The default search term is 'jquery'.

Google places some restrictions on your use of this service, including obtaining a key specific to a target URL providing the service, making the Web site freely accessible, and showing included Google branding. See the link above for more details.

You can also remove the GSVideobar widget if it is no longer required.

Default videobar:

 

$('#defaultVideobar').gsvideobar();

$('#removeVideobar').toggle(
	function() {
		$(this).text('Re-attach');
		$('#defaultVideobar').gsvideobar('destroy');
	},
	function() {
		$(this).text('Remove');
		$('#defaultVideobar').gsvideobar();
	}
);

You can override the defaults globally as shown below:

$.gsvideobar.setDefaults({horizontal: true});

Processed fields are marked with a class of hasGSVideobar and are not re-processed if targetted a second time.

Formatting Options

You have some control over the appearance of the videobar.

Formatting:

 

 

$('#formatVideobar').gsvideobar();
		
var thumbnails = [$.gsvideobar.thumbnailsSmall, $.gsvideobar.thumbnailsMedium];
		
$('#format input,#format select').change(function() {
	$('#formatVideobar').gsvideobar('change',
		{closeText: $('#close').val(),
		horizontal: $('#orientation').val() == 'true',
		thumbnailSize: thumbnails[$('#thumbnails').val()],
		manyResults: $('#results').val() == 'true'});
});

Player Options

The default is a floating video player, appearing next to the videobar. Alternately, you can provide the jQuery selector or object for a container to hold the player somewhere else on the page. You can also set the player's size in your own CSS.

#playerArea .playerInnerBox_gsvb .player_gsvb { width: 400px; height: 200px; }

Recommended sizes maintain a 4:3 aspect ratio, with widths over 300px gaining an extra 20px in height. For example:

Inline player:

 

$('#playerVideobar').gsvideobar({player: '#playerArea'});

Multiple Videobars

You can connect multiple videobars to the one player. Connect the first videobar to the player area, then mark other videobars as "slaves" to the original "master".

Multiple videobars:

 

 

 

$('#masterVideobar').gsvideobar({search: 'australia', player: '#sharedArea'});
$('#slaveVideobar').gsvideobar({search: 'cats', master: '#masterVideobar'});

Cycling Searches

You can set the videobar up to cycle automatically through a set of search terms, with control over the interval between cycles and the order. Just pass an array of search terms when attaching the videobar.

Connect a status area to the videobar to show all the search terms, indicating which is currently being used and allowing the user to change to another term.

Cycling:

 

 

$('#cycleVideobar').gsvideobar({statusArea: '#cycleStatus',
	search: ['jquery', 'australia', 'cats', 'tennis']});
	
var times = [$.gsvideobar.cycleVShort, $.gsvideobar.cycleShort,
	$.gsvideobar.cycleMedium, $.gsvideobar.cycleLong];
var modes = [$.gsvideobar.cycleRandom, $.gsvideobar.cycleLinear];
		
$('#cycle select').change(function() {
	$('#cycleVideobar').gsvideobar('change',
		{cycleTime: times[$('#cycleTime').val()],
		cycleMode: modes[$('#cycleMode').val()]});
});

YouTube Specifics

Within YouTube you can find specific feeds, optionally within a time period. Or you can target a particular channel, and optionally search for terms.

YouTube feeds:

  OR

 

 

 

$('#youtubeVideobar').gsvideobar({search: $.gsvideobar.ytMostViewed});
		
var feeds = [$.gsvideobar.ytMostViewed,
	$.gsvideobar.ytRecentlyFeatured, $.gsvideobar.ytTopRated];
var periods = ['', $.gsvideobar.ytToday, $.gsvideobar.ytThisWeek,
	$.gsvideobar.ytThisMonth, $.gsvideobar.ytAllTime];
		
$('#youtube select').change(function() {
	$('#youtubeVideobar').gsvideobar('search',
		feeds[$('#ytFeed').val()] + periods[$('#ytPeriod').val()]);
});

$('#ytSearch').click(function() {
	$('#youtubeVideobar').gsvideobar('search',
		$.gsvideobar.youTube($('#ytChannel').val()) +
		' ' + $('#ytKeywords').val());
});

In the Wild

This tab highlights examples of this plugin in use "in the wild".

To add another example, please contact me (kbwood{at}iinet.com.au) and provide the plugin name, the URL of your site, its title, and a short description of its purpose and where/how the plugin is used.

Quick Reference

A full list of all possible settings is shown below. Note that not all would apply in all cases. For more detail see the documentation reference page.

$(selector).gsvideobar({
	horizontal: true, // True for horizontal display, false for vertical
	thumbnailSize: this.thumbnailsMedium, // The size of the video thumbnails
	player: '', // jQuery selector, jQuery object, or element
		// for the player area, or '' for a floating player
	master: '', // jQuery selector, jQuery object, or element
		// for the master videobar on the same page
	closeText: '', // Text displayed at the top of the player to close it
	search: 'jquery', // Single or list of search terms
	manyResults: false, // True for many results, false for only a few
	cycleTime: this.cycleMedium, // Time between cycles of the search terms
	cycleMode: this.cycleRandom, // Mode of cycling through the search terms
	statusArea: '' // jQuery selector, jQuery object, or element for a status area
});

Usage

  1. Include the jQuery library in the head section of your page.
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  2. Set your Google Search key for use with your Web site.
    <script type="text/javascript">
    $.googleSearchKey = 'ABQIAAAA...2Z_iWfuw';
    </script>
  3. Download and include the jQuery GSVideobar CSS and JavaScript in the head section of your page.
    <style type="text/css">@import "jquery.gsvideobar.css";</style>
    <script type="text/javascript" src="jquery.gsvideobar.js"></script>
    Alternately, you can use the packed version jquery.gsvideobar.pack.js (3.3K vs 7.5K) or minified version jquery.gsvideobar.min.js (3.5K, 1.5K when zipped).
  4. Connect the GSVideobar functionality to your divs or spans.
    $(selector).gsvideobar({search: ...});

For more detail see the documentation reference page.

Comments

None as yet.

Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.

Change History

VersionDateChanges
1.0.126 Dec 2009
  • Corrected initialisation in Chrome
1.0.029 Nov 2008
  • Initial release

Valid HTML 4.01 Strict