PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.3.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.3.4
3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 All 197 releases
convertkit / resources / backend / js / tabs.js

tabs.js in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 2.3.4, at resources/backend/js/tabs.js

124 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Provides functionality for tabbed interfaces.
3 *
4 * @since 2.2.5
5 *
6 * @package ConvertKit
7 * @author ConvertKit
8 */
9
10 /**
11 * Initializes tabbed interfaces
12 *
13 * @since 2.2.5
14 */
15 function convertKitTabsInit() {
16
17 ( function ( $ ) {
18
19 // Safely call this function by destroying any previously initialized instances.
20 convertKitTabsDestroy();
21
22 // Iterate through all JS tab instances, initializing each one.
23 $( '.convertkit-js-tabs' ).each(
24 function () {
25
26 const nav_tab_container = $( this ),
27 nav_tab_panels_container = $( nav_tab_container ).data( 'panels-container' ),
28 nav_tab_panel = $( nav_tab_container ).data( 'panel' ),
29 nav_tab_active = $( nav_tab_container ).data( 'active' ),
30 match_height = $( nav_tab_container ).data( 'match-height' );
31
32 // Call update.
33 convertKitTabsUpdate( nav_tab_container, nav_tab_panels_container, nav_tab_panel, nav_tab_active, $( 'a.' + nav_tab_active, $( nav_tab_container ) ).attr( 'href' ) );
34
35 // If fix height is set, define the height of the content areas to match the parent of the nav tab container.
36 if ( typeof match_height !== 'undefined' ) {
37 $( nav_tab_panels_container ).height( $( match_height ).innerHeight() );
38 }
39
40 // Register a listener when a tab is clicked.
41 $( nav_tab_container ).on(
42 'click.convertkit_tabs',
43 'a',
44 function ( e ) {
45
46 e.preventDefault();
47
48 // Update the UI to show the active tab and content associated with it.
49 convertKitTabsUpdate( nav_tab_container, nav_tab_panels_container, nav_tab_panel, nav_tab_active, $( this ).attr( 'href' ) );
50
51 }
52 );
53
54 }
55 );
56
57 } )( jQuery );
58
59 }
60
61 /**
62 * For the given active tab:
63 * - Hides all other content in the group
64 * - Shows content associated with the active tab
65 *
66 * @since 1.0.0
67 *
68 * @param object nav_tab_container <ul> Navigation Tab Container
69 * @param string nav_tab_panels_container ID of element containing content panel, to display, which associate with the navigation tabs
70 * @param string nav_tab_panel Class of elements containing content panels, to hide, which associate with the navigation tabs
71 * @param string nav_tab_active Class to apply to the clicked active_tab element
72 * @param string active_tab ID of <a> tab which has been selected / clicked
73 */
74 function convertKitTabsUpdate( nav_tab_container, nav_tab_panels_container, nav_tab_panel, nav_tab_active, active_tab ) {
75
76 ( function ( $ ) {
77
78 // If we don't have an active tab at this point, we don't have any tabs, so bail.
79 if ( typeof active_tab === 'undefined' ) {
80 return;
81 }
82 if ( active_tab.length === 0 ) {
83 return;
84 }
85
86 // Deactivate all tabs in this container.
87 $( 'a', $( nav_tab_container ) ).removeClass( nav_tab_active );
88
89 // Hide all panels in this container.
90 $( nav_tab_panel, $( nav_tab_panels_container ) ).hide();
91
92 // Activate the clicked / selected tab in this container.
93 $( 'a[href="' + active_tab + '"]', $( nav_tab_container ) ).addClass( nav_tab_active );
94
95 // Show the active tab's panels in this container.
96 $( active_tab ).show();
97
98 } )( jQuery );
99
100 }
101
102 /**
103 * Destroys previously initialized tabbed interfaces, no longer
104 * listening to events.
105 *
106 * @since 1.0.0
107 */
108 function convertKitTabsDestroy() {
109
110 ( function ( $ ) {
111
112 // Iterate through all JS tab instances, destroying each one.
113 $( '.convertkit-js-tabs' ).each(
114 function () {
115
116 $( this ).off( 'click.convertkit_tabs', 'a' );
117
118 }
119 );
120
121 } )( jQuery );
122
123 }
124