PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 2.7.0
WDesignKit – AI Templates, Widget Builder & MCP Workflow v2.7.0
2.7.1 2.7.0 2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 All 130 releases
wdesignkit / assets / js / admin / wdkit-deactivate-survey.js

wdkit-deactivate-survey.js in WDesignKit – AI Templates, Widget Builder & MCP Workflow 2.7.0, at assets/js/admin/wdkit-deactivate-survey.js

71 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Adds a close button to the shared deactivation dialog.
3 *
4 * The dialog's markup lives in includes/posimyth-sdk/class-posimyth-deactivation-survey.php, which
5 * is sync-managed and must not be edited here, so the button is injected instead of printed. It is
6 * scoped to `.posi-deact-p-wdesignkit` — the parent class that file documents for product-specific
7 * customisation — so a sibling POSIMYTH plugin's dialog is untouched.
8 *
9 * Behaviour matches the two ways out the SDK already provides, Esc and a backdrop click: the dialog
10 * closes and THE PLUGIN STAYS ACTIVE. That is deliberately different from "Skip & Deactivate",
11 * which does deactivate. Nothing is sent either way.
12 *
13 * @since 2.6.4
14 */
15 ( function () {
16 'use strict';
17
18 var SELECTOR = '.posi-deact-p-wdesignkit';
19
20 /**
21 * Close the dialog without deactivating.
22 *
23 * Mirrors the SDK's own closeModal(): it opens with .css('display','flex'), so clearing the
24 * inline display returns the element to the stylesheet's `display:none` and lets a later open
25 * set it again. Removing the node instead would break every reopen, since the SDK looks the
26 * modal up once on load.
27 *
28 * @param {HTMLElement} modal The dialog's outer .posi-deact-modal element.
29 */
30 function close_modal( modal ) {
31 modal.style.display = 'none';
32 }
33
34 /**
35 * Build the button and place it in the dialog.
36 *
37 * @param {HTMLElement} modal The dialog's outer .posi-deact-modal element.
38 */
39 function add_close_button( modal ) {
40 var dialog = modal.querySelector( '.posi-deact-dialog' );
41
42 // Guard against running twice: the script is idempotent so a second call — a re-render, or a
43 // future SDK that ships its own control — cannot stack two buttons in the corner.
44 if ( ! dialog || dialog.querySelector( '.wdkit-deact-close' ) ) {
45 return;
46 }
47
48 var button = document.createElement( 'button' );
49
50 button.type = 'button';
51 button.className = 'wdkit-deact-close';
52 // Named for screen readers: the glyph alone announces as "times" or nothing at all.
53 button.setAttribute( 'aria-label', wdkitDeactSurvey.close_label );
54 button.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true"><path d="M1 1l12 12M13 1L1 13" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>';
55
56 button.addEventListener( 'click', function () {
57 close_modal( modal );
58 } );
59
60 dialog.appendChild( button );
61 }
62
63 document.addEventListener( 'DOMContentLoaded', function () {
64 var modal = document.querySelector( SELECTOR );
65
66 if ( modal ) {
67 add_close_button( modal );
68 }
69 } );
70 }() );
71