PluginProbe
WP Docs / 2.2.1
WP Docs v2.2.1
2.3.3 2.3.2 trunk 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1
wp-docs / js / admin-scripts.js

admin-scripts.js in WP Docs 2.2.1, at js/admin-scripts.js

695 lines 18.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // JavaScript Document
2 var wpdocs_move_copy = 'move';
3 jQuery(document).ready(function($){
4
5 var files_multi_select = false;
6
7 $('.new-folder').on('click', function(){
8 var data = {
9 'action': 'wpdocs_create_folder',
10 'parent_dir': $(this).data('id'),
11 'nonce': wpdocs_ajax_object.nonce
12 };
13 // We can also pass the url value separately from ajaxurl for front end AJAX implementations
14 $('.ab-new').removeClass('ab-new');
15 $.post(wpdocs_ajax_object.ajax_url, data, function(response) {
16
17 $('div.wpdocs_list > ul').prepend(response);
18
19 $('div.wpdocs_list ul li.ab-dir a.wpd-edit').eq(0).click();
20 });
21 });
22
23 $('body').on('click', '.wpdocs-reset', function(){
24 var reset_confirmation = confirm(wpdocs_ajax_object.reset_confirm);
25
26 if(!reset_confirmation){
27 return false;
28 }
29 });
30
31 $('body').on('click', '.wpdocs_list ul li .file', function(event){
32
33
34 if(files_multi_select){
35 event.preventDefault();
36 $(this).parent().toggleClass('selected-item');
37 }else{
38 return true;
39 }
40 });
41
42 $('body').on('click', '.wpdocs_toolbar .wp-docs-multi-select', function(event){
43
44 if(!wpdocs_ajax_object.wpdocs_pro){
45 alert(wpdocs_ajax_object.premium_feature);
46 return;
47 }
48
49 $(this).toggleClass('selection-enabled');
50 files_multi_select = $(this).hasClass('selection-enabled');
51
52 if(!files_multi_select){
53 $('.wpdocs_list ul li.selected-item').removeClass('selected-item');
54 }
55 });
56
57
58 $('body').on('click', '.wpdocs_list ul li.ab-dir > a.dtitle', function(){
59 var obj = $(this);
60 var id = obj.parent().data('id');
61 var resource_id = obj.parent().data('resource');
62 var html_str = $.parseHTML(obj.html());
63 var folder_name = '';
64 $.each( html_str, function( i, el ){
65 $.each(el, function(k,v){
66 switch(k){
67
68 case 'wholeText':
69 folder_name = v;
70
71 break;
72
73 }
74 });
75 });
76 var rename_to = prompt(wpdocs_ajax_object.rename_confirm, folder_name);
77
78 if($.trim(rename_to)!=''){
79 var data = {
80 'action': 'wpdocs_update_folder',
81 'dir_id': id,
82 'resource_id': resource_id,
83 'new_name': rename_to,
84 'nonce': wpdocs_ajax_object.nonce
85 };
86 // We can also pass the url value separately from ajaxurl for front end AJAX implementations
87 $.post(wpdocs_ajax_object.ajax_url, data, function(response) {
88 //window.location.reload();
89 obj.html(rename_to);
90 });
91 }
92 });
93
94
95 $('body').on('click', '.wpdocs_list ul li.ab-dir a.wpd-edit', function(){
96 $(this).closest('li.ab-dir').find('a.dtitle').click();
97 });
98
99 $('body').on('click', '.wpdocs_list ul li.ab-dir a.wpd-trash', function(){
100 var delete_confirm = confirm(wpdocs_ajax_object.wpdocs_delete_msg);
101 var obj = $(this);
102 if(delete_confirm){
103 var data = {
104 'action': 'wpdocs_delete_folder',
105 'dir_id': $(this).closest('li.ab-dir').data('id'),
106 'resource_id': $(this).closest('li.ab-dir').data('resource'),
107 'nonce': wpdocs_ajax_object.nonce
108 };
109
110 $.post(wpdocs_ajax_object.ajax_url, data, function(response) {
111 obj.closest('li.ab-dir').fadeOut();
112 });
113
114
115 }
116 });
117
118 $('body').on('click', '.wpdocs_list ul li:not(.ab-dir):not(.ab-short) a.wpd-trash', function(event){
119 event.preventDefault();
120 var multi_delete = (files_multi_select && $('.wpdocs_list ul li.selected-item').length>1);
121 var delete_confirm = confirm(multi_delete?wpdocs_ajax_object.del_confirm_all:wpdocs_ajax_object.del_confirm);
122 var obj = $(this);
123 if(delete_confirm){
124 var id = obj.parents().eq(1).data('dir');
125
126 var attachment_id = obj.parents().eq(1).data('id');
127 var attachment_ids = {};
128
129 if($('.wpdocs_list ul li.selected-item').length>0){
130 $.each($('.wpdocs_list ul li.selected-item'), function(i,v){
131 attachment_ids[i] = $(this).data('id');
132 });
133 }else{
134 attachment_ids[0] = attachment_id;
135 }
136 //console.log(attachment_ids);
137 obj.parents().eq(1).fadeOut();
138 var data = {
139 'action': 'wpdocs_delete_files',
140 'dir_id': id,
141 'files': attachment_ids,
142 'nonce': wpdocs_ajax_object.nonce,
143 };
144 //alert(attachment.id);//return;
145 // We can also pass the url value separately from ajaxurl for front end AJAX implementations
146 $.post(wpdocs_ajax_object.ajax_url, data, function(response) {
147 //window.location.reload();
148 if(multi_delete){
149 $('.wpdocs_list ul li.selected-item').fadeOut();
150 }else{
151 obj.closest('li:not(.ab-dir)').fadeOut();
152 }
153 });
154 }
155 });
156
157 $('body').on('click', '.wpdocs_list ul li > a.folder', function(){
158 var is_shortcut = $(this).parent().hasClass('ab-short');
159 var linked_id = $(this).parent().data('linked');
160 var linked_url = (is_shortcut?$(this).parent().data('guid'):'');
161 var dir_id = (linked_id?linked_id:$(this).parent().data('id'));
162
163 if(linked_url && !linked_id){
164 window.open(linked_url, '_blank').focus();
165 return;
166 }else{
167 window.location.href = (linked_url?linked_url:'options-general.php?page=wpdocs&dir='+dir_id);
168 }
169 });
170 $('body').on('click', '.back-folder', function(){
171 window.location.href = 'options-general.php?page=wpdocs&dir='+$(this).data('parent');
172 });
173
174 setTimeout(function(){
175 if ($('.new-file:visible').length > 0) {
176 if ( typeof wp !== 'undefined' && wp.media && wp.media.editor) {
177 $('body').on('click', '.new-file:visible', function(e) {
178 var id = $(this).data('id');
179 var this_id = $(this).prop('id');
180
181 e.preventDefault();
182 //alert(id);alert(attachment.id);return;
183
184 var attachment_ids = [];
185 var add_file_status = true;
186
187 wp.media.editor.send.attachment = function(props, attachment) {
188
189
190 attachment_ids.push(attachment.id);
191 //alert(attachment.id);//return;
192 // We can also pass the url value separately from ajaxurl for front end AJAX implementations
193
194 if(add_file_status){
195
196 add_file_status = false;
197
198 setTimeout(function(){
199
200 var data = {
201 'action': 'wpdocs_add_files',
202 'dir_id': id,
203 'files': attachment_ids,
204 'nonce': wpdocs_ajax_object.nonce,
205 };
206 $.post(wpdocs_ajax_object.ajax_url, data, function(response) {
207 //window.location.reload();
208 //console.log(response);
209 if(response!=''){
210 $('div.wpdocs_list > ul > li:not(.ab-dir)').remove();
211 $('div.wpdocs_list > ul').append(response);
212 }
213 });
214
215 })
216
217 }
218
219
220 };
221
222 wp.media.editor.open(this_id);
223 //.open($(this));
224 //return false;
225 });
226
227 }
228 }
229 }, 1000);
230
231 //save selected file or directory globally every time on selection these will be replaced
232
233 var selected_move_dir = null;
234 var selected_move_is_file = false;
235 var selected_move_file_dir = null;
236
237 $('.wpdocs-specific-sections .save_changes').on('click', function(){
238 var dir_id = $('.wpdocs-specific-sections button.modal-btn').data('dir_id');
239
240 wp_docs_update_options(dir_id);
241 });
242
243 function wp_docs_update_options(dir_id = 0){
244 //console.log($(this));
245 //console.log($(this).parents().eq(1));
246
247 $conditional_class = (dir_id == 0 ? ':not(.wpdocs_dir_options)' : '.wpdocs_dir_options');
248
249 var wpdocs_option_ajax = $('input[name^="wpdocs_options"][value="ajax"]'+$conditional_class);
250 var wpdocs_option_ajax_url = $('input[name^="wpdocs_options"][value="ajax_url"]'+$conditional_class);
251
252 var wpdocs_option_file_upload = $('input[name^="wpdocs_options"][value="file_upload"]'+$conditional_class);
253 var wpdocs_option_current_user_files = $('input[name^="wpdocs_options"][value="current_user_files"]'+$conditional_class);
254 var wpdocs_option_del_from_front = $('input[name^="wpdocs_options"][value="del_from_front"]'+$conditional_class);
255
256
257 if(wpdocs_option_file_upload.prop('checked') == false){
258
259 wpdocs_option_current_user_files.prop('checked', false);
260 wpdocs_option_del_from_front.prop('checked', false);
261
262 }
263
264
265 if(wpdocs_option_ajax.prop('checked') == false){
266
267 wpdocs_option_ajax_url.prop('checked', false);
268
269 }
270
271 var wpdocs_option_checked = $('input[name^="wpdocs_options"][type="checkbox"]:checked'+$conditional_class);
272 var wpdocs_option_text = $('input[name^="wpdocs_options"][type="text"]'+$conditional_class);
273 var wpdocs_option_select = $('select[name^="wpdocs_options"]'+$conditional_class);
274
275 var wpdocs_options_post = {};
276
277 if(wpdocs_ajax_object.empty_settings){
278
279 wpdocs_options_post['wpdocs_options_update'] = true;
280
281 }
282
283
284 if(wpdocs_option_select.length > 0 ){
285 $.each(wpdocs_option_select, function () {
286
287 var name = $(this).data('name');
288
289
290 wpdocs_options_post[name] = $(this).val();
291
292 });
293 }
294
295
296 if(wpdocs_option_text.length > 0 ){
297 $.each(wpdocs_option_text, function () {
298
299 wpdocs_options_post[$(this).data('name')] = $(this).val();
300
301 });
302 }
303
304 if(wpdocs_option_checked.length > 0 ){
305 $.each(wpdocs_option_checked, function () {
306
307 wpdocs_options_post[$(this).val()] = true;
308
309 });
310 }
311
312 var wpdocs_option_colors = $('input[name^="wpdocs_options"][type="color"]'+$conditional_class);
313
314 if(wpdocs_option_colors.length > 0 && !wpdocs_ajax_object.empty_settings){
315 $.each(wpdocs_option_colors, function () {
316
317 wpdocs_options_post[$(this).attr('id')] = $(this).val();
318
319 });
320 }
321
322 if(!wpdocs_options_post.allowed_role){
323 wpdocs_options_post.allowed_role = 'empty';
324 }
325
326
327 var data = {
328
329 action : 'wpdocs_update_option',
330 wpdocs_update_option_nonce : wpdocs_ajax_object.nonce,
331 wpdocs_options : wpdocs_options_post,
332 wpdocs_dir_id : dir_id
333
334 }
335
336
337
338 $.post(ajaxurl, data, function(code, response){
339
340 //console.log(response);
341
342 if(response == 'success'){
343
344 var alerts = (dir_id == 0 ? $('.wpdocs-options .alert.alert_main'): $('.wpdocs-specific-sections .alert.alert_dir'));
345
346 //console.log(alert);
347 alerts.removeClass('d-none').addClass('show');
348 setTimeout(function(){
349 alerts.addClass('d-none');
350 }, 10000);
351
352 }
353
354 });
355
356
357 }
358
359 $('input[name^="wpdocs_options"]:checkbox').on('change', function(){
360
361 var this_obj = $(this);
362 if(this_obj.prop('checked')){
363 setTimeout(function(){
364 this_obj.parents().eq(1).find('ul').removeClass('d-none');
365 });
366
367 }else{
368 this_obj.parents().eq(1).find('ul').addClass('d-none');
369 }
370 });
371
372 $('input[name^="wpdocs_options"]:checkbox').change();
373
374 $('body').on('change', 'input[name^="wpdocs_options"]:not(.wpdocs_dir_options), select[name^="wpdocs_options"]:not(.wpdocs_dir_options)', function(){
375 wp_docs_update_options();
376 });
377
378 if(wpdocs_ajax_object.empty_settings){
379
380 $('input[name^="wpdocs_options"]').change();
381
382 }
383
384
385 function wpdocs_disable_child(dir_id){
386
387 var dir_list_select = $('li.wpdocs_move_folder_to select');
388 var dir_list_options = dir_list_select.find('option');
389 var current = dir_list_select.find('option[value="'+dir_id+'"]');
390 var current_parent = current.data('parent');
391
392 var childs = dir_list_select.find('option[data-parent="'+dir_id+'"]');
393
394 //check if the selected is not a file than disable all child directories
395 if (!selected_move_is_file) {
396
397 if (dir_list_options.length > 0) {
398
399 $.each(dir_list_options, function () {
400
401 var this_val = $(this).val();
402 var this_parent = $(this).data('parent');
403
404 if (this_val == current_parent) {
405
406 $(this).prop('disabled', true);
407 //$(this).hide();
408 $(this).prop('title', wpdocs_ajax_object.move_str);
409 }
410
411
412 if ($(this).val() == dir_id || $(this).data('parent') == dir_id) {
413
414 $(this).prop('disabled', true);
415 //$(this).hide();
416 $(this).prop('title', wpdocs_ajax_object.move_str);
417
418 if (childs.length > 0 && this_val != dir_id) {
419
420 wpdocs_disable_child(this_val);
421
422 }
423 }
424
425 });
426 }
427
428 } else {
429
430 //if selected is file than disable only its parent directory and root directory
431
432 current = dir_list_select.find('option[value="' + selected_move_file_dir + '"]');
433 var current_root = dir_list_select.find('option[value="0"]');
434 current.prop('disabled', true);
435 //current.hide();
436 current_root.prop('disabled', true);
437 //current_root.hide();
438 current_root.prop('title', wpdocs_ajax_object.move_str);
439
440 }
441
442 }
443
444 $('body').on('click', '.wpdocs_list ul li a.wpd-move, .wpdocs_list ul li a.wpd-copy', function(){
445
446 var dir_id = $(this).parents('li').data('id');
447 var file_dir = $(this).parents('li').data('dir');
448 var is_file = file_dir !== undefined;
449 selected_move_file_dir = is_file ? file_dir: null;
450 selected_move_is_file = is_file;
451
452 selected_move_dir = dir_id;
453 var dir_list_select = $('li.wpdocs_move_folder_to select');
454 var dir_list_options = dir_list_select.find('option');
455 dir_list_options.prop('disabled', false);
456 dir_list_options.show();
457
458
459 $('li.wpdocs_move_folder_to').show();
460
461 wpdocs_disable_child(selected_move_dir);
462
463
464
465 wpdocs_move_copy = ($(this).hasClass('wpd-copy')?'copy':'move');
466
467 $('.wpdocs_move_folder_to button').removeClass('copy move').addClass(wpdocs_move_copy).html(wpdocs_move_copy);
468
469
470 });
471
472 $('body').on('click', 'li.wpdocs_move_folder_to button', function(){
473
474 var selected_dir = $('li.wpdocs_move_folder_to select').val();
475
476
477
478 if(selected_dir != -1){
479
480 var wpdocs_move_selected_dir_obj = {
481
482 'dir_selected' : selected_move_dir,
483 'dir_id' : selected_dir,
484 'files' : selected_move_dir,
485 'is_file' : selected_move_is_file,
486 'file_dir': selected_move_file_dir,
487 'action_type': wpdocs_move_copy,
488 };
489
490 var data = {
491
492 action: 'wpdocs_update_option',
493 wpdocs_update_option_nonce : wpdocs_ajax_object.nonce,
494 wpdocs_move_selected_dir: wpdocs_move_selected_dir_obj
495
496 }
497
498 if(wpdocs_move_copy=='copy' && wpdocs_ajax_object.wpdocs_pro!='1'){
499 alert(wpdocs_ajax_object.premium_feature);return;
500 }
501
502 $.blockUI({message:(wpdocs_move_copy=='copy'?wpdocs_ajax_object.copied:wpdocs_ajax_object.moved)});
503
504 $.post(ajaxurl, data, function(response) {
505
506 response = JSON.parse(response);
507
508 if(response){
509
510
511
512 window.location.href= wpdocs_ajax_object.url+'&dir='+selected_dir ;
513
514 }else{
515
516 alert(wpdocs_ajax_object.move_error);
517 $(this).parents('li.wpdocs_move_folder_to').hide();
518
519 }
520
521 });
522
523
524 }else{
525
526 alert(wpdocs_ajax_object.target_dir_msg);
527 }
528 });
529
530 if($('.wpdocs_options_allowed_role:not(.wpdocs_dir_options)').length > 0){
531
532 new SlimSelect({
533
534 select:'.wpdocs_options_allowed_role:not(.wpdocs_dir_options)',
535 placeholder: wpdocs_ajax_object.select_role_str,
536 });
537 }
538
539
540 if($('.wpdocs_options_allowed_role.wpdocs_dir_options').length > 0){
541
542 new SlimSelect({
543
544 select:'.wpdocs_options_allowed_role.wpdocs_dir_options',
545 placeholder: wpdocs_ajax_object.select_role_str,
546 });
547
548 }
549
550
551 $('.wpdocs_meta_links .wpdocs_show_option').on('click', function(){
552
553 var control = $($(this).data('control'));
554 var show = $(this).attr('data-show');
555
556 if(show == 'true'){
557 $(this).attr('data-show', false);
558 control.slideUp();
559 }else{
560 $(this).attr('data-show', true);
561 control.slideDown();
562
563 }
564
565 });
566
567
568
569 $('.wp_docs_import_memphis').on('click', function(){
570
571 var import_confirm = confirm(wpdocs_ajax_object.import_confirm);
572 var progress_text = $(this).data('text');
573
574 if(!import_confirm) return;
575
576 var data = {
577
578 action : 'wp_docs_import_memphis_docs',
579 wp_docs_nonce:wpdocs_ajax_object.nonce,
580 };
581
582 $('.wp_docs_importing').show();
583 $('.wp_docs_importing .progress-bar').text(progress_text);
584 $('.wp_docs_importing_alert').hide();
585
586
587 $.post(ajaxurl, data, function(resp, code){
588 $('.wp_docs_importing').hide();
589 if(code == 'success' && resp.status){
590 window.location.href = wpdocs_ajax_object.url;
591 }else if(resp.remarks){
592 $('.wp_docs_importing_alert').show();
593 $('.wp_docs_importing_alert').text(resp.remarks);
594 }
595
596 setTimeout(function() {
597
598 $('.wp_docs_importing_alert').fadeOut();
599
600 }, 5000);
601
602 });
603
604 });
605
606 $('.wp_docs_import_memphis_rollback').on('click', function(){
607
608 var import_confirm = confirm(wpdocs_ajax_object.undo_import_confirm);
609 var progress_text = $(this).data('text');
610
611 if(!import_confirm) return;
612
613 var data = {
614
615 action : 'wp_docs_import_memphis_rollback',
616 wp_docs_nonce:wpdocs_ajax_object.nonce,
617 };
618
619 $('.wp_docs_importing .progress-bar').text(progress_text);
620 $('.wp_docs_importing').show();
621
622 $.post(ajaxurl, data, function(resp, code){
623 $('.wp_docs_importing').hide();
624 if(code == 'success' && resp.status){
625 window.location.href = wpdocs_ajax_object.url;
626 }
627
628 });
629
630 });
631
632
633 $('.wpdocs-wrapper').on('click', 'h2.nav-tab-wrapper a.nav-tab', function(){
634 wpdocs_ajax_object.wc_os_pg = parseInt(wpdocs_ajax_object.wc_os_pg);
635 $(this).siblings().removeClass('nav-tab-active');
636 $(this).addClass('nav-tab-active');
637 $('.nav-tab-content, form:not(.wrap.wpdocs-wrapper .nav-tab-content):not(.ignore)').hide();
638 //console.log($(this).index());
639 $('.nav-tab-content').eq($(this).index()).removeClass('hides').show();
640 var state_url = wpdocs_ajax_object.url+'&t='+$(this).index()+(wpdocs_ajax_object.wc_os_pg>0?'&pg='+wpdocs_ajax_object.wc_os_pg:'');
641 window.history.replaceState('', '', state_url);
642 $('form input[name="wos_tn"]').val($(this).index());
643 wpdocs_ajax_object.wc_os_tab = $(this).index();
644 $('.wrap.wpdocs-wrapper').attr('class', 'wrap wpdocs-wrapper tab-'+$(this).index());
645
646 $('.wpdocs-wrapper form').prop('action', state_url);
647
648 });
649 function parse_query_string(query) {
650 var vars = query.split("&");
651 var query_string = {};
652 for (var i = 0; i < vars.length; i++) {
653 var pair = vars[i].split("=");
654 // If first entry with this name
655 if (typeof query_string[pair[0]] === "undefined") {
656 query_string[pair[0]] = decodeURIComponent(pair[1]);
657 // If second entry with this name
658 } else if (typeof query_string[pair[0]] === "string") {
659 var arr = [query_string[pair[0]], decodeURIComponent(pair[1])];
660 query_string[pair[0]] = arr;
661 // If third or later entry with this name
662 } else {
663 query_string[pair[0]].push(decodeURIComponent(pair[1]));
664 }
665 }
666 return query_string;
667 }
668
669 if($('.wpdocs-wrapper').length>0){
670 var query = window.location.search.substring(1);
671 var qs = parse_query_string(query);
672
673 if(typeof(qs.t)!='undefined'){
674 $('.wpdocs-wrapper a.nav-tab').eq(qs.t).click();
675 }
676 }
677
678 $('#translate_wpdocs_btn').on('click', function(){
679 var val = $.trim($('#translate_wpdocs').val());
680 if(val){
681
682 var url = new URL(val);
683 var dir = url.searchParams.get("dir");
684 var updated_str = val;
685
686 if(typeof(dir)!='undefined' && (dir in wpdocs_ajax_object.all_dirs)){
687 updated_str = updated_str.replace('dir='+dir, wpdocs_ajax_object.all_dirs[dir]);
688 }
689 $('.translate_wpdocs').append(updated_str+'<br />');
690 $('#translate_wpdocs').val('');
691 }
692
693
694 });
695 });