| 1 |
window.WpGetApi = window.WpGetApi || {}; |
| 2 |
|
| 3 |
(function (window, document, $, wpgetapi, undefined) { |
| 4 |
|
| 5 |
'use strict'; |
| 6 |
|
| 7 |
/** |
| 8 |
* Start the JS. |
| 9 |
*/ |
| 10 |
wpgetapi.onReady = function () { |
| 11 |
|
| 12 |
var $page = wpgetapi.page(); |
| 13 |
|
| 14 |
wpgetapi.functionsHelp(); |
| 15 |
|
| 16 |
$page |
| 17 |
.on( 'change keyup', '.field-id input', wpgetapi.functionsHelp ) |
| 18 |
.on( 'cmb2_remove_row cmb2_add_row cmb2_shift_row', wpgetapi.functionsHelp ); |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Adds the endpoint into the functions help section. |
| 24 |
*/ |
| 25 |
wpgetapi.functionsHelp = function ( e ) { |
| 26 |
|
| 27 |
// change, keyup, add_row etc |
| 28 |
if( e && e.type.length > 0 ) { |
| 29 |
|
| 30 |
var $this = $( this ); |
| 31 |
var $group = $this.parents( '.cmb-repeatable-grouping' ); |
| 32 |
|
| 33 |
// if we are adding a group, clear it |
| 34 |
if( e.type == 'cmb2_add_row' ) { |
| 35 |
$group = $( '.cmb-repeatable-grouping' ).last(); |
| 36 |
$group.find( '.functions .endpoint_id' ).html( '' ); |
| 37 |
} |
| 38 |
|
| 39 |
if( $group.length > 0 ) |
| 40 |
$group.find( '.functions .endpoint_id' ).html( $this.val() ); |
| 41 |
|
| 42 |
} else { |
| 43 |
|
| 44 |
$('.cmb-repeatable-grouping').each(function( index, value ) { |
| 45 |
|
| 46 |
var $group = $( this ); |
| 47 |
var endpoint_value = $group.find( '.field-id input' ).val(); |
| 48 |
$group.find( '.functions .endpoint_id' ).html( endpoint_value ); |
| 49 |
|
| 50 |
}); |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Gets jQuery object containing all . Caches the result. |
| 58 |
* |
| 59 |
* @since 1.0.0 |
| 60 |
* |
| 61 |
* @return {Object} jQuery object containing all. |
| 62 |
*/ |
| 63 |
wpgetapi.page = function() { |
| 64 |
if ( wpgetapi.$page ) { |
| 65 |
return wpgetapi.$page; |
| 66 |
} |
| 67 |
wpgetapi.$page = $('.wpgetapi'); |
| 68 |
return wpgetapi.$page; |
| 69 |
}; |
| 70 |
|
| 71 |
$( wpgetapi.onReady ); |
| 72 |
|
| 73 |
}(window, document, jQuery, window.WpGetApi)); |