PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.7
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / admin / js / wdk-dependfields-edit.js

wdk-dependfields-edit.js in WP Directory Kit 1.2.7, at admin/js/wdk-dependfields-edit.js

125 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 (function ($) {
3 'use strict';
4 jQuery(document).ready(function ($) {
5 wdk_dependfields_update('form.wdk-depend-fields');
6
7 $('.wdk_copy_on_subcategories').on('click', function(e){
8 e.preventDefault();
9 wdk_copy_on_subcategories($(this).attr('data-category'), this, $(this).attr('data-wpnonce'));
10 });
11 });
12 })(jQuery);
13
14 var wdk_dependfields_update_jqxhr = null;
15 const wdk_dependfields_update = ($selector = null) => {
16 if(!$selector){
17 console.log('form not detected')
18 return false;
19 }
20
21
22 jQuery($selector).find('input.trigger_section').on('change', function(){
23 var that = jQuery(this);
24 if(that.prop('checked')) {
25 that.closest('.wdk-col-section').nextAll().each(function(){
26 if(jQuery(this).hasClass('wdk-col-section'))
27 return false;
28
29 jQuery(this).find('input:not(.trigger_section)').prop('checked', true);
30 });
31 } else {
32 that.closest('.wdk-col-section').nextAll().each(function(){
33 if(jQuery(this).hasClass('wdk-col-section'))
34 return false;
35
36 jQuery(this).find('input:not(.trigger_section)').prop('checked', false);
37 });
38 }
39
40 var nextEl = that.closest('.wdk-col-section').next();
41 if(!nextEl.hasClass('wdk-col-section')) {
42 nextEl.find('input').trigger('change');
43 }
44 });
45
46 jQuery($selector).find('.wdk-col-section').each(function(){
47 var that = jQuery(this);
48 var checked = true;
49 that.nextAll().each(function(){
50 if(jQuery(this).hasClass('wdk-col-section'))
51 return false;
52
53 if(!jQuery(this).find('input:not(.trigger_section)').prop('checked')) {
54 checked = false;
55 return false;
56 }
57 });
58 if(checked) {
59 that.find('input.trigger_section').prop('checked', true);
60 } else {
61 that.find('input.trigger_section').prop('checked', false);
62 }
63 });
64
65 jQuery($selector).find('input:not(.trigger_section)').on('change', function(){
66 var _this = jQuery(this);
67 var this_form = _this.closest('form');
68 var loading_el = _this.closest('.wdk_field');
69
70 //var data = this_form.serializeArray();
71 var data = new Array();
72 data.push({ name: 'action', value: "wdk_admin_action" });
73 data.push({ name: 'page', value: "wdk_backendajax" });
74 data.push({ name: 'function', value: "update_depend" });
75 data.push({ name: '_wpnonce', value: this_form.find('input[name="_wpnonce"]').val() });
76 data.push({ name: 'main_field', value: this_form.find('input[name="main_field"]').val() });
77 data.push({ name: 'field_id', value: this_form.find('input[name="field_id"]').val() });
78
79 this_form.find('input:not(:checked)').each(function(){
80 if(jQuery(this).attr('name').indexOf('field_hide_') != -1)
81 data.push({ name: jQuery(this).attr('name'), value: "1" });
82 });
83
84 // Assign handlers immediately after making the request,
85 // and remember the jqxhr object for this request
86 if (wdk_dependfields_update_jqxhr != null)
87 wdk_dependfields_update_jqxhr.abort();
88
89 loading_el.addClass('wdk_btn_load_indicator out');
90
91 wdk_dependfields_update_jqxhr = jQuery.post(script_dependfields_parameters.ajax_url, data, function (data) {
92
93
94 }).always(function(data) {
95 loading_el.removeClass('wdk_btn_load_indicator out');
96 });
97 })
98 }
99
100 var wdk_copy_on_subcategories_jqxhr = null;
101 const wdk_copy_on_subcategories = ($category_id = null, el, $_wpnonce) => {
102
103 if(!$category_id) return false;
104
105 var el = jQuery(el);
106
107 //var data = this_form.serializeArray();
108 var data = new Array();
109 data.push({ name: 'action', value: "wdk_admin_action" });
110 data.push({ name: 'page', value: "wdk_backendajax" });
111 data.push({ name: 'function', value: "depend_copy_on_subcategories" });
112 data.push({ name: 'category_id', value: $category_id });
113 data.push({ name: '_wpnonce', value: $_wpnonce });
114
115 // and remember the jqxhr object for this request
116 if (wdk_copy_on_subcategories_jqxhr != null)
117 wdk_copy_on_subcategories_jqxhr.abort();
118
119 el.addClass('wdk_btn_load_indicator out');
120 wdk_copy_on_subcategories_jqxhr = jQuery.post(script_dependfields_parameters.ajax_url, data, function (data) {
121 console.log('success copied')
122 }).always(function(data) {
123 el.removeClass('wdk_btn_load_indicator out');
124 });
125 }