From 134ac37362da1f8c75f44517f976391e2c3d8bec Mon Sep 17 00:00:00 2001 From: alchemyunited Date: Fri, 19 Dec 2014 16:40:18 -0500 Subject: [PATCH] add new and shift triggers --- js/cmb2.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/js/cmb2.js b/js/cmb2.js index 8fc70faf6..2b9854cf9 100755 --- a/js/cmb2.js +++ b/js/cmb2.js @@ -367,6 +367,7 @@ window.CMB2 = (function(window, document, $, undefined){ }; cmb.afterRowInsert = function( $row, group ) { + var $focus = $row.find('input:not([type="button"]), textarea, select').first(); if ( $focus.length ) { if ( group ) { @@ -446,6 +447,10 @@ window.CMB2 = (function(window, document, $, undefined){ event.preventDefault(); var $self = $(this); + + // before anything significant happens + $self.trigger( 'cmb2_add_group_row_start', $self ); + var $table = $('#'+ $self.data('selector')); var $oldRow = $table.find('.cmb-repeatable-grouping').last(); var prevNum = parseInt( $oldRow.data('iterator') ); @@ -458,7 +463,7 @@ window.CMB2 = (function(window, document, $, undefined){ $oldRow.after( $newRow ); cmb.afterRowInsert( $newRow, true ); - + if ( $table.find('.cmb-repeatable-grouping').length <= 1 ) { $table.find('.cmb-remove-group-row').prop( 'disabled', true ); } else { @@ -504,6 +509,9 @@ window.CMB2 = (function(window, document, $, undefined){ var number = $table.find('.cmb-repeatable-grouping').length; if ( number > 1 ) { + + $table.trigger( 'cmb2_remove_group_row_start', $self ); + // when a group is removed loop through all next groups and update fields names $parent.nextAll( '.cmb-repeatable-grouping' ).find( cmb.repeatEls ).each( cmb.updateNameAttr ); @@ -552,6 +560,9 @@ window.CMB2 = (function(window, document, $, undefined){ event.preventDefault(); var $self = $(this); + // before anything signif happens + $self.trigger( 'cmb2_shift_rows_enter', $self ); + var $parent = $self.parents( '.cmb-repeatable-grouping' ); var $goto = $self.hasClass( 'move-up' ) ? $parent.prev( '.cmb-repeatable-grouping' ) : $parent.next( '.cmb-repeatable-grouping' ); @@ -559,6 +570,9 @@ window.CMB2 = (function(window, document, $, undefined){ return; } + // we're gonna shift + $self.trigger( 'cmb2_shift_rows_start', $self ); + var inputVals = []; // Loop this items fields $parent.find( cmb.repeatEls ).each( function() { @@ -605,6 +619,9 @@ window.CMB2 = (function(window, document, $, undefined){ $element.val( inputVals[ index ]['val'] ); } }); + + // shift done + $self.trigger( 'cmb2_shift_rows_complete', $self ); }; cmb.initPickers = function( $timePickers, $datePickers, $colorPickers ) {