| @@ -11,120 +11,35 @@ | ||
| 11 | 11 | |
| 12 | 12 | var $page = wpgetapi.page(); |
| 13 | 13 | |
| 14 | 14 | wpgetapi.functionsHelp(); |
| 15 | - wpgetapi.tooltips(); | |
| 16 | - | |
| 15 | + | |
| 17 | 16 | $page |
| 18 | - .on( 'click', '.functions .copy-this', wpgetapi.copyThis ) | |
| 19 | 17 | .on( 'change keyup', '.field-id input', wpgetapi.functionsHelp ) |
| 20 | - .on( 'cmb2_remove_row cmb2_add_row cmb2_shift_row', wpgetapi.functionsHelp ) | |
| 21 | - .on( 'cmb2_add_row', wpgetapi.disableTestUntilSave ); | |
| 18 | + .on( 'cmb2_remove_row cmb2_add_row cmb2_shift_row', wpgetapi.functionsHelp ); | |
| 22 | 19 | |
| 23 | 20 | } |
| 24 | 21 | |
| 25 | - | |
| 26 | 22 | /** |
| 27 | - * Do the tooltips | |
| 23 | + * Adds the endpoint into the functions help section. | |
| 28 | 24 | */ |
| 29 | - wpgetapi.tooltips = function () { | |
| 30 | - $( ".wrap.wpgetapi .dashicons-editor-help" ).tooltip({ | |
| 31 | - items: "[data-tip]", | |
| 32 | - content: function () { | |
| 33 | - return $(this).data("tip"); | |
| 34 | - }, | |
| 35 | - classes: { | |
| 36 | - "ui-tooltip": "wpgetapi-tooltip" | |
| 37 | - }, | |
| 38 | - position: { my: "left+10 center", at: "right center" }, | |
| 39 | - close: function (event, ui) { | |
| 40 | - ui.tooltip.hover( | |
| 41 | - function () { | |
| 42 | - $(this).stop(true).fadeTo(400, 1); | |
| 43 | - }, | |
| 44 | - function () { | |
| 45 | - $(this).fadeOut("400", function () { | |
| 46 | - $(this).remove(); | |
| 47 | - }) | |
| 48 | - }); | |
| 49 | - } | |
| 50 | - }); | |
| 51 | - } | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * Copy the template tag or the shortcode | |
| 55 | - */ | |
| 56 | - wpgetapi.copyThis = function ( e ) { | |
| 57 | - | |
| 58 | - const $this = $( this ); | |
| 59 | - const textToCopy = $this.prev( '.wpgetapi-copy' ).text(); | |
| 60 | - | |
| 61 | - navigator.clipboard.writeText(textToCopy).then( | |
| 62 | - function() { | |
| 63 | - /* clipboard successfully set */ | |
| 64 | - $this.after( '<span class="copied">Copied</span>' ); | |
| 65 | - setTimeout( | |
| 66 | - function() { | |
| 67 | - $( '.copied' ).remove(); | |
| 68 | - }, 3000 | |
| 69 | - ); | |
| 70 | - | |
| 71 | - }, | |
| 72 | - function() { | |
| 73 | - /* clipboard write failed */ | |
| 74 | - $this.append('Oops! Your browser doesn\'t support this.') | |
| 75 | - } | |
| 76 | - ) | |
| 77 | - | |
| 78 | - } | |
| 79 | - | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * Adds the endpoint into the functions help section, | |
| 83 | - * meaning the Template tag and the shortcode. | |
| 84 | - */ | |
| 85 | 25 | wpgetapi.functionsHelp = function ( e ) { |
| 86 | 26 | |
| 87 | - // change, keyup, add_row etc | |
| 88 | - if( e && e.type.length > 0 ) { | |
| 27 | + // set $this depending on how we call function | |
| 28 | + var $this = e ? $( this ) : $( '.field-id input' ); | |
| 29 | + var $group = $this.parents( '.cmb-repeatable-grouping' ); | |
| 89 | 30 | |
| 90 | - var $this = $( this ); | |
| 91 | - var $group = $this.parents( '.cmb-repeatable-grouping' ); | |
| 92 | - | |
| 93 | - // if we are adding a group, clear it | |
| 94 | - if( e.type == 'cmb2_add_row' ) { | |
| 95 | - $group = $( '.cmb-repeatable-grouping' ).last(); | |
| 96 | - $group.find( '.functions .endpoint_id' ).html( '' ); | |
| 97 | - } | |
| 98 | - | |
| 99 | - if( $group.length > 0 ) | |
| 100 | - $group.find( '.functions .endpoint_id' ).html( $this.val() ); | |
| 101 | - | |
| 102 | - } else { | |
| 103 | - | |
| 104 | - $('.cmb-repeatable-grouping').each(function( index, value ) { | |
| 105 | - | |
| 106 | - var $group = $( this ); | |
| 107 | - var endpoint_value = $group.find( '.field-id input' ).val(); | |
| 108 | - $group.find( '.functions .endpoint_id' ).html( endpoint_value ); | |
| 109 | - | |
| 110 | - }); | |
| 111 | - | |
| 31 | + // if we are adding a group, clear it | |
| 32 | + if( e && e.type == 'cmb2_add_row' ) { | |
| 33 | + $group = $( '.cmb-repeatable-grouping' ).last(); | |
| 34 | + $group.find( '.functions .endpoint_id' ).html( '' ); | |
| 112 | 35 | } |
| 36 | + if( $group.length > 0 ) | |
| 37 | + $group.find( '.functions .endpoint_id' ).html( $this.val() ); | |
| 113 | 38 | |
| 114 | 39 | } |
| 115 | 40 | |
| 116 | - | |
| 117 | - /** | |
| 118 | - * Disable the Test Endpoint button on adding new row. | |
| 119 | - * | |
| 120 | - */ | |
| 121 | - wpgetapi.disableTestUntilSave = function ( evt, row ) { | |
| 122 | - var $row = $( row ); | |
| 123 | - $row.find( '.wpgetapi-test-area .test-button' ).attr( 'disabled', true ); | |
| 124 | - } | |
| 125 | - | |
| 126 | - | |
| 41 | + | |
| 127 | 42 | /** |
| 128 | 43 | * Gets jQuery object containing all . Caches the result. |
| 129 | 44 | * |
| 130 | 45 | * @since 1.0.0 |