PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.1
Secure Custom Fields v6.9.1
6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / _field-group-locations.js
secure-custom-fields / assets / src / js Last commit date
bindings 6 months ago commands 1 week ago pro 1 week ago _acf-compatibility.js 1 year ago _acf-condition-types.js 7 months ago _acf-condition.js 1 year ago _acf-conditions.js 1 year ago _acf-field-accordion.js 6 months ago _acf-field-button-group.js 7 months ago _acf-field-checkbox.js 1 month ago _acf-field-color-picker.js 7 months ago _acf-field-date-picker.js 1 month ago _acf-field-date-time-picker.js 1 month ago _acf-field-file.js 1 month ago _acf-field-google-map.js 6 months ago _acf-field-icon-picker.js 1 month ago _acf-field-image.js 1 month ago _acf-field-link.js 1 year ago _acf-field-oembed.js 1 month ago _acf-field-page-link.js 1 year ago _acf-field-post-object.js 1 year ago _acf-field-radio.js 1 month ago _acf-field-range.js 1 year ago _acf-field-relationship.js 1 month ago _acf-field-select.js 1 month ago _acf-field-tab.js 3 weeks ago _acf-field-taxonomy.js 7 months ago _acf-field-time-picker.js 1 month ago _acf-field-true-false.js 1 month ago _acf-field-url.js 1 year ago _acf-field-user.js 1 year ago _acf-field-wysiwyg.js 1 month ago _acf-field.js 1 year ago _acf-fields.js 1 year ago _acf-helpers.js 1 year ago _acf-hooks.js 1 year ago _acf-internal-post-type.js 7 months ago _acf-media.js 1 week ago _acf-modal.js 1 year ago _acf-model.js 1 year ago _acf-notice.js 7 months ago _acf-panel.js 1 year ago _acf-popup.js 7 months ago _acf-postbox.js 1 year ago _acf-screen.js 10 months ago _acf-select2.js 1 year ago _acf-tinymce.js 6 months ago _acf-tooltip.js 10 months ago _acf-unload.js 1 year ago _acf-validation.js 1 month ago _acf.js 7 months ago _browse-fields-modal.js 7 months ago _field-group-compatibility.js 1 year ago _field-group-conditions.js 1 year ago _field-group-field.js 3 months ago _field-group-fields.js 10 months ago _field-group-locations.js 1 year ago _field-group-settings.js 1 year ago _field-group.js 10 months ago acf-escaped-html-notice.js 1 year ago acf-field-group.js 1 year ago acf-input.js 1 year ago acf-internal-post-type.js 1 year ago acf.js 1 year ago
_field-group-locations.js
130 lines
1 ( function ( $, undefined ) {
2 /**
3 * locationManager
4 *
5 * Field group location rules functionality
6 *
7 * @date 15/12/17
8 * @since ACF 5.7.0
9 *
10 * @param void
11 * @return void
12 */
13
14 var locationManager = new acf.Model( {
15 id: 'locationManager',
16 wait: 'ready',
17
18 events: {
19 'click .add-location-rule': 'onClickAddRule',
20 'click .add-location-group': 'onClickAddGroup',
21 'click .remove-location-rule': 'onClickRemoveRule',
22 'change .refresh-location-rule': 'onChangeRemoveRule',
23 },
24
25 initialize: function () {
26 this.$el = $( '#acf-field-group-options' );
27 this.updateGroupsClass();
28 },
29
30 onClickAddRule: function ( e, $el ) {
31 this.addRule( $el.closest( 'tr' ) );
32 },
33
34 onClickRemoveRule: function ( e, $el ) {
35 this.removeRule( $el.closest( 'tr' ) );
36 },
37
38 onChangeRemoveRule: function ( e, $el ) {
39 this.changeRule( $el.closest( 'tr' ) );
40 },
41
42 onClickAddGroup: function ( e, $el ) {
43 this.addGroup();
44 },
45
46 addRule: function ( $tr ) {
47 acf.duplicate( $tr );
48 this.updateGroupsClass();
49 },
50
51 removeRule: function ( $tr ) {
52 if ( $tr.siblings( 'tr' ).length == 0 ) {
53 $tr.closest( '.rule-group' ).remove();
54 } else {
55 $tr.remove();
56 }
57
58 // Update h4
59 var $group = this.$( '.rule-group:first' );
60 $group.find( 'h4' ).text( acf.__( 'Show this field group if' ) );
61
62 this.updateGroupsClass();
63 },
64
65 changeRule: function ( $rule ) {
66 // vars
67 var $group = $rule.closest( '.rule-group' );
68 var prefix = $rule
69 .find( 'td.param select' )
70 .attr( 'name' )
71 .replace( '[param]', '' );
72
73 // ajaxdata
74 var ajaxdata = {};
75 ajaxdata.action = 'acf/field_group/render_location_rule';
76 ajaxdata.rule = acf.serialize( $rule, prefix );
77 ajaxdata.rule.id = $rule.data( 'id' );
78 ajaxdata.rule.group = $group.data( 'id' );
79
80 // temp disable
81 acf.disable( $rule.find( 'td.value' ) );
82
83 const self = this;
84
85 // ajax
86 $.ajax( {
87 url: acf.get( 'ajaxurl' ),
88 data: acf.prepareForAjax( ajaxdata ),
89 type: 'post',
90 dataType: 'html',
91 success: function ( html ) {
92 if ( ! html ) return;
93 $rule.replaceWith( html );
94 },
95 } );
96 },
97
98 addGroup: function () {
99 // vars
100 var $group = this.$( '.rule-group:last' );
101
102 // duplicate
103 $group2 = acf.duplicate( $group );
104
105 // update h4
106 $group2.find( 'h4' ).text( acf.__( 'or' ) );
107
108 // remove all tr's except the first one
109 $group2.find( 'tr' ).not( ':first' ).remove();
110
111 // update the groups class
112 this.updateGroupsClass();
113 },
114
115 updateGroupsClass: function () {
116 var $group = this.$( '.rule-group:last' );
117
118 var $ruleGroups = $group.closest( '.rule-groups' );
119
120 var rows_count = $ruleGroups.find( '.acf-table tr' ).length;
121
122 if ( rows_count > 1 ) {
123 $ruleGroups.addClass( 'rule-groups-multiple' );
124 } else {
125 $ruleGroups.removeClass( 'rule-groups-multiple' );
126 }
127 },
128 } );
129 } )( jQuery );
130