PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.2-a.5
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / modules / widgets / contact-info / contact-info-admin.js
contact-info-admin.js
55 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global ajaxurl, contact_info_api_key_ajax_obj */
2
3 ( function ( $ ) {
4 $( document ).on( 'change', '.jp-contact-info-showmap', function () {
5 var $checkbox = $( this ),
6 isChecked = $checkbox.is( ':checked' );
7
8 $checkbox.closest( '.widget' ).find( '.jp-contact-info-admin-map' ).toggle( isChecked );
9 } );
10
11 $( document ).on( 'widget-synced', function ( event, widgetContainer ) {
12 // This event fires for all widgets, so restrict this to Contact Info widgets and the API key input.
13 if (
14 ! widgetContainer.is( '[id*="widget_contact_info"]' ) ||
15 ! $( document.activeElement ).is( 'input[id*="apikey"]' )
16 ) {
17 return;
18 }
19
20 event.preventDefault();
21
22 var $apikey_input = widgetContainer.find( 'input[id*="apikey"]' );
23
24 $.post(
25 ajaxurl,
26 {
27 _ajax_nonce: contact_info_api_key_ajax_obj.nonce,
28 action: 'customize-contact-info-api-key',
29 apikey: $apikey_input.val(),
30 },
31 function ( data ) {
32 var $map_element = $apikey_input
33 .closest( '.jp-contact-info-admin-map' )
34 .parent()
35 .find( '.jp-contact-info-embed-map' );
36 var $warning_span = $map_element.find( '[class*="notice"]' );
37
38 if ( '1' !== data.result ) {
39 if ( $warning_span.length === 0 ) {
40 $map_element.append(
41 '<span class="notice notice-warning" style="display: block;">' +
42 data.result +
43 '</span>'
44 );
45 } else if ( $warning_span.text() !== data.result ) {
46 $warning_span.text( data.result );
47 }
48 } else {
49 $map_element.empty();
50 }
51 }
52 );
53 } );
54 } )( window.jQuery );
55