PluginProbe
WPGet API – Connect to any external REST API / 1.9.9
WPGet API – Connect to any external REST API v1.9.9
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 1.9.9, at assets/js/wpgetapi-admin.js

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