PluginProbe
WP Reset / 1.65
WP Reset v1.65
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.65, at js/wp-reset.js

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