PageSourceSearch

https://xiongmaodigital.com/wp-content/plugins/ai-addons-for-eleme…/target-rule/target-rule.js?ver=1.0.0

js xiongmaodigital.com collected 2026-10-06 20:55:58 UTC 8,234 bytes, 264 lines download raw bytes

1;(function ( $, window, undefined ) {
2
3	var init_target_rule_select2  = function( selector ) {
4		
5		$(selector).astselect2({
6
7			placeholder: astRules.search,
8
9			ajax: {
10			    url: ajaxurl,
11			    dataType: 'json',
12			    method: 'post',
13			    delay: 250,
14			    data: function (params) {
15			      	return {
16			        	q: params.term, // search term
17				        page: params.page,
18						action: 'aiea_hf_get_posts_by_query',
19						nonce: astRules.ajax_nonce
20			    	};
21				},
22				processResults: function (data) {
23					// console.log(data);
24					// console.log("inside");
25		            // parse the results into the format expected by Select2.
26		            // since we are using custom formatting functions we do not need to
27		            // alter the remote JSON data
28
29		            return {
30		                results: data
31		            };
32		        },
33			    cache: true
34			},
35			minimumInputLength: 2,
36			language: astRules.ast_lang
37		});
38	};
39
40	var update_target_rule_input = function(wrapper) {
41		var rule_input 		= wrapper.find('.ast-target_rule-input');
42		var old_value = rule_input.val();
43		var new_value = [];
44		
45		wrapper.find('.ai-target-rule-condition').each(function(i) {
46			
47			var $this 			= $(this);
48			var temp_obj 		= {};
49			var rule_condition 	= $this.find('select.target_rule-condition');
50			var specific_page 	= $this.find('select.target_rule-specific-page');
51
52			var rule_condition_val 	= rule_condition.val();
53			var specific_page_val 	= specific_page.val();
54			
55			if ( '' != rule_condition_val ) {
56
57				temp_obj = {
58					type 	: rule_condition_val,
59					specific: specific_page_val
60				} 
61				
62				new_value.push( temp_obj );
63			};
64		})
65
66
67		var rules_string = JSON.stringify( new_value );
68		rule_input.val( rules_string );
69	};
70
71	var update_close_button = function(wrapper) {
72
73		type 		= wrapper.closest('.ast-target-rule-wrapper').attr('data-type');
74		rules 		= wrapper.find('.ai-target-rule-condition');
75		show_close	= false;
76
77		if ( 'display' == type ) {
78			if ( rules.length > 1 ) {
79				show_close = true;
80			}
81		}else{
82			show_close = true;
83		}
84
85		rules.each(function() {
86			if ( show_close ) {
87				jQuery(this).find('.target_rule-condition-delete').removeClass('ast-hidden');
88			}else{
89				jQuery(this).find('.target_rule-condition-delete').addClass('ast-hidden');
90			}
91		});
92	};
93
94	var update_exclusion_button = function( force_show, force_hide ) {
95		var display_on = $('.ast-target-rule-display-on-wrap');
96		var exclude_on = $('.ast-target-rule-exclude-on-wrap');
97		
98		var exclude_field_wrap = exclude_on.closest('tr');
99		var add_exclude_block  = display_on.find('.target_rule-add-exclusion-rule');
100		var exclude_conditions = exclude_on.find('.ai-target-rule-condition');
101		
102		if ( true == force_hide ) {
103			exclude_field_wrap.addClass( 'ast-hidden' );
104			add_exclude_block.removeClass( 'ast-hidden' );
105		}else if( true == force_show ){
106			exclude_field_wrap.removeClass( 'ast-hidden' );
107			add_exclude_block.addClass( 'ast-hidden' );
108		}else{
109			
110			if ( 1 == exclude_conditions.length && '' == $(exclude_conditions[0]).find('select.target_rule-condition').val() ) {
111				exclude_field_wrap.addClass( 'ast-hidden' );
112				add_exclude_block.removeClass( 'ast-hidden' );
113			}else{
114				exclude_field_wrap.removeClass( 'ast-hidden' );
115				add_exclude_block.addClass( 'ast-hidden' );
116			}
117		}
118
119	};
120	
121	var aiea_hide_shortcode_field = function() {
122		var selected = $('#aiea_hf_template_type').val() || 'none';
123		$( '.ai-hf-options-table' ).removeClass().addClass( 'ai-hf-options-table widefat ai-hf-selected-template-type-' + selected );
124	}
125
126	
127
128	$(document).ready(function($) {
129		
130		var $document = $( document );
131		
132		$("#postbox-container-1 > div > .postbox:not(#submitdiv)").remove();
133		$("#postbox-container-2 > div > .postbox:not(#ai-hf-meta-box)").remove();
134		
135		$document.on( 'change', '#aiea_hf_template_type', function( e ) {
136			aiea_hide_shortcode_field();
137		});
138		aiea_hide_shortcode_field();
139
140		jQuery( '.ai-target-rule-condition' ).each( function() {
141			var $this 			= $( this ),
142				condition 		= $this.find('select.target_rule-condition'),
143				condition_val 	= condition.val(),
144				specific_page 	= $this.next( '.target_rule-specific-page-wrap' );
145
146			if( 'specifics' == condition_val ) {
147				specific_page.slideDown( 300 );
148			}
149		} );
150
151		
152		jQuery('select.target-rule-select2').each(function(index, el) {
153			init_target_rule_select2( el );
154		});
155
156		jQuery('.ast-target-rule-selector-wrapper').each(function() {
157			update_close_button( jQuery(this) );
158		})
159
160		/* Show hide exclusion button */
161		update_exclusion_button();
162
163		jQuery( document ).on( 'change', '.ai-target-rule-condition select.target_rule-condition' , function( e ) {
164			
165			var $this 		= jQuery(this),
166				this_val 	= $this.val(),
167				field_wrap 	= $this.closest('.ast-target-rule-wrapper');
168
169			if( 'specifics' == this_val ) {
170				$this.closest( '.ai-target-rule-condition' ).next( '.target_rule-specific-page-wrap' ).slideDown( 300 );
171			} else {
172				$this.closest( '.ai-target-rule-condition' ).next( '.target_rule-specific-page-wrap' ).slide
172Up( 300 );
173			}
174
175			update_target_rule_input( field_wrap );
176		} );
177
178		jQuery( '.ast-target-rule-selector-wrapper' ).on( 'change', '.target-rule-select2', function(e) {
179			var $this 		= jQuery( this ),
180				field_wrap 	= $this.closest('.ast-target-rule-wrapper');
181
182			update_target_rule_input( field_wrap );
183		});
184		
185		jQuery( '.ast-target-rule-selector-wrapper' ).on( 'click', '.target_rule-add-rule-wrap a', function(e) {
186			e.preventDefault();
187			e.stopPropagation();
188			var $this 	= jQuery( this ),
189				id 		= $this.attr( 'data-rule-id' ),
190				new_id 	= parseInt(id) + 1,
191				type 	= $this.attr( 'data-rule-type' ),
192				rule_wrap = $this.closest('.ast-target-rule-selector-wrapper').find('.target_rule-builder-wrap'),
193				template  = wp.template( 'ai-target-rule-' + type + '-condition' ),
194				field_wrap 		= $this.closest('.ast-target-rule-wrapper');
195			
196			rule_wrap.append( template( { id : new_id, type : type } ) );
197			
198			init_target_rule_select2( '.ast-target-rule-'+type+'-on .target-rule-select2' );
199			
200			$this.attr( 'data-rule-id', new_id );
201
202			update_close_button( field_wrap );
203		});
204
205		jQuery( '.ast-target-rule-selector-wrapper' ).on( 'click', '.target_rule-condition-delete', function(e) {
206			var $this 			= jQuery( this ),
207				rule_condition 	= $this.closest('.ai-target-rule-condition'),
208				field_wrap 		= $this.closest('.ast-target-rule-wrapper');
209				cnt 			= 0,
210				data_type 		= field_wrap.attr( 'data-type' ),
211				optionVal 		= $this.siblings('.target_rule-condition-wrap').children('.target_rule-condition').val();
212
213			if ( 'exclude' == data_type ) {
214					
215				if ( 1 === field_wrap.find('.target_rule-condition').length ) {
216
217					field_wrap.find('.target_rule-condition').val('');
218					field_wrap.find('.target_rule-specific-page').val('');
219					field_wrap.find('.target_rule-condition').trigger('change');
220					update_exclusion_button( false, true );
221
222				}else{
223					$this.parent('.ai-target-rule-condition').next('.target_rule-specific-page-wrap').remove();
224					rule_condition.remove();
225				}
226
227			} else {
228
229				$this.parent('.ai-target-rule-condition').next('.target_rule-specific-page-wrap').remove();
230				rule_condition.remove();
231			}
232
233			field_wrap.find('.ai-target-rule-condition').each(function(i) {
234				var condition       = jQuery( this ),
235					old_rule_id     = condition.attr('data-rule'),
236					select_location = condition.find('.target_rule-condition'),
237					select_specific = condition.find('.target_rule-specific-page'),
238					location_name   = select_location.attr( 'name' );
239					
240				condition.attr( 'data-rule', i );
241
242				select_location.attr( 'name', location_name.replace('['+old_rule_id+']', '['+i+']') );
243				
244				condition.removeClass('ast-target-rule-'+old_rule_id).addClass('ast-target-rule-'+i);
245
246				cnt = i;
247			});
248
249			field_wrap.find('.target_rule-add-rule-wrap a').attr( 'data-rule-id', cnt )
250
251			update_close_button( field_wrap );
252			update_target_rule_input( field_wrap );
253		});
254		
255		jQuery( '.ast-target-rule-selector-wrapper' ).on( 'click', '.target_rule-add-exclusion-rule a', function(e) {
256			e.preventDefault();
257			e.stopPropagation();
258			update_exclusion_button( true );
259		});
260			
261		
262	});
263
264}(jQuery, window));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.