PluginProbe
WPGet API – Connect to any external REST API / 2.1.4
WPGet API – Connect to any external REST API v2.1.4
1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.10 2.2.2 2.2.3 All 97 releases
wpgetapi / assets / js / wpgetapi-admin.js

wpgetapi-admin.js in WPGet API – Connect to any external REST API 2.1.4, at assets/js/wpgetapi-admin.js

144 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 wpgetapi.tooltips();
16
17 $page
18 .on( 'click', '.functions .copy-this', wpgetapi.copyThis )
19 .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 );
22
23 }
24
25
26 /**
27 * Do the tooltips
28 */
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 wpgetapi.functionsHelp = function ( e ) {
86
87 // change, keyup, add_row etc
88 if( e && e.type.length > 0 ) {
89
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
112 }
113
114 }
115
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
127 /**
128 * Gets jQuery object containing all . Caches the result.
129 *
130 * @since 1.0.0
131 *
132 * @return {Object} jQuery object containing all.
133 */
134 wpgetapi.page = function() {
135 if ( wpgetapi.$page ) {
136 return wpgetapi.$page;
137 }
138 wpgetapi.$page = $('.wpgetapi');
139 return wpgetapi.$page;
140 };
141
142 $( wpgetapi.onReady );
143
144 }(window, document, jQuery, window.WpGetApi));