/*
 * Collapsible widget extension: tabs behavior
 * https://github.com/filamentgroup/collapsible
 * Copyright (c) 2014 Filament Group, Inc.
 * Licensed under the MIT, GPL licenses.
 */

;(function ($, window, document) {

	$( document ).bind( "init", function( e ){
		var pluginName = "collapsible";
		var activeTabClass = "tab-active";
		var $collapsible = $( e.target ).closest( "." + pluginName );
		var $tabContainer = $collapsible.parent();
		var $tabNav = $tabContainer.find( ".tabnav" );
		var self;
		var id;

		if( $collapsible.is( "." + pluginName ) && $tabContainer.is( ".tabs" ) ){
			self = $collapsible.data( pluginName );
			id = self.content.attr( "id" );
			$tabNav.find( "[aria-controls=" + id + "]" ).remove();

			self.$tabHeader = $( "<a href='#'>" + self.header[0].innerHTML + "</a>" ).attr( "aria-controls", id );
			self.header.css( 'display', 'none' );

			self.$tabHeader.bind( window.tappy ? "tap" : "click", function( e ){
				e.preventDefault();
				e.stopPropagation();

				if( self.$tabHeader.is( '.' + activeTabClass ) ) {
					self.$tabHeader.removeClass( activeTabClass );
				} else {
					$tabContainer.find( '.' + activeTabClass ).removeClass( activeTabClass );
					self.$tabHeader.addClass( activeTabClass );
				}

				self.toggle();
			});

			if( !$tabNav.length ) {
				$tabNav = $( "<nav class='tabnav'></nav>" );
				$tabContainer.prepend( $tabNav );
			}

			if( !self.collapsed ) {
				self.$tabHeader.addClass( activeTabClass );
				self._expand();
			}

			$tabNav.append( self.$tabHeader );
		}
	});

})(jQuery, window, document);

@@ -828,19 +828,68 @@
 ls%22, id 
+).attr(%22role%22,%22tab%22).attr(%22aria-selected%22,%22false%22
 );%0A
-
 %09%09%09self.
@@ -1236,24 +1236,54 @@
 iveTabClass 
+).attr(%22aria-selected%22,%22false%22
 );%0A%09%09%09%09%09self
@@ -1311,32 +1311,61 @@
  activeTabClass 
+).attr(%22aria-selected%22,%22true%22
 );%0A%09%09%09%09%7D%0A%0A%09%09%09%09se
@@ -1528,24 +1528,24 @@
 llapsed ) %7B%0A
-
 %09%09%09%09self.$ta
@@ -1573,24 +1573,53 @@
 iveTabClass 
+).attr(%22aria-selected%22,%22true%22
 );%0A%09%09%09%09self.

Improve WCAG support so screen readers can read back if tab is active.