Skip to content

Commit

Permalink
Merge pull request alleyinteractive#455 from alleyinteractive/392-new…
Browse files Browse the repository at this point in the history
…-tab-click-events

Properly bind tab button click events for new tabbed groups
  • Loading branch information
danielbachhuber committed Feb 20, 2016
2 parents ba310d4 + 75c2d04 commit 6b51fa1
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions js/fieldmanager-group-tabs.js
Expand Up @@ -19,13 +19,33 @@ var FieldmanagerGroupTabs;
*/
bindEvents: function() {

$( '.fm-tab-bar a' ).on( 'click', $.proxy( function( e ) {
e.preventDefault();
this.selectTab( $( e.currentTarget ) );
$('.fm-tab-bar').each( $.proxy( function( k, el ) {
this.bindClickEvents( $( el ) );
}, this ) );
$( '.fm-tab-bar li' ).on( 'click', $.proxy( function( e ) {
e.preventDefault();
this.selectTab( $( e.currentTarget ).children('a') );
$( document ).on( 'fm_added_element', $.proxy( function( e ) {
var el = $( e.target );
if ( ! $( '.fm-tab-bar a', el ).length ) {
return;
}
counter = el.parent().data( 'fm-group-counter' );
if ( ! counter ) {
counter = el.siblings( '.fm-item' ).length - 1;
} else {
counter++;
}
el.parent().data( 'fm-group-counter', counter );
var replaceProto = function( el, attr ) {
el.attr( attr, el.attr( attr ).replace( '-proto-', '-' + counter + '-' ) );
};

// We also need to set these unique IDs, because FM doesn't do it for us.
$( '.fm-tab-bar a', el ).each( function() {
replaceProto( $( this ), 'href' );
});
$( '.wp-tabs-panel', el ).each( function() {
replaceProto( $( this ), 'id' );
});
this.bindClickEvents( el );
}, this ) );

if ( this.supportsLocalStorage() ) {
Expand Down Expand Up @@ -83,6 +103,20 @@ var FieldmanagerGroupTabs;

},

/**
* Bind tab item click events
*/
bindClickEvents: function( el ) {
$( 'a', el ).on( 'click.fm-select-tab', $.proxy( function( e ) {
e.preventDefault();
this.selectTab( $( e.currentTarget ) );
}, this ) );
$( 'li', el ).on( 'click.fm-select-tab', $.proxy( function( e ) {
e.preventDefault();
this.selectTab( $( e.currentTarget ).children('a') );
}, this ) );
},

/**
* Select a given tab
*/
Expand Down

0 comments on commit 6b51fa1

Please sign in to comment.