|
2 | 2 | document.addEventListener( 'DOMContentLoaded', function() { |
3 | 3 | document.addEventListener( 'click', function(event) { |
4 | 4 | if ( event.target.classList.contains( 'perflab-install-active-plugin' ) ) { |
| 5 | + var target = event.target; |
| 6 | + target.parentElement.querySelector( 'span' ).classList.remove( 'hidden' ); |
5 | 7 |
|
6 | | - if ( confirm( perflab_module_migration_notice.prompt_message ) ) { |
7 | | - var target = event.target; |
8 | | - target.parentElement.querySelector( 'span' ).classList.remove( 'hidden' ); |
| 8 | + var data = new FormData(); |
| 9 | + data.append( 'action', 'perflab_install_activate_standalone_plugins' ); |
| 10 | + data.append( 'nonce', perflab_module_migration_notice.nonce ); |
9 | 11 |
|
10 | | - var data = new FormData(); |
11 | | - data.append( 'action', 'perflab_install_activate_standalone_plugins' ); |
12 | | - data.append( 'nonce', perflab_module_migration_notice.nonce ); |
13 | | - |
14 | | - fetch( perflab_module_migration_notice.ajaxurl, { |
15 | | - method: 'POST', |
16 | | - credentials: 'same-origin', |
17 | | - body: data |
18 | | - }) |
19 | | - .then( function ( response ) { |
20 | | - if ( ! response.ok ) { |
21 | | - throw new Error( perflab_module_migration_notice.network_error ); |
22 | | - } |
23 | | - return response.json(); |
24 | | - }) |
25 | | - .then( function( result ) { |
26 | | - target.parentElement.querySelector( 'span' ).classList.add( 'hidden' ); |
27 | | - if ( ! result.success ) { |
28 | | - alert( result.data.errorMessage ); |
29 | | - } |
30 | | - window.location.reload(); |
31 | | - }) |
32 | | - .catch( function( error ) { |
33 | | - alert( error.errorMessage ); |
34 | | - window.location.reload(); |
35 | | - }); |
36 | | - } |
| 12 | + fetch( perflab_module_migration_notice.ajaxurl, { |
| 13 | + method: 'POST', |
| 14 | + credentials: 'same-origin', |
| 15 | + body: data |
| 16 | + }) |
| 17 | + .then( function ( response ) { |
| 18 | + if ( ! response.ok ) { |
| 19 | + throw new Error( perflab_module_migration_notice.network_error ); |
| 20 | + } |
| 21 | + return response.json(); |
| 22 | + }) |
| 23 | + .then( function( result ) { |
| 24 | + target.parentElement.querySelector( 'span' ).classList.add( 'hidden' ); |
| 25 | + if ( ! result.success ) { |
| 26 | + alert( perflab_replace_html_entity( result.data.errorMessage ) ); |
| 27 | + } |
| 28 | + window.location.reload(); |
| 29 | + }) |
| 30 | + .catch( function( error ) { |
| 31 | + alert( error.errorMessage ); |
| 32 | + window.location.reload(); |
| 33 | + }); |
37 | 34 | } |
38 | 35 | }); |
| 36 | + |
| 37 | + // Function to replace HTML entities with their corresponding characters. |
| 38 | + function perflab_replace_html_entity( str ) { |
| 39 | + return str.replace( /&#(\d+);/g, function( match, dec ) { |
| 40 | + return String.fromCharCode( dec ); |
| 41 | + }); |
| 42 | + } |
39 | 43 | }); |
40 | 44 | } )( document ); |
0 commit comments