/** * Provides functionality for tabbed interfaces. * * @package WPZincDashboardWidget * @author WP Zinc */ /** * Initializes tabbed interfaces * * @since 1.0.0 */ function wp_zinc_tabs_init() { ( function ( $ ) { // Safely call this function by destroying any previously initialized instances. wp_zinc_tabs_destroy(); // Iterate through all JS tab instances, initializing each one. $( '.wpzinc-js-tabs' ).each( function () { var nav_tab_container = $( this ), nav_tab_panels_container = $( nav_tab_container ).data( 'panels-container' ), nav_tab_panel = $( nav_tab_container ).data( 'panel' ), nav_tab_active = $( nav_tab_container ).data( 'active' ), match_height = $( nav_tab_container ).data( 'match-height' ); // Call update. wp_zinc_tabs_update( nav_tab_container, nav_tab_panels_container, nav_tab_panel, nav_tab_active, $( 'a.' + nav_tab_active, $( nav_tab_container ) ).attr( 'href' ) ); // If fix height is set, define the height of the content areas to match the parent of the nav tab container. if ( typeof match_height !== 'undefined' ) { $( nav_tab_panels_container ).height( $( match_height ).innerHeight() ); } // Register a listener when a tab is clicked. $( nav_tab_container ).on( 'click.wpzinc_tabs', 'a', function ( e ) { // Don't do anything if this is an external URL. if ( location.hostname === this.hostname || ! this.hostname.length ) { // Local. e.preventDefault(); } else { // External. return true; } // Update the UI to show the active tab and content associated with it. wp_zinc_tabs_update( nav_tab_container, nav_tab_panels_container, nav_tab_panel, nav_tab_active, $( this ).attr( 'href' ) ); } ); } ); // Register a listener when a form element has the data-tab attribute, to toggle a tab's enabled/disabled icon. $( '.wpzinc-tab-indicator' ).on( 'change.wpzinc_tab_indicator', function ( e ) { var tab_href = $( this ).data( 'tab' ); if ( $( this ).is( 'input' ) ) { var enabled = $( this ).prop( 'checked' ); } else if ( $( this ).is( 'select' ) ) { var enabled = $( this ).val(); } // Enable or Disable Tab. if ( enabled == 1 ) { $( 'a[href=#' + tab_href + ']' ).addClass( 'enabled' ); } else { $( 'a[href=#' + tab_href + ']' ).removeClass( 'enabled' ); } } ); } )( jQuery ); } /** * For the given active tab: * - Hides all other content in the group * - Shows content associated with the active tab * * @since 1.0.0 * * @param object nav_tab_container