PluginProbe
WP Reset / 1.60
WP Reset v1.60
trunk 1.0 1.1 1.11 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.77 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.90 All 42 releases
wp-reset / js / wp-reset.js

wp-reset.js in WP Reset 1.60, at js/wp-reset.js

617 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WP Reset
3 * https://wpreset.com/
4 * (c) WebFactory Ltd, 2017-2019
5 */
6
7 jQuery(document).ready(function($) {
8 // init tabs
9 $('#wp-reset-tabs')
10 .tabs({
11 activate: function(event, ui) {
12 localStorage.setItem('wp-reset-tabs', $('#wp-reset-tabs').tabs('option', 'active'));
13 },
14 active: localStorage.getItem('wp-reset-tabs') || 0
15 })
16 .show();
17
18 // delete transients
19 $('.tools_page_wp-reset').on('click', '#delete-transients', 'click', function(e) {
20 e.preventDefault();
21
22 run_tool(this, 'delete_transients');
23
24 return false;
25 }); // delete transients
26
27 // delete uploads
28 $('.tools_page_wp-reset').on('click', '#delete-uploads', 'click', function(e) {
29 e.preventDefault();
30
31 run_tool(this, 'delete_uploads');
32
33 return false;
34 }); // delete uploads
35
36 // reset theme options (mods)
37 $('.tools_page_wp-reset').on('click', '#reset-theme-options', 'click', function(e) {
38 e.preventDefault();
39
40 run_tool(this, 'reset_theme_options');
41
42 return false;
43 }); // reset theme options
44
45 // delete themes
46 $('.tools_page_wp-reset').on('click', '#delete-themes', 'click', function(e) {
47 e.preventDefault();
48
49 run_tool(this, 'delete_themes');
50
51 return false;
52 }); // delete themes
53
54 // delete plugins
55 $('.tools_page_wp-reset').on('click', '#delete-plugins', 'click', function(e) {
56 e.preventDefault();
57
58 run_tool(this, 'delete_plugins');
59
60 return false;
61 }); // delete plugins
62
63 // drop custom tables
64 $('.tools_page_wp-reset').on('click', '#drop-custom-tables', 'click', function(e) {
65 e.preventDefault();
66
67 run_tool(this, 'drop_custom_tables');
68
69 return false;
70 }); // drop custom tables
71
72 // truncate custom tables
73 $('.tools_page_wp-reset').on('click', '#truncate-custom-tables', 'click', function(e) {
74 e.preventDefault();
75
76 run_tool(this, 'truncate_custom_tables');
77
78 return false;
79 }); // truncate custom tables
80
81 // delete htaccess file
82 $('.tools_page_wp-reset').on('click', '#delete-htaccess', 'click', function(e) {
83 e.preventDefault();
84
85 run_tool(this, 'delete_htaccess');
86
87 return false;
88 }); // delete htaccess file
89
90 // compare snapshot
91 $('#wpr-snapshots').on('click', '.compare-snapshot', 'click', function(e) {
92 e.preventDefault();
93 uid = $(this).data('ss-uid');
94 button = $(this);
95
96 block_ui($(button).data('wait-msg'));
97 $.get({
98 url: ajaxurl,
99 data: {
100 action: 'wp_reset_run_tool',
101 _ajax_nonce: wp_reset.nonce_run_tool,
102 tool: 'compare_snapshots',
103 extra_data: uid
104 }
105 })
106 .always(function(data) {
107 swal.close();
108 })
109 .done(function(data) {
110 if (data.success) {
111 msg = $(button)
112 .data('title')
113 .replace('%s', $(button).data('name'));
114 swal({
115 width: '90%',
116 title: msg,
117 html: data.data,
118 showConfirmButton: false,
119 allowEnterKey: false,
120 focusConfirm: false,
121 showCloseButton: true,
122 customClass: 'compare-snapshots'
123 });
124 } else {
125 swal({
126 type: 'error',
127 title: wp_reset.documented_error + ' ' + data.data
128 });
129 }
130 })
131 .fail(function(data) {
132 swal({ type: 'error', title: wp_reset.undocumented_error });
133 });
134
135 return false;
136 }); // compare snapshot
137
138 // restore snapshot
139 $('#wpr-snapshots').on('click', '.restore-snapshot', 'click', function(e) {
140 e.preventDefault();
141 uid = $(this).data('ss-uid');
142
143 run_tool(this, 'restore_snapshot', uid);
144
145 return false;
146 }); // restore snapshot
147
148 // download snapshot
149 $('#wpr-snapshots').on('click', '.download-snapshot', 'click', function(e) {
150 e.preventDefault();
151 uid = $(this).data('ss-uid');
152 button = this;
153
154 block_ui($(this).data('wait-msg'));
155 $.get({
156 url: ajaxurl,
157 data: {
158 action: 'wp_reset_run_tool',
159 _ajax_nonce: wp_reset.nonce_run_tool,
160 tool: 'download_snapshot',
161 extra_data: uid
162 }
163 })
164 .always(function(data) {
165 swal.close();
166 })
167 .done(function(data) {
168 if (data.success) {
169 msg = $(button)
170 .data('success-msg')
171 .replace('%s', data.data);
172 swal({ type: 'success', title: msg });
173 } else {
174 swal({
175 type: 'error',
176 title: wp_reset.documented_error + ' ' + data.data
177 });
178 }
179 })
180 .fail(function(data) {
181 swal({ type: 'error', title: wp_reset.undocumented_error });
182 });
183
184 return false;
185 }); // downlod snapshot
186
187 // delete snapshot
188 $('#wpr-snapshots').on('click', '.delete-snapshot', 'click', function(e) {
189 e.preventDefault();
190 uid = $(this).data('ss-uid');
191
192 run_tool(this, 'delete_snapshot', uid);
193
194 return false;
195 }); // delete snapshot
196
197 // create snapshot
198 $('.tools_page_wp-reset').on('click', '.create-new-snapshot', 'click', function(e) {
199 e.preventDefault();
200 button = $('#create-new-snapshot-primary');
201
202 swal({
203 title: $(button).data('title'),
204 type: 'question',
205 text: $(button).data('text'),
206 input: 'text',
207 inputPlaceholder: $(button).data('placeholder'),
208 showCancelButton: true,
209 focusConfirm: false,
210 confirmButtonText: $(button).data('btn-confirm'),
211 cancelButtonText: wp_reset.cancel_button,
212 width: 600
213 }).then(result => {
214 if (typeof result.value != 'undefined') {
215 block = block_ui($(button).data('msg-wait'));
216 $.get({
217 url: ajaxurl,
218 data: {
219 action: 'wp_reset_run_tool',
220 _ajax_nonce: wp_reset.nonce_run_tool,
221 tool: 'create_snapshot',
222 extra_data: result.value
223 }
224 })
225 .always(function(data) {
226 swal.close();
227 })
228 .done(function(data) {
229 if (data.success) {
230 swal({
231 type: 'success',
232 title: $(button).data('msg-success')
233 }).then(result => {
234 location.reload();
235 });
236 } else {
237 swal({
238 type: 'error',
239 title: wp_reset.documented_error + ' ' + data.data
240 });
241 }
242 })
243 .fail(function(data) {
244 swal({ type: 'error', title: wp_reset.undocumented_error });
245 });
246 } // if confirmed
247 });
248
249 return false;
250 }); // create snapshot
251
252 // show/hide extra table info in snapshot diff
253 $('body.tools_page_wp-reset').on('click', '.header-row', function(e) {
254 e.preventDefault();
255
256 parent = $(this).parents('div.wpr-table-container > table > tbody');
257 $(' > tr:not(.header-row)', parent).toggleClass('hidden');
258
259 $('span.dashicons', parent)
260 .toggleClass('dashicons-arrow-down-alt2')
261 .toggleClass('dashicons-arrow-up-alt2');
262
263 return false;
264 }); // show hide extra info in diff
265
266 // standard way of running a tool, with confirmation, loading and success message
267 function run_tool(button, tool_name, extra_data) {
268 confirm_action(
269 wp_reset.confirm_title,
270 $(button).data('text-confirm'),
271 $(button).data('btn-confirm'),
272 wp_reset.cancel_button
273 ).then(result => {
274 if (result.value) {
275 block = block_ui($(button).data('text-wait'));
276 $.get({
277 url: ajaxurl,
278 data: {
279 action: 'wp_reset_run_tool',
280 _ajax_nonce: wp_reset.nonce_run_tool,
281 tool: tool_name,
282 extra_data: extra_data
283 }
284 })
285 .always(function(data) {
286 swal.close();
287 })
288 .done(function(data) {
289 if (data.success) {
290 if (data.data == 1) {
291 msg = $(button).data('text-done-singular');
292 } else {
293 msg = $(button)
294 .data('text-done')
295 .replace('%n', data.data);
296 }
297 swal({ type: 'success', title: msg }).then(() => {
298 if (tool_name == 'restore_snapshot') {
299 location.reload();
300 }
301 });
302 if (tool_name == 'delete_snapshot') {
303 $('#wpr-ss-' + extra_data).remove();
304 if ($('#wpr-snapshots tr').length <= 1) {
305 $('#wpr-snapshots').hide();
306 $('#ss-no-snapshots').show();
307 }
308 }
309 } else {
310 swal({
311 type: 'error',
312 title: wp_reset.documented_error + ' ' + data.data
313 });
314 }
315 })
316 .fail(function(data) {
317 swal({ type: 'error', title: wp_reset.undocumented_error });
318 });
319 } // if confirmed
320 });
321 } // run_tool
322
323 // display a message while an action is performed
324 function block_ui(message) {
325 tmp = swal({
326 text: message,
327 type: false,
328 imageUrl: wp_reset.icon_url,
329 onOpen: () => {
330 $(swal.getImage()).addClass('rotating');
331 },
332 imageWidth: 100,
333 imageHeight: 100,
334 imageAlt: message,
335 allowOutsideClick: false,
336 allowEscapeKey: false,
337 allowEnterKey: false,
338 showConfirmButton: false
339 });
340
341 return tmp;
342 } // block_ui
343
344 // display dialog to confirm action
345 function confirm_action(title, question, btn_confirm, btn_cancel) {
346 tmp = swal({
347 title: title,
348 type: 'question',
349 html: question,
350 showCancelButton: true,
351 focusConfirm: false,
352 confirmButtonText: btn_confirm,
353 cancelButtonText: btn_cancel,
354 confirmButtonColor: '#dd3036',
355 width: 600
356 });
357
358 return tmp;
359 } // confirm_action
360
361 $('#wp_reset_form').on('submit', function(e, confirmed) {
362 if (!confirmed) {
363 $('#wp_reset_submit').trigger('click');
364 e.preventDefault();
365 return false;
366 }
367
368 $(this)
369 .off('submit')
370 .submit();
371 return true;
372 }); // bypass default submit behaviour
373
374 $('#wp_reset_submit').click(function(e) {
375 if ($('#wp_reset_confirm').val() !== 'reset') {
376 swal({
377 title: wp_reset.invalid_confirmation_title,
378 text: wp_reset.invalid_confirmation,
379 type: 'error',
380 confirmButtonText: wp_reset.ok_button
381 });
382
383 e.preventDefault();
384 return false;
385 } // wrong confirmation code
386
387 message = wp_reset.confirm1 + '<br>' + wp_reset.confirm2;
388 swal({
389 title: wp_reset.confirm_title,
390 type: 'question',
391 html: message,
392 showCancelButton: true,
393 focusConfirm: false,
394 confirmButtonText: wp_reset.confirm_button,
395 cancelButtonText: wp_reset.cancel_button,
396 confirmButtonColor: '#dd3036',
397 width: 600
398 }).then(result => {
399 if (result.value === true) {
400 block_ui(wp_reset.doing_reset);
401 $('#wp_reset_form').trigger('submit', true);
402 }
403 });
404
405 e.preventDefault();
406 return false;
407 }); // reset submit
408
409 // collapse / expand card
410 $('.card').on('click', '.toggle-card', function(e) {
411 e.preventDefault();
412
413 card = $(this)
414 .parents('.card')
415 .toggleClass('collapsed');
416 $('.dashicons', this)
417 .toggleClass('dashicons-arrow-up-alt2')
418 .toggleClass('dashicons-arrow-down-alt2');
419 $(this).blur();
420
421 cards = localStorage.getItem('wp-reset-cards');
422 if (cards == null) {
423 cards = new Object();
424 } else {
425 cards = JSON.parse(cards);
426 }
427
428 if (card.hasClass('collapsed')) {
429 cards[card.attr('id')] = 'collapsed';
430 } else {
431 cards[card.attr('id')] = 'expanded';
432 }
433 localStorage.setItem('wp-reset-cards', JSON.stringify(cards));
434
435 return false;
436 }); // toggle-card
437
438 // init cards; collapse those that need collapsing
439 cards = localStorage.getItem('wp-reset-cards');
440 if (cards != null) {
441 cards = JSON.parse(cards);
442 }
443 $.each(cards, function(card_name, card_value) {
444 if (card_value == 'collapsed') {
445 $('a.toggle-card', '#' + card_name).trigger('click');
446 }
447 });
448
449 // dismiss notice / pointer
450 $('.wpr-dismiss-notice').on('click', function(e) {
451 notice_name = $(this).data('notice');
452 if (!notice_name) {
453 return true;
454 }
455
456 if ($(this).data('survey')) {
457 $('#survey-dialog').dialog('close');
458 }
459
460 $.get(ajaxurl, {
461 notice_name: notice_name,
462 _ajax_nonce: wp_reset.nonce_dismiss_notice,
463 action: 'wp_reset_dismiss_notice'
464 });
465
466 $(this)
467 .parents('.notice-wrapper')
468 .fadeOut();
469
470 e.preventDefault();
471 return false;
472 }); // dismiss notice
473
474 // maybe init survey dialog
475 if (wp_reset.open_survey) {
476 $('#survey-dialog').dialog({
477 dialogClass: 'wp-dialog wpr-dialog wpr-survey-dialog',
478 modal: 1,
479 resizable: false,
480 width: 800,
481 height: 'auto',
482 show: 'fade',
483 hide: 'fade',
484 close: function(event, ui) {},
485 open: function(event, ui) {
486 wpr_fix_dialog_close(event, ui);
487 },
488 autoOpen: true,
489 closeOnEscape: true
490 });
491 }
492
493 // turn questions into checkboxes
494 $('.question-wrapper').on('click', function(e) {
495 if ($(this).hasClass('selected')) {
496 $(this).removeClass('selected');
497 } else {
498 if ($('.question-wrapper.selected').length >= 2) {
499 swal({
500 type: 'error',
501 allowOutsideClick: false,
502 text: 'You can choose only up to 2 features at a time.'
503 });
504 } else {
505 $(this).addClass('selected');
506 }
507 }
508
509 e.preventDefault();
510 return false;
511 });
512
513 // submit and hide survey
514 $('.submit-survey').on('click', function(e) {
515 if ($('.question-wrapper.selected').length != 2 && $('.question-wrapper.selected').length != 1) {
516 swal({
517 type: 'error',
518 allowOutsideClick: false,
519 text: 'Please choose 1 or 2 features you would like us to build next.'
520 });
521 return false;
522 }
523
524 if (
525 $('#survey-dialog .custom-input').val() == '' &&
526 $('#survey-dialog .custom-input')
527 .parents('div.question-wrapper')
528 .hasClass('selected')
529 ) {
530 swal({
531 type: 'error',
532 allowOutsideClick: false,
533 text: 'Please describe the custom feature you need.'
534 });
535 return false;
536 }
537
538 answers = '';
539 $('.question-wrapper.selected').each(function(i, el) {
540 answers += $(el).data('value') + ',';
541 });
542
543 $.post(ajaxurl, {
544 survey: 'features',
545 answers: answers,
546 emailme: $('#survey-dialog #emailme:checked').val(),
547 custom_answer: $('#survey-dialog .custom-input').val(),
548 _ajax_nonce: wp_reset.nonce_submit_survey,
549 action: 'wp_reset_submit_survey'
550 });
551
552 $('#survey-dialog').dialog('close');
553 swal({
554 type: 'success',
555 text: 'Thank you for your time! We appriciate your input!'
556 });
557
558 e.preventDefault();
559 return false;
560 });
561
562 $('.tools_page_wp-reset').on('click', '.open-webhooks-dialog', function(e) {
563 $(this).blur();
564 $('#webhooks-dialog').dialog('open');
565
566 e.preventDefault();
567 return false;
568 });
569
570 // webhooks dialog init
571 $('#webhooks-dialog').dialog({
572 dialogClass: 'wp-dialog wpr-dialog webhooks-dialog',
573 modal: 1,
574 resizable: false,
575 title: 'WP Webhooks - Connect WordPress to any 3rd party system',
576 width: 550,
577 height: 'auto',
578 show: 'fade',
579 hide: 'fade',
580 open: function(event, ui) {
581 wpr_fix_dialog_close(event, ui);
582 $(this)
583 .siblings()
584 .find('span.ui-dialog-title')
585 .html(wp_reset.webhooks_dialog_title);
586 },
587 close: function(event, ui) {},
588 autoOpen: false,
589 closeOnEscape: true
590 });
591 $(window).resize(function(e) {
592 $('#webhooks-dialog').dialog('option', 'position', {
593 my: 'center',
594 at: 'center',
595 of: window
596 });
597 });
598
599 jQuery('#install-webhooks').on('click', function(e) {
600 $('#webhooks-dialog').dialog('close');
601 jQuery('body').append(
602 '<div style="width:550px;height:450px; position:fixed;top:10%;left:50%;margin-left:-275px; color:#444; background-color: #fbfbfb;border:1px solid #DDD; border-radius:4px;box-shadow: 0px 0px 0px 4000px rgba(0, 0, 0, 0.85);z-index: 9999999;"><iframe src="' +
603 wp_reset.webhooks_install_url +
604 '" style="width:100%;height:100%;border:none;" /></div>'
605 );
606 jQuery('#wpwrap').css('pointer-events', 'none');
607 e.preventDefault();
608 return false;
609 });
610 }); // onload
611
612 function wpr_fix_dialog_close(event, ui) {
613 jQuery('.ui-widget-overlay').bind('click', function() {
614 jQuery('#' + event.target.id).dialog('close');
615 });
616 } // wpr_fix_dialog_close
617