PluginProbe
Image Source Control Lite – Show Image Credits and Captions / 3.11.0
Image Source Control Lite – Show Image Credits and Captions v3.11.0
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
image-source-control-isc / admin / assets / js / feedback.js

feedback.js in Image Source Control Lite – Show Image Credits and Captions 3.11.0, at admin/assets/js/feedback.js

91 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 document.addEventListener('DOMContentLoaded', function () {
2 // show overlay when clicked on "deactivate" for any known ISC slug
3 let iscDeactivateLinks = document.querySelectorAll('#deactivate-isc, #deactivate-image-source-control-isc, #deactivate-image-source-control');
4
5 iscDeactivateLinks.forEach(link => {
6 link.addEventListener('click', function (e) {
7 // bail if there is more than one deactivate link (ISC being enabled more than once)
8 if (document.querySelectorAll('#deactivate-isc, #deactivate-image-source-control-isc, #deactivate-image-source-control').length > 1) {
9 return;
10 }
11 e.preventDefault();
12 // update the global variable with the href of the clicked link
13 iscDeactivateLinkUrl = this.getAttribute( 'href' );
14 // only show the feedback form once per 30 days
15 var cValue = iscFeedbackGetCookie("isc_hide_deactivate_feedback");
16 if (cValue === undefined) {
17 document.querySelector('#isc-feedback-overlay').style.display = 'block';
18 document.querySelector('#isc-feedback-content textarea').focus();
19 } else {
20 // click on the deactivate link
21 window.location.href = iscDeactivateLinkUrl;
22 }
23 });
24 });
25
26 // show the email input field
27 document.querySelector('#isc-feedback-send-reply').addEventListener('click', function () {
28 document.querySelector('#isc-feedback-reply-email').style.display = 'block';
29 });
30
31 // send the form or close it
32 document.querySelectorAll('#isc-feedback-content .button').forEach(button => {
33 button.addEventListener('click', function (e) {
34 e.preventDefault();
35 // set the cookie for 30 days
36 iscStoreFeedbackCookie();
37
38 // hide the content of the feedback form while we process the data
39 document.querySelector('#isc-feedback-content form').style.display = 'none';
40 if (this.classList.contains('isc-feedback-submit')) {
41 // show feedback message
42 document.querySelector('#isc-feedback-after-submit').style.display = 'block';
43
44 // Preparing form data including the action parameter
45 let formData = new FormData(document.querySelector('#isc-feedback-content form'));
46 formData.append('action', 'isc_send_feedback'); // Adding the action parameter manually
47
48 fetch(ajaxurl, {
49 method: 'POST',
50 headers: {
51 'Content-Type': 'application/x-www-form-urlencoded',
52 },
53 body: new URLSearchParams(formData).toString() // Convert FormData to URLSearchParams string
54 })
55 .finally(() => {
56 // deactivate the plugin and close the popup with a timeout
57 setTimeout(() => {
58 document.querySelector('#isc-feedback-overlay').remove();
59 }, 2000)
60 window.location.href = iscDeactivateLinkUrl;
61 });
62 } else {
63 document.querySelector('#isc-feedback-overlay').remove();
64 window.location.href = iscDeactivateLinkUrl;
65 }
66 });
67 });
68
69
70 // close button for feedback form
71 document.querySelector('#isc-feedback-overlay-close-button').addEventListener('click', function () {
72 document.querySelector('#isc-feedback-overlay').style.display = 'none';
73 });
74 });
75
76 function iscFeedbackGetCookie(name) {
77 const cookies = document.cookie.split(';');
78 for (let cookie of cookies) {
79 const [cookieName, cookieValue] = cookie.split('=').map(c => c.trim());
80 if (cookieName === name) {
81 return decodeURIComponent(cookieValue);
82 }
83 }
84 }
85
86 function iscStoreFeedbackCookie() {
87 const expiry_date = new Date();
88 expiry_date.setSeconds(expiry_date.getSeconds() + 2592000);
89 document.cookie = "isc_hide_deactivate_feedback=1; expires=" + expiry_date.toUTCString() + "; path=/";
90 }
91