PluginProbe
WP Directory Kit / 1.2.3
WP Directory Kit v1.2.3
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.3, at admin/js/wdk-dependfields-edit.js

92 lines 3.0 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 })(jQuery);
8
9 var wdk_dependfields_update_jqxhr = null;
10 const wdk_dependfields_update = ($selector = null) => {
11 if(!$selector){
12 console.log('form not detected')
13 return false;
14 }
15
16
17 jQuery($selector).find('input.trigger_section').on('change', function(){
18 var that = jQuery(this);
19 if(that.prop('checked')) {
20 that.closest('.wdk-col-section').nextAll().each(function(){
21 if(jQuery(this).hasClass('wdk-col-section'))
22 return false;
23
24 jQuery(this).find('input:not(.trigger_section)').prop('checked', true);
25 });
26 } else {
27 that.closest('.wdk-col-section').nextAll().each(function(){
28 if(jQuery(this).hasClass('wdk-col-section'))
29 return false;
30
31 jQuery(this).find('input:not(.trigger_section)').prop('checked', false);
32 });
33 }
34
35 var nextEl = that.closest('.wdk-col-section').next();
36 if(!nextEl.hasClass('wdk-col-section')) {
37 nextEl.find('input').trigger('change');
38 }
39 });
40
41 jQuery($selector).find('.wdk-col-section').each(function(){
42 var that = jQuery(this);
43 var checked = true;
44 that.nextAll().each(function(){
45 if(jQuery(this).hasClass('wdk-col-section'))
46 return false;
47
48 if(!jQuery(this).find('input:not(.trigger_section)').prop('checked')) {
49 checked = false;
50 return false;
51 }
52 });
53 if(checked) {
54 that.find('input.trigger_section').prop('checked', true);
55 } else {
56 that.find('input.trigger_section').prop('checked', false);
57 }
58 });
59
60 jQuery($selector).find('input:not(.trigger_section)').on('change', function(){
61 var _this = jQuery(this);
62 var this_form = _this.closest('form');
63 var loading_el = _this.closest('.wdk_field');
64
65 //var data = this_form.serializeArray();
66 var data = new Array();
67 data.push({ name: 'action', value: "wdk_admin_action" });
68 data.push({ name: 'page', value: "wdk_backendajax" });
69 data.push({ name: 'function', value: "update_depend" });
70 data.push({ name: '_wpnonce', value: this_form.find('input[name="_wpnonce"]').val() });
71 data.push({ name: 'main_field', value: this_form.find('input[name="main_field"]').val() });
72 data.push({ name: 'field_id', value: this_form.find('input[name="field_id"]').val() });
73
74 this_form.find('input:not(:checked)').each(function(){
75 if(jQuery(this).attr('name').indexOf('field_hide_') != -1)
76 data.push({ name: jQuery(this).attr('name'), value: "1" });
77 });
78
79 // Assign handlers immediately after making the request,
80 // and remember the jqxhr object for this request
81 if (wdk_dependfields_update_jqxhr != null)
82 wdk_dependfields_update_jqxhr.abort();
83
84 loading_el.addClass('wdk_btn_load_indicator out');
85 wdk_dependfields_update_jqxhr = jQuery.post(script_dependfields_parameters.ajax_url, data, function (data) {
86
87
88 }).always(function(data) {
89 loading_el.removeClass('wdk_btn_load_indicator out');
90 });
91 })
92 }