1
|
|
|
/** |
2
|
|
|
* JavaScript for Bulk Delete Plugin |
3
|
|
|
* |
4
|
|
|
* http://bulkwp.com |
5
|
|
|
* |
6
|
|
|
* @author: Sudar <http://sudarmuthu.com> |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/*global BulkWP, postboxes, pagenow, ajaxurl*/ |
10
|
|
|
jQuery(document).ready(function () { |
11
|
|
|
/** |
12
|
|
|
* Enable select2 |
13
|
|
|
*/ |
14
|
|
|
jQuery( '.select2' ).select2({ |
15
|
|
|
width: '300px' |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
jQuery( '.select2Ajax' ).select2({ |
19
|
|
|
ajax: { |
20
|
|
|
url: ajaxurl, |
21
|
|
|
dataType: 'json', |
22
|
|
|
delay: 250, |
23
|
|
|
data: function (params) { |
24
|
|
|
var taxonomy = jQuery(this).attr('data-taxonomy'); |
25
|
|
|
return { |
26
|
|
|
q: params.term, |
27
|
|
|
taxonomy: taxonomy, |
28
|
|
|
action: 'load_taxonomy_term' |
29
|
|
|
}; |
30
|
|
|
}, |
31
|
|
|
processResults: function( data ) { |
32
|
|
|
var options = []; |
33
|
|
|
if ( data ) { |
34
|
|
|
|
35
|
|
|
jQuery.each( data, function( index, dataPair ) { |
36
|
|
|
options.push( { id: dataPair[0], text: dataPair[1] } ); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
return { |
41
|
|
|
results: options |
42
|
|
|
}; |
43
|
|
|
}, |
44
|
|
|
cache: true |
45
|
|
|
}, |
46
|
|
|
minimumInputLength: 3, // the minimum of symbols to input before perform a search |
47
|
|
|
width: '300px' |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
// Start Jetpack. |
51
|
|
|
BulkWP.jetpack(); |
52
|
|
|
|
53
|
|
|
BulkWP.enableHelpTooltips( jQuery( '.bd-help' ) ); |
54
|
|
|
|
55
|
|
|
jQuery( '.user_restrict_to_no_posts_filter' ).change( function() { |
56
|
|
|
var $this = jQuery(this), |
57
|
|
|
filterEnabled = $this.is( ':checked' ), |
58
|
|
|
$filterItems = $this.parents( 'table' ).children().find( '.user_restrict_to_no_posts_filter_items' ); |
59
|
|
|
|
60
|
|
|
if ( filterEnabled ) { |
61
|
|
|
$filterItems.removeClass( 'visually-hidden' ); |
62
|
|
|
} else { |
63
|
|
|
$filterItems.addClass( 'visually-hidden' ); |
64
|
|
|
} |
65
|
|
|
} ); |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Enable Postbox handling |
69
|
|
|
*/ |
70
|
|
|
postboxes.add_postbox_toggles(pagenow); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Toggle the date restrict fields |
74
|
|
|
*/ |
75
|
|
|
function toggle_date_restrict(el) { |
76
|
|
|
if (jQuery("#smbd" + el + "_restrict").is(":checked")) { |
77
|
|
|
jQuery("#smbd" + el + "_op").removeAttr('disabled'); |
78
|
|
|
jQuery("#smbd" + el + "_days").removeAttr('disabled'); |
79
|
|
|
} else { |
80
|
|
|
jQuery("#smbd" + el + "_op").attr('disabled', 'true'); |
81
|
|
|
jQuery("#smbd" + el + "_days").attr('disabled', 'true'); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Toggle limit restrict fields |
87
|
|
|
*/ |
88
|
|
|
function toggle_limit_restrict(el) { |
89
|
|
|
if (jQuery("#smbd" + el + "_limit").is(":checked")) { |
90
|
|
|
jQuery("#smbd" + el + "_limit_to").removeAttr('disabled'); |
91
|
|
|
} else { |
92
|
|
|
jQuery("#smbd" + el + "_limit_to").attr('disabled', 'true'); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Toggle user login restrict fields |
98
|
|
|
*/ |
99
|
|
|
function toggle_login_restrict(el) { |
100
|
|
|
if (jQuery("#smbd" + el + "_login_restrict").is(":checked")) { |
101
|
|
|
jQuery("#smbd" + el + "_login_days").removeAttr('disabled'); |
102
|
|
|
} else { |
103
|
|
|
jQuery("#smbd" + el + "_login_days").attr('disabled', 'true'); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Toggle user registered restrict fields |
109
|
|
|
*/ |
110
|
|
|
function toggle_registered_restrict(el) { |
111
|
|
|
if (jQuery("#smbd" + el + "_registered_restrict").is(":checked")) { |
112
|
|
|
jQuery("#smbd" + el + "_registered_days").removeAttr('disabled'); |
113
|
|
|
} else { |
114
|
|
|
jQuery("#smbd" + el + "_registered_days").attr('disabled', 'true'); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Toggle Post type dropdown. |
120
|
|
|
*/ |
121
|
|
|
function toggle_post_type_dropdown( el ) { |
122
|
|
|
// TODO: Check why the element is not toggling even when display:none is added by JS. |
123
|
|
|
if ( jQuery( "#smbd" + el + "_no_posts" ).is( ":checked" ) ) { |
124
|
|
|
jQuery( "tr#smbd" + el + "-post-type-dropdown" ).show(); |
125
|
|
|
} else { |
126
|
|
|
jQuery( "tr#smbd" + el + "-post-type-dropdown" ).hide(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
// hide all terms |
131
|
|
|
function hideAllTerms() { |
132
|
|
|
jQuery('table.terms').hide(); |
133
|
|
|
jQuery('input.terms').attr('checked', false); |
134
|
|
|
} |
135
|
|
|
// call it for the first time |
136
|
|
|
hideAllTerms(); |
137
|
|
|
|
138
|
|
|
// taxonomy click handling |
139
|
|
|
jQuery('.custom-tax').change(function () { |
140
|
|
|
var $this = jQuery(this), |
141
|
|
|
$tax = $this.val(), |
142
|
|
|
$terms = jQuery('table.terms_' + $tax); |
143
|
|
|
|
144
|
|
|
if ($this.is(':checked')) { |
145
|
|
|
hideAllTerms(); |
146
|
|
|
$terms.show('slow'); |
147
|
|
|
} |
148
|
|
|
}); |
149
|
|
|
|
150
|
|
|
// date time picker |
151
|
|
|
jQuery.each(BulkWP.dt_iterators, function (index, value) { |
152
|
|
|
// invoke the date time picker |
153
|
|
|
jQuery('#smbd' + value + '_cron_start').datetimepicker({ |
154
|
|
|
timeFormat: 'HH:mm:ss' |
155
|
|
|
}); |
156
|
|
|
|
157
|
|
|
jQuery('#smbd' + value + '_restrict').change(function () { |
158
|
|
|
toggle_date_restrict(value); |
159
|
|
|
}); |
160
|
|
|
|
161
|
|
|
jQuery('#smbd' + value + '_limit').change(function () { |
162
|
|
|
toggle_limit_restrict(value); |
163
|
|
|
}); |
164
|
|
|
|
165
|
|
|
jQuery('#smbd' + value + '_login_restrict').change(function () { |
166
|
|
|
toggle_login_restrict(value); |
167
|
|
|
}); |
168
|
|
|
|
169
|
|
|
jQuery('#smbd' + value + '_registered_restrict').change(function () { |
170
|
|
|
toggle_registered_restrict(value); |
171
|
|
|
}); |
172
|
|
|
|
173
|
|
|
jQuery( '#smbd' + value + '_no_posts' ).change( function () { |
174
|
|
|
toggle_post_type_dropdown( value ); |
175
|
|
|
}); |
176
|
|
|
}); |
177
|
|
|
|
178
|
|
|
jQuery.each( BulkWP.pro_iterators, function ( index, value) { |
179
|
|
|
jQuery('.bd-' + value.replace( '_', '-' ) + '-pro').hide(); |
180
|
|
|
jQuery('#smbd_' + value + '_cron_freq, #smbd_' + value + '_cron_start, #smbd_' + value + '_cron').removeAttr('disabled'); |
181
|
|
|
} ); |
182
|
|
|
|
183
|
|
|
// Validate user action |
184
|
|
|
jQuery('button[name="bd_action"]').click(function () { |
185
|
|
|
var currentButton = jQuery(this).val(), |
186
|
|
|
valid = false, |
187
|
|
|
msg_key = "deletePostsWarning", |
188
|
|
|
error_key = "selectPostOption"; |
189
|
|
|
|
190
|
|
|
if (currentButton in BulkWP.validators) { |
191
|
|
|
valid = BulkWP[BulkWP.validators[currentButton]](this); |
192
|
|
|
} else { |
193
|
|
|
if (jQuery(this).parent().prev().children('table').find(":checkbox:checked[value!='true']").size() > 0) { // monstrous selector |
194
|
|
|
valid = true; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
if (valid) { |
199
|
|
|
if (currentButton in BulkWP.pre_action_msg) { |
200
|
|
|
msg_key = BulkWP.pre_action_msg[currentButton]; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return confirm(BulkWP.msg[msg_key]); |
204
|
|
|
} else { |
205
|
|
|
if (currentButton in BulkWP.error_msg) { |
206
|
|
|
error_key = BulkWP.error_msg[currentButton]; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
alert(BulkWP.msg[error_key]); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
return false; |
213
|
|
|
}); |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Validation functions |
217
|
|
|
*/ |
218
|
|
|
BulkWP.noValidation = function() { |
219
|
|
|
return true; |
220
|
|
|
}; |
221
|
|
|
|
222
|
|
|
BulkWP.validateSelect2 = function(that) { |
223
|
|
|
if (null !== jQuery(that).parent().prev().children().find(".select2[multiple]").val()) { |
224
|
|
|
return true; |
225
|
|
|
} else { |
226
|
|
|
return false; |
227
|
|
|
} |
228
|
|
|
}; |
229
|
|
|
|
230
|
|
|
BulkWP.validateUrl = function(that) { |
231
|
|
|
if (jQuery(that).parent().prev().children('table').find("textarea").val() !== '') { |
232
|
|
|
return true; |
233
|
|
|
} else { |
234
|
|
|
return false; |
235
|
|
|
} |
236
|
|
|
}; |
237
|
|
|
|
238
|
|
|
BulkWP.validateUserMeta = function() { |
239
|
|
|
if (jQuery('#smbd_u_meta_value').val() !== '') { |
240
|
|
|
return true; |
241
|
|
|
} else { |
242
|
|
|
return false; |
243
|
|
|
} |
244
|
|
|
}; |
245
|
|
|
}); |
246
|
|
|
|
247
|
|
|
BulkWP.jetpack = function() { |
248
|
|
|
jQuery('.bd-feedback-pro').hide(); |
249
|
|
|
|
250
|
|
|
jQuery('#smbd_feedback_cron_freq, #smbd_feedback_cron_start, #smbd_feedback_cron').removeAttr('disabled'); |
251
|
|
|
jQuery('#smbd_feedback_use_filter').removeAttr('disabled'); |
252
|
|
|
|
253
|
|
|
// enable filters |
254
|
|
|
jQuery('input[name="smbd_feedback_use_filter"]').change(function() { |
255
|
|
|
if('true' === jQuery(this).val()) { |
256
|
|
|
// using filters |
257
|
|
|
jQuery('#jetpack-filters').show(); |
258
|
|
|
} else { |
259
|
|
|
jQuery('#jetpack-filters').hide(); |
260
|
|
|
} |
261
|
|
|
}); |
262
|
|
|
|
263
|
|
|
// enable individual filters |
264
|
|
|
jQuery.each(['name', 'email', 'ip'], function (index, value) { |
265
|
|
|
jQuery('#smbd_feedback_author_' + value + '_filter').change(function() { |
266
|
|
|
if(jQuery(this).is(':checked')) { |
267
|
|
|
jQuery('#smbd_feedback_author_' + value + '_op').removeAttr('disabled'); |
268
|
|
|
jQuery('#smbd_feedback_author_' + value + '_value').removeAttr('disabled'); |
269
|
|
|
} else { |
270
|
|
|
jQuery('#smbd_feedback_author_' + value + '_op').attr('disabled', 'true'); |
271
|
|
|
jQuery('#smbd_feedback_author_' + value + '_value').attr('disabled', 'true'); |
272
|
|
|
} |
273
|
|
|
}); |
274
|
|
|
}); |
275
|
|
|
}; |
276
|
|
|
|
277
|
|
|
BulkWP.enableHelpTooltips = function ( $selector ) { |
278
|
|
|
$selector.tooltip({ |
279
|
|
|
content: function() { |
280
|
|
|
return jQuery(this).prop('title'); |
281
|
|
|
}, |
282
|
|
|
position: { |
283
|
|
|
my: 'center top', |
284
|
|
|
at: 'center bottom+10', |
285
|
|
|
collision: 'flipfit' |
286
|
|
|
}, |
287
|
|
|
hide: { |
288
|
|
|
duration: 200 |
289
|
|
|
}, |
290
|
|
|
show: { |
291
|
|
|
duration: 200 |
292
|
|
|
} |
293
|
|
|
}); |
294
|
|
|
}; |
295
|
|
|
|