PluginProbe
WPVulnerability / 5.1.2
WPVulnerability v5.1.2
5.1.6 5.1.2 5.1.1 5.0.1 5.0.0 trunk 0.1 0.2 1.0 1.0.1 1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 All 57 releases
wpvulnerability / assets / admin.js

admin.js in WPVulnerability 5.1.2, at assets/admin.js

94 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WPvulnerability admin scripts.
3 *
4 * @package WPVulnerability
5 */
6
7 if ( typeof jQuery !== 'undefined' ) {
8 jQuery( document ).on(
9 'wp-plugin-update-success',
10 function ( event, args ) {
11 jQuery( 'tr[data-plugin="' + args.plugin + '"]' ).nextAll( '.wpvulnerability' ).first().remove();
12 }
13 );
14 }
15
16 document.addEventListener(
17 'DOMContentLoaded',
18 function () {
19 var periodRadios = document.querySelectorAll( 'input[name="wpvulnerability-config[period]"]' );
20 var dayWrap = document.getElementById( 'wpvulnerability_day_wrap' );
21 var timeWrap = document.getElementById( 'wpvulnerability_time_wrap' );
22
23 if ( ! periodRadios.length || ! dayWrap || ! timeWrap ) {
24 return;
25 }
26
27 function toggleFields() {
28 var checked = document.querySelector( 'input[name="wpvulnerability-config[period]"]:checked' );
29 var value = checked ? checked.value : null;
30
31 if ( value === 'daily' ) {
32 dayWrap.style.display = 'none';
33 timeWrap.style.display = '';
34 } else if ( value === 'weekly' ) {
35 dayWrap.style.display = '';
36 timeWrap.style.display = '';
37 } else {
38 dayWrap.style.display = 'none';
39 timeWrap.style.display = 'none';
40 }
41 }
42
43 toggleFields();
44 periodRadios.forEach(
45 function ( radio ) {
46 radio.addEventListener( 'change', toggleFields );
47 }
48 );
49
50 var notifyOptions = [
51 {
52 checkboxSelector: 'input[name="wpvulnerability-config[notify][email]"]',
53 fieldId: 'wpvulnerability_emails',
54 },
55 {
56 checkboxSelector: 'input[name="wpvulnerability-config[notify][slack]"]',
57 fieldId: 'wpvulnerability_slack_webhook',
58 },
59 {
60 checkboxSelector: 'input[name="wpvulnerability-config[notify][teams]"]',
61 fieldId: 'wpvulnerability_teams_webhook',
62 },
63 ];
64
65 function toggleRow( checkbox, row ) {
66 if ( ! checkbox || ! row ) {
67 return;
68 }
69
70 row.style.display = checkbox.checked ? '' : 'none';
71 }
72
73 notifyOptions.forEach(
74 function ( option ) {
75 var checkbox = document.querySelector( option.checkboxSelector );
76 var row = document.getElementById( option.fieldId );
77 row = row ? row.closest( 'tr' ) : null;
78
79 toggleRow( checkbox, row );
80
81 if ( checkbox ) {
82 checkbox.addEventListener(
83 'change',
84 function () {
85 toggleRow( checkbox, row );
86 }
87 );
88 }
89 }
90 );
91
92 }
93 );
94