$()

in src/main/resources/js/site.js [19:106]


$(document).ready(function() {

	//
	// This is a hack to enable google-code-prettify to work with maven.
	//
	// The problem is that maven, when building the site, replaces:
	// <pre class="prettyprint">...</pre>
	// with:
	// <div class="prettyprint"><pre>...</pre></div>
	//
	// Effectively, it removes the class parameter from the <pre> element, which
	// is required for google-code-prettify to work.
	// 
	// This hack restores the class of all <pre> elements which are the child of 
	// a <div class="prettyprint">.
	//
	$('pre').each(function() {
		var parent = $(this).parent();
		
		if (parent.hasClass('prettyprint')) {
			parent.removeClass('prettyprint');
			$(this).addClass('prettyprint');
		}
		
		if (parent.hasClass('linenums')) {
			parent.removeClass('linenums');
			$(this).addClass('linenums');
		}
	})
	
	// Hack to add default visuals to tables
	$('table').each(function() {
		if ($(this).hasClass('bodyTable')) {
			
			// Remove border="1" which is added by maven
			this.border = 0;
			
			// Add bootstrap table styling
			$(this).addClass('table table-striped table-bordered');
		}
	});
	
	// Render tabs
	$('.auto-tabs').each(function(groupid) {

		// Find tab bar
		$(this).find('ul').each(function() {

			// Add styling
			$(this).addClass('nav nav-tabs');

			// Go tab bar items
			$(this).find('li').each(function(itemid) {
			
				// Set first tab as active
				if (itemid == 0) {
					$(this).addClass('active');
				}
				
				// Replace text with a link to tab contents
				var name = $(this).html();
				var link = $('<a>')
					.attr('href', '#' + 'tab-' + groupid + '-' + itemid)
					.attr('data-toggle', 'tab')
					.html(name);
				$(this).html(link);
			});
		});
		
		// Find tab contents
		$(this).find('.tab-content .tab-pane').each(function(itemid) {
			
			// Set first tab as active
			if (itemid == 0) {
				$(this).addClass('active');
			}
			
			// Set the tab id
			$(this).attr('id', 'tab-' + groupid + '-' + itemid);
		});
	});
	
	// Make external links open in new tab
	$('a.external').attr('target', '_blank');
	
	// Trigger prettyprint
	prettyPrint();
});