-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathayecode-ds.js
146 lines (116 loc) · 5.75 KB
/
ayecode-ds.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
(function($) {
if(!window.ayecodeds)
window.ayecodeds = {};
if(ayecodeds.DeactivateFeedbackForm)
return;
ayecodeds.DeactivateFeedbackForm = function(plugin)
{
var self = this;
var strings = ayecodeds_deactivate_feedback_form_strings;
var support_btn = plugin.support_url ? '<a class="button button-primary" href="'+plugin.support_url+'" target="_blank" >'+strings.get_support+'</a>' : '';
var documentation = plugin.documentation_url ? ' <a class="button button-primary" href="'+plugin.documentation_url+'" target="_blank" >'+strings.documentation+'</a>' : '';
this.plugin = plugin;
// Dialog HTML
var element = $('\
<div class="ayecodeds-deactivate-dialog" data-modal-id="' + plugin.slug + '">\
<form>\
<input type="hidden" name="plugin"/>\
<h2>' + strings.quick_feedback + '<span id="ayecodeds-plugin-name"></span></h2>\
<p>\
' + strings.foreword + '\
</p>\
<ul class="ayecodeds-deactivate-reasons"></ul>\
<input id="ayecode-feedback-other" name="comments" placeholder="' + strings.brief_description + '" style="width: 100%;padding: 5px;display: none;"/>\
<p class="ayecodeds-help-buttons" style="float: left;display: none;">\
'+support_btn+documentation+'\
</p> \
<p class="ayecodeds-deactivate-dialog-buttons" style="float: right;">\
<input type="submit" class="button confirm" value="' + strings.skip_and_deactivate + '"/>\
<button data-modal-action="cancel" class="button button-primary" onclick="tb_remove();jQuery(\'#ayecode-deactivation-form\').html(\'\');return false;">' + strings.cancel + '</button>\
</p>\
</form><style>#TB_window {overflow-y:auto;border-radius: 4px;height: fit-content !important;width:auto !important; left: 50%;top: 50% !important;margin-left: unset !important; -webkit-transform: translate(-50%, -50%);transform: translate(-50%, -50%);}#TB_title{display:none;}#TB_ajaxContent {height: auto !important;}</style>\
</div>\
')[0];
this.element = element;
var pluginNiceName = $("#the-list [data-slug='" + plugin.slug + "'] .plugin-title strong").text();
$(element).find("input[name='plugin']").val(JSON.stringify(plugin));
$(element).find("#ayecodeds-plugin-name").text(" - "+pluginNiceName);
//
$(element).on("click", "input[name='reason']", function(event) {
$(element).find("input[type='submit']").val(
strings.submit_and_deactivate
);
//hide then we can show if needed
jQuery("#ayecode-feedback-other,.ayecodeds-help-buttons").hide();
if(jQuery(this).val()=="other"){
jQuery("#ayecode-feedback-other").attr('placeholder',strings.brief_description ).show();
}else if(jQuery(this).val()=="found-better-plugin"){
jQuery("#ayecode-feedback-other").attr('placeholder',strings.better_plugins_name ).show();
}else if(jQuery(this).val()=="suddenly-stopped-working" || jQuery(this).val()=="plugin-broke-site" || jQuery(this).val()=="plugin-setup-difficult" || jQuery(this).val()=="plugin-design-difficult"){
jQuery(".ayecodeds-help-buttons").show();
}
});
$(element).find("form").on("submit", function(event) {
self.onSubmit(event);
});
// Reasons list
var ul = $(element).find("ul.ayecodeds-deactivate-reasons");
for(var key in plugin.reasons)
{
var li = $("<li><input type='radio' name='reason'/> <span></span></li>");
$(li).find("input").val(key);
$(li).find("span").html(plugin.reasons[key]);
$(ul).append(li);
}
// Listen for deactivate
$("#the-list [data-slug='" + plugin.slug + "'] .deactivate>a").on("click", function(event) {
self.onDeactivateClicked(event);
});
};
ayecodeds.DeactivateFeedbackForm.prototype.onDeactivateClicked = function(event)
{
var strings = ayecodeds_deactivate_feedback_form_strings;
this.deactivateURL = event.target.href;
event.preventDefault();
if(!$('#ayecode-deactivation-form').length){
$( "#wpfooter" ).after( "<div id='ayecode-deactivation-form' style='display: none;'></div>" );
}
$('#ayecode-deactivation-form').html(this.element);
tb_show(strings.quick_feedback,'#TB_inline?height=auto&inlineId=ayecode-deactivation-form');
};
ayecodeds.DeactivateFeedbackForm.prototype.onSubmit = function(event)
{
var element = this.element;
var strings = ayecodeds_deactivate_feedback_form_strings;
var self = this;
var data = $(element).find("form").serialize();
$(element).find("button, input[type='submit']").prop("disabled", true);
if($(element).find("input[name='reason']:checked").length)
{
$(element).find("input[type='submit']").val(strings.thank_you);
$.ajax({
type: "POST",
url: "https://wpgeodirectory.com/tracking/",
data: data,
complete: function() {
window.location.href = self.deactivateURL;
}
});
}
else
{
$(element).find("input[type='submit']").val(strings.please_wait);
window.location.href = self.deactivateURL;
}
event.preventDefault();
return false;
};
$(document).ready(function() {
for(var i = 0; i < ayecodeds_deactivate_feedback_form_plugins.length; i++)
{
var plugin = ayecodeds_deactivate_feedback_form_plugins[i];
new ayecodeds.DeactivateFeedbackForm(plugin);
// console.log(plugin);
}
});
})(jQuery);