PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
← All changes | assets/js/deactivate.js +37 -29 1.2.01.4.1 View file →
@@ -1,6 +1,18 @@
1 1 // Deactivation Form
2 2 jQuery(document).ready(function () {
3 + // NOTE: the "requirements" value below intentionally matches the literal
4 + // value="Plugin doesn\'t meet my requirements" attribute currently rendered
5 + // in includes/admin.php (the backslash is not a PHP-string escape there —
6 + // that markup is raw HTML, so it prints as a literal backslash character).
7 + var COMMENT_REQUIRED_REASONS = [
8 + "I found a bug",
9 + "Plugin suddenly stopped working",
10 + "Plugin broke my site",
11 + "Other",
12 + "Plugin doesn\\'t meet my requirements",
13 + ];
14 +
3 15 jQuery(document).on("click", function (e) {
4 16 var popup = document.getElementById("dw-wpmcs-survey-form");
5 17 var overlay = document.getElementById("dw-wpmcs-survey-form-wrap");
6 18 var openButton = document.getElementById("deactivate-media-cloud-sync");
@@ -32,9 +44,12 @@
32 44 popup.style.display = "none";
33 45 overlay.style.display = "none";
34 46 jQuery("#dw-wpmcs-survey-form form")[0].reset();
35 47 jQuery("#dw-wpmcs-survey-form form .dw-wpmcs-comments").hide();
36 - jQuery("#dw-wpmcs-error").html("");
48 + jQuery("#dw-wpmcs-survey-form .dw-wpmcs-comments textarea").removeClass(
49 + "has-error"
50 + );
51 + dwWpmcsSetError("");
37 52 }
38 53
39 54 jQuery("#dw-wpmcs-survey-form form").on("submit", function (e) {
40 55 e.preventDefault();
@@ -69,9 +84,9 @@
69 84 }
70 85 });
71 86
72 87 jQuery("#dw-wpmcs-survey-form .dw-wpmcs-comments textarea").on(
73 - "keyup",
88 + "input",
74 89 function () {
75 90 dwWpmcsValidate();
76 91 }
77 92 );
@@ -78,51 +93,44 @@
78 93
79 94 jQuery("#dw-wpmcs-survey-form form input[type='radio']").on(
80 95 "change",
81 96 function () {
82 - dwWpmcsValidate();
83 - let val = jQuery(this).val();
84 - if (
85 - val == "I found a bug" ||
86 - val == "Plugin suddenly stopped working" ||
87 - val == "Plugin broke my site" ||
88 - val == "Other" ||
89 - val == "Plugin doesn't meet my requirement"
90 - ) {
97 + var val = jQuery(this).val();
98 + if (COMMENT_REQUIRED_REASONS.indexOf(val) !== -1) {
91 99 jQuery("#dw-wpmcs-survey-form form .dw-wpmcs-comments").show();
92 100 } else {
93 101 jQuery("#dw-wpmcs-survey-form form .dw-wpmcs-comments").hide();
94 102 }
103 + dwWpmcsValidate();
95 104 }
96 105 );
97 106
107 + function dwWpmcsSetError(message) {
108 + jQuery("#dw-wpmcs-error-text").text(message);
109 + jQuery("#dw-wpmcs-error").toggleClass("is-visible", !!message);
110 + }
111 +
98 112 function dwWpmcsValidate() {
99 - var error = "";
100 113 var reason = jQuery(
101 114 "#dw-wpmcs-survey-form form input[name='reason']:checked"
102 115 ).val();
116 + var $textarea = jQuery("#dw-wpmcs-survey-form .dw-wpmcs-comments textarea");
117 + $textarea.removeClass("has-error");
118 +
103 119 if (!reason) {
104 - error += "Please select your reason for deactivation";
120 + dwWpmcsSetError("Please select a reason so we know how to improve");
121 + return false;
105 122 }
123 +
106 124 if (
107 - error === "" &&
108 - (reason == "I found a bug" ||
109 - reason == "Plugin suddenly stopped working" ||
110 - reason == "Plugin broke my site" ||
111 - reason == "Other" ||
112 - reason == "Plugin doesn't meet my requirement")
125 + COMMENT_REQUIRED_REASONS.indexOf(reason) !== -1 &&
126 + $textarea.val().trim().length <= 0
113 127 ) {
114 - var comments = jQuery(
115 - "#dw-wpmcs-survey-form .dw-wpmcs-comments textarea"
116 - ).val();
117 - if (comments.length <= 0) {
118 - error += "Please specify";
119 - }
120 - }
121 - if (error !== "") {
122 - jQuery("#dw-wpmcs-error").html(error);
128 + dwWpmcsSetError("Please add a few details so we can look into it");
129 + $textarea.addClass("has-error");
123 130 return false;
124 131 }
125 - jQuery("#dw-wpmcs-error").html("");
132 +
133 + dwWpmcsSetError("");
126 134 return true;
127 135 }
128 136 });