', {
'class' : newLinkClass,
'data-toggle' : 'collapse',
'data-parent' : '#collapse-' + $tabGroup.attr( 'id' ),
'href' : '#' + newHash,
'html' : $this.html()
} )
)
)
).append(
$( '', {
'id' : newHash,
'class' : 'panel-collapse collapse'
} )
)
);
} );
$tabGroup.next().after( collapseDiv );
$tabGroup.addClass( hidden );
$( '.tab-content.responsive' ).addClass( hidden );
} );
fakewaffle.checkResize();
fakewaffle.bindTabToCollapse();
if ( activeTab ) {
$( activeTab ).collapse( 'show' );
}
};
fakewaffle.checkResize = function () {
if ( $( '.panel-group.responsive' ).is( ':visible' ) === true && fakewaffle.currentPosition === 'tabs' ) {
fakewaffle.tabToPanel();
fakewaffle.currentPosition = 'panel';
} else if ( $( '.panel-group.responsive' ).is( ':visible' ) === false && fakewaffle.currentPosition === 'panel' ) {
fakewaffle.panelToTab();
fakewaffle.currentPosition = 'tabs';
}
};
fakewaffle.tabToPanel = function () {
var tabGroups = $( '.nav-tabs.responsive' );
$.each( tabGroups, function ( index, tabGroup ) {
// Find the tab
var tabContents = $( tabGroup ).next( '.tab-content' ).find( '.tab-pane' );
$.each( tabContents, function ( index, tabContent ) {
// Find the id to move the element to
var destinationId = $( tabContent ).attr( 'id' ).replace ( /^/, '#collapse-' );
// Convert tab to panel and move to destination
$( tabContent )
.removeClass( 'tab-pane' )
.addClass( 'panel-body' )
.appendTo( $( destinationId ) );
} );
} );
};
fakewaffle.panelToTab = function () {
var panelGroups = $( '.panel-group.responsive' );
$.each( panelGroups, function ( index, panelGroup ) {
var destinationId = $( panelGroup ).attr( 'id' ).replace( 'collapse-', '#' );
var destination = $( destinationId ).next( '.tab-content' )[ 0 ];
// Find the panel contents
var panelContents = $( panelGroup ).find( '.panel-body' );
// Convert to tab and move to destination
panelContents
.removeClass( 'panel-body' )
.addClass( 'tab-pane' )
.appendTo( $( destination ) );
} );
};
fakewaffle.bindTabToCollapse = function () {
var tabs = $( '.nav-tabs.responsive' ).find( 'li a' );
var collapse = $( '.panel-group.responsive' ).find( '.panel-collapse' );
// Toggle the panels when the associated tab is toggled
tabs.on( 'shown.bs.tab', function ( e ) {
if (fakewaffle.currentPosition === 'tabs') {
var $current = $( e.currentTarget.hash.replace( /#/, '#collapse-' ) );
$current.collapse( 'show' );
if ( e.relatedTarget ) {
var $previous = $( e.relatedTarget.hash.replace( /#/, '#collapse-' ) );
$previous.collapse( 'hide' );
}
}
} );
// Toggle the tab when the associated panel is toggled
collapse.on( 'shown.bs.collapse', function ( e ) {
if (fakewaffle.currentPosition === 'panel') {
// Activate current tabs
var current = $( e.target ).context.id.replace( /collapse-/g, '#' );
$( 'a[href="' + current + '"]' ).tab( 'show' );
// Update the content with active
var panelGroup = $( e.currentTarget ).closest( '.panel-group.responsive' );
$( panelGroup ).find( '.panel-body' ).removeClass( 'active' );
$( e.currentTarget ).find( '.panel-body' ).addClass( 'active' );
}
} );
};
$( window ).resize( function () {
fakewaffle.checkResize();
} );
return fakewaffle;
}( window.jQuery, fakewaffle || { } ) );