@@ -19,13 +19,33 @@ var FieldmanagerGroupTabs;
19
19
*/
20
20
bindEvents : function ( ) {
21
21
22
- $ ( '.fm-tab-bar a' ) . on ( 'click' , $ . proxy ( function ( e ) {
23
- e . preventDefault ( ) ;
24
- this . selectTab ( $ ( e . currentTarget ) ) ;
22
+ $ ( '.fm-tab-bar' ) . each ( $ . proxy ( function ( k , el ) {
23
+ this . bindClickEvents ( $ ( el ) ) ;
25
24
} , this ) ) ;
26
- $ ( '.fm-tab-bar li' ) . on ( 'click' , $ . proxy ( function ( e ) {
27
- e . preventDefault ( ) ;
28
- this . selectTab ( $ ( e . currentTarget ) . children ( 'a' ) ) ;
25
+ $ ( document ) . on ( 'fm_added_element' , $ . proxy ( function ( e ) {
26
+ var el = $ ( e . target ) ;
27
+ if ( ! $ ( '.fm-tab-bar a' , el ) . length ) {
28
+ return ;
29
+ }
30
+ counter = el . parent ( ) . data ( 'fm-group-counter' ) ;
31
+ if ( ! counter ) {
32
+ counter = el . siblings ( '.fm-item' ) . length - 1 ;
33
+ } else {
34
+ counter ++ ;
35
+ }
36
+ el . parent ( ) . data ( 'fm-group-counter' , counter ) ;
37
+ var replaceProto = function ( el , attr ) {
38
+ el . attr ( attr , el . attr ( attr ) . replace ( '-proto-' , '-' + counter + '-' ) ) ;
39
+ } ;
40
+
41
+ // We also need to set these unique IDs, because FM doesn't do it for us.
42
+ $ ( '.fm-tab-bar a' , el ) . each ( function ( ) {
43
+ replaceProto ( $ ( this ) , 'href' ) ;
44
+ } ) ;
45
+ $ ( '.wp-tabs-panel' , el ) . each ( function ( ) {
46
+ replaceProto ( $ ( this ) , 'id' ) ;
47
+ } ) ;
48
+ this . bindClickEvents ( el ) ;
29
49
} , this ) ) ;
30
50
31
51
if ( this . supportsLocalStorage ( ) ) {
@@ -83,6 +103,20 @@ var FieldmanagerGroupTabs;
83
103
84
104
} ,
85
105
106
+ /**
107
+ * Bind tab item click events
108
+ */
109
+ bindClickEvents : function ( el ) {
110
+ $ ( 'a' , el ) . on ( 'click.fm-select-tab' , $ . proxy ( function ( e ) {
111
+ e . preventDefault ( ) ;
112
+ this . selectTab ( $ ( e . currentTarget ) ) ;
113
+ } , this ) ) ;
114
+ $ ( 'li' , el ) . on ( 'click.fm-select-tab' , $ . proxy ( function ( e ) {
115
+ e . preventDefault ( ) ;
116
+ this . selectTab ( $ ( e . currentTarget ) . children ( 'a' ) ) ;
117
+ } , this ) ) ;
118
+ } ,
119
+
86
120
/**
87
121
* Select a given tab
88
122
*/
0 commit comments