PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 2.0.25
Advanced Ads – Ad Manager & AdSense v2.0.25
2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / admin / assets / js / conditions.js
advanced-ads / admin / assets / js Last commit date
adblocker-image-data.js 1 year ago admin-global.js 1 year ago admin.js 2 days ago advertisement.js 3 months ago conditions.js 1 year ago dialog-advads-modal.js 1 year ago termination.js 1 year ago ui.js 3 years ago
conditions.js
535 lines
1 /**
2 * Logic for Display and Visitor Conditions forms
3 */
4
5 jQuery(document).ready(function ($) {
6 /**
7 * Pressing the button to add a new condition to the list of conditions
8 */
9 $('.advads-conditions-new select').on('change', function () {
10 // get the form fieldset and values.
11 const condition_form_container = $(this).parents('fieldset');
12 const condition_type = condition_form_container
13 .find('.advads-conditions-new select')
14 .val();
15 const condition_title = condition_form_container
16 .find('.advads-conditions-new select option:selected')
17 .text();
18 let condition_index = parseInt(
19 condition_form_container.find('.advads-conditions-index').val()
20 );
21 const condition_list_target_ID = $.escapeSelector(
22 condition_form_container.data('condition-list-target')
23 ); // ID of the container into which the new condition is loaded.
24 const condition_list_target = $('#' + condition_list_target_ID); // container into which the new condition is loaded.
25 const conditions_form_name = condition_form_container.data(
26 'condition-form-name'
27 ); // name prefix for the form.
28 const conditions_connector_default = condition_form_container.data(
29 'condition-connector-default'
30 ); // default connector option.
31 const conditions_action =
32 condition_form_container.data('condition-action'); // action to which to send the AJAX call to.
33 if (!condition_type || '' == condition_type) {
34 return;
35 }
36 condition_form_container.find('.advads-loader').show(); // show loader.
37 $.ajax({
38 type: 'POST',
39 url: ajaxurl,
40 data: {
41 action: conditions_action,
42 type: condition_type,
43 index: condition_index,
44 form_name: conditions_form_name,
45 nonce: advadsglobal.ajax_nonce,
46 },
47 success(r, textStatus, XMLHttpRequest) {
48 // add.
49 if (r) {
50 if ('or' === conditions_connector_default) {
51 // as used for display conditions.
52 var connector =
53 '<input style="display:none;" type="checkbox" name="' +
54 conditions_form_name +
55 '[' +
56 condition_index +
57 '][connector]" checked="checked" value="or" id="advads-conditions-' +
58 condition_list_target_ID +
59 '-' +
60 condition_index +
61 '-connector"><label for="advads-conditions-' +
62 condition_list_target_ID +
63 '-' +
64 condition_index +
65 '-connector">' +
66 advadstxt.condition_or +
67 '</label>';
68 var newline =
69 '<tr class="advads-conditions-connector advads-conditions-connector-or"><td colspan="3">' +
70 connector +
71 '</td></tr><tr><td class="advads-conditions-type" data-condition-type="' +
72 condition_type +
73 '">' +
74 condition_title +
75 '</td><td>' +
76 r +
77 '</td><td><button type="button" class="advads-conditions-remove button">x</button></td></tr>';
78 } else {
79 // as used for visitor conditions.
80 var connector =
81 '<input type="checkbox" name="' +
82 conditions_form_name +
83 '[' +
84 condition_index +
85 '][connector]" value="or" id="advads-conditions-' +
86 condition_list_target_ID +
87 '-' +
88 condition_index +
89 '-connector"><label for="advads-conditions-' +
90 condition_list_target_ID +
91 '-' +
92 condition_index +
93 '-connector">' +
94 advadstxt.condition_and +
95 '</label>';
96 var newline =
97 '<tr class="advads-conditions-connector advads-conditions-connector-and"><td colspan="3">' +
98 connector +
99 '</td></tr><tr><td class="advads-conditions-type" data-condition-type="' +
100 condition_type +
101 '">' +
102 condition_title +
103 '</td><td>' +
104 r +
105 '</td><td><button type="button" class="advads-conditions-remove button">x</button></td></tr>';
106 }
107 condition_list_target.find('tbody').append(newline);
108 condition_list_target
109 .find(
110 'tbody .advads-conditions-single.advads-buttonset'
111 )
112 .advads_buttonset();
113 condition_list_target
114 .find('tbody .advads-conditions-connector input')
115 .advads_button();
116 // increase count.
117 condition_index++;
118 condition_form_container
119 .find('.advads-conditions-index')
120 .val(condition_index);
121 // reset select.
122 condition_form_container.find(
123 '.advads-conditions-new select'
124 )[0].selectedIndex = 0;
125 advads_display_condition_option_not_selected();
126 const tr = $(this).parents('.advads-conditions-table tr');
127
128 condition_list_target.next('input').remove();
129 }
130 },
131 error(MLHttpRequest, textStatus, errorThrown) {
132 condition_form_container
133 .find('.advads-conditions-new')
134 .append(errorThrown);
135 },
136 complete(MLHttpRequest, textStatus) {
137 condition_form_container
138 .find('.advads-conditions-new .advads-loader')
139 .hide(); // hide loader.
140 },
141 });
142 });
143 // disable term in the term list of the appropriate condition by just clicking on it.
144 $(document).on(
145 'click',
146 '.advads-conditions-terms-buttons .button',
147 function (e) {
148 $(this).remove();
149 }
150 );
151 // display input field to search for terms.
152 $(document).on(
153 'click',
154 '.advads-conditions-terms-show-search',
155 function (e) {
156 e.preventDefault();
157 // display input field.
158 $(this).siblings('.advads-conditions-terms-search').show().focus();
159 // register autocomplete.
160 advads_register_terms_autocomplete(
161 $(this).siblings('.advads-conditions-terms-search')
162 );
163 $(this).next('br').show();
164 $(this).hide();
165 }
166 );
167
168 // function for autocomplete.
169 function advads_register_terms_autocomplete(self) {
170 self.autocomplete({
171 classes: {
172 'ui-autocomplete': 'advads-ui-autocomplete',
173 },
174 source(request, callback) {
175 // var searchField = request.term;
176 advads_term_search(self, callback);
177 },
178 minLength: 1,
179 select(event, ui) {
180 // append new line with input fields.
181 $(
182 '<label class="button advads-button advads-ui-state-active"><span class="advads-button-text">' +
183 ui.item.label +
184 '<input type="hidden" name="' +
185 self.data('inputName') +
186 '" value="' +
187 ui.item.value +
188 '"></span></label>'
189 ).appendTo(self.siblings('.advads-conditions-terms-buttons'));
190
191 // show / hide other elements
192 // $( '.advads-display-conditions-individual-post' ).hide();
193 // $( '.advads-conditions-postids-list .show-search a' ).show();
194 },
195 // eslint-disable-next-line no-unused-vars
196 close(event, ui) {
197 self.val('');
198 },
199 });
200 }
201
202 // remove author from list by clicking on it.
203 $(document).on(
204 'click',
205 '.advads-conditions-authors-buttons .button',
206 function () {
207 $(this).remove();
208 }
209 );
210 // display input field to search for author.
211 $(document).on(
212 'click',
213 '.advads-conditions-authors-show-search',
214 function (e) {
215 e.preventDefault();
216 // display input field.
217 $(this)
218 .siblings('.advads-conditions-authors-search')
219 .show()
220 .focus();
221 // register autocomplete.
222 advadsRegisterAuthorAutocomplete(
223 $(this).siblings('.advads-conditions-authors-search')
224 );
225 $(this).next('br').show();
226 $(this).hide();
227 }
228 );
229
230 // author search box autocomplete.
231 function advadsRegisterAuthorAutocomplete(self) {
232 self.autocomplete({
233 classes: {
234 'ui-autocomplete': 'advads-ui-autocomplete',
235 },
236 source(request, callback) {
237 advadsAuthorSearch(self, callback);
238 },
239 minLength: 1,
240 select(event, ui) {
241 // append new line with input fields.
242 $(
243 '<label class="button advads-button advads-ui-state-active"><span class="advads-button-text">' +
244 ui.item.label +
245 '<input type="hidden" name="' +
246 self.data('inputName') +
247 '" value="' +
248 ui.item.value +
249 '"></span></label>'
250 ).appendTo(self.siblings('.advads-conditions-authors-buttons'));
251 },
252 close() {
253 self.val('');
254 },
255 });
256 }
257
258 // display input field to search for post, page, etc.
259 $(document).on(
260 'click',
261 '.advads-conditions-postids-show-search',
262 function (e) {
263 e.preventDefault();
264 // display input field.
265 $(this)
266 .next()
267 .find('.advads-display-conditions-individual-post')
268 .show();
269 //$( '.advads-conditions-postids-search-line .description' ).hide();
270 $(this).hide();
271 }
272 );
273 // register autocomplete to display condition individual posts.
274 // eslint-disable-next-line no-unused-vars
275 $(document).on(
276 'focus',
277 '.advads-display-conditions-individual-post',
278 // eslint-disable-next-line no-unused-vars
279 function (e) {
280 const self = this;
281 if (!$(this).data('autocomplete')) {
282 // If the autocomplete wasn't called yet:
283 $(this)
284 .autocomplete({
285 classes: {
286 'ui-autocomplete': 'advads-ui-autocomplete',
287 },
288 source(request, callback) {
289 const searchParam = request.term;
290 advads_post_search(searchParam, callback);
291 },
292 minLength: 1,
293 select(event, ui) {
294 // append new line with input fields
295 const newline = $(
296 `<label class="button advads-button advads-ui-state-active"><span class="advads-button-text">${ui.item.label}</span></label>`
297 );
298 $(
299 `<input type="hidden" name="${self.dataset.fieldName}[value][]" value="${ui.item.value}"/>`
300 ).appendTo(newline);
301 newline.insertBefore(
302 $(self).parent(
303 '.advads-conditions-postids-search-line'
304 )
305 );
306 },
307 // eslint-disable-next-line no-unused-vars
308 close(event, ui) {
309 $(self).val('');
310 },
311 })
312 .autocomplete()
313 .data('ui-autocomplete')._renderItem = function (ul, item) {
314 ul.addClass(
315 'advads-conditions-postids-autocomplete-suggestions'
316 );
317 return $('<li></li>')
318 .append(
319 "<span class='left'>" +
320 item.label +
321 "</span>&nbsp;<span class='right'>" +
322 item.info +
323 '</span>'
324 )
325 .appendTo(ul);
326 };
327 }
328 }
329 );
330
331 // remove individual posts from the display conditions post list.
332 $(document).on(
333 'click',
334 '.advads-conditions-postid-buttons .button',
335 // eslint-disable-next-line no-unused-vars
336 function (e) {
337 $(this).remove();
338 }
339 );
340 // display/hide error message if no option was selected
341 // is also called on every click.
342 function advads_display_condition_option_not_selected() {
343 $('.advads-conditions-not-selected').each(function () {
344 if ($(this).siblings('input:checked').length) {
345 $(this).hide();
346 } else {
347 $(this).show();
348 }
349 });
350 }
351
352 advads_display_condition_option_not_selected();
353
354 // update error messages when an item is clicked.
355 $(document).on(
356 'click',
357 '.advads-conditions-terms-buttons input[type="checkbox"], .advads-conditions-single input[type="checkbox"]',
358 function () {
359 // needs a slight delay until the buttons are updated.
360 window.setTimeout(
361 advads_display_condition_option_not_selected,
362 200
363 );
364 }
365 );
366 // activate and toggle conditions connector option.
367 $('.advads-conditions-connector input').advads_button();
368
369 // dynamically change label.
370 jQuery(document).on(
371 'click',
372 '.advads-conditions-connector input',
373 function () {
374 if (jQuery(this).is(':checked')) {
375 jQuery(this)
376 .next('label')
377 .find('span')
378 .html(advadstxt.condition_or);
379 jQuery(this)
380 .parents('.advads-conditions-connector')
381 .addClass('advads-conditions-connector-or')
382 .removeClass('advads-conditions-connector-and');
383 } else {
384 jQuery(this)
385 .next('label')
386 .find('span')
387 .html(advadstxt.condition_and);
388 jQuery(this)
389 .parents('.advads-conditions-connector')
390 .addClass('advads-conditions-connector-and')
391 .removeClass('advads-conditions-connector-or');
392 }
393 }
394 );
395 // remove a line with a display or visitor condition.
396 $(document).on('click', '.advads-conditions-remove', function () {
397 const tr = $(this).parents('.advads-conditions-table tr');
398 const table = $(this).closest('.advads-conditions-table');
399 tr.prev('tr').remove();
400 tr.remove();
401
402 if (table.find('tr').length === 0) {
403 const fieldset = table.next('fieldset');
404 table.after(
405 '<input type="hidden" name="' +
406 fieldset.data('condition-form-name') +
407 '[0][type]" value="unknown">'
408 );
409 }
410 });
411 });
412
413 /**
414 * Callback for term search autocomplete
415 *
416 * @param {type} search term
417 * @param field
418 * @param {type} callback
419 * @return {obj} json object with labels and values
420 */
421 function advads_term_search(field, callback) {
422 // return ['post', 'poster'];
423 const query = {
424 action: 'advads-terms-search',
425 nonce: advadsglobal.ajax_nonce,
426 };
427
428 query.search = field.val();
429 query.tax = field.data('tagName');
430
431 let querying = true;
432
433 const results = {};
434 jQuery.post(
435 ajaxurl,
436 query,
437 function (r) {
438 querying = false;
439 const results = [];
440 if (r) {
441 r.map(function (element, index) {
442 results[index] = {
443 value: element.term_id,
444 label: element.name,
445 };
446 });
447 }
448 callback(results);
449 },
450 'json'
451 );
452 }
453
454 /**
455 * Callback for author search autocomplete
456 *
457 * @param {string} search author
458 * @param {HTMLInputElement} field html input field
459 * @param {Function} callback Callback function
460 * @return {Object} JSON object with labels and values
461 */
462
463 function advadsAuthorSearch(field, callback) {
464 const query = {
465 action: 'advads-authors-search',
466 nonce: advadsglobal.ajax_nonce,
467 };
468
469 query.search = field.val();
470
471 let querying = true;
472
473 const results = [];
474 // eslint-disable-next-line no-undef
475 jQuery.post(
476 // eslint-disable-next-line no-undef
477 ajaxurl,
478 query,
479 function (r) {
480 querying = false;
481 if (r) {
482 r.map(function (element, index) {
483 results[index] = {
484 value: element.data.ID,
485 label: element.data.display_name,
486 };
487 });
488 }
489 callback(results);
490 },
491 'json'
492 );
493 }
494
495 /**
496 * Callback for post search autocomplete
497 *
498 * @param {str} searchParam
499 * @param {type} callback
500 * @return {obj} json object with labels and values
501 */
502 function advads_post_search(searchParam, callback) {
503 // return ['post', 'poster'];
504 const query = {
505 action: 'advads-post-search',
506 _ajax_linking_nonce: jQuery('#_ajax_linking_nonce').val(),
507 search: searchParam,
508 nonce: advadsglobal.ajax_nonce,
509 };
510
511 let querying = true;
512
513 const results = {};
514 jQuery.post(
515 ajaxurl,
516 query,
517 function (r) {
518 querying = false;
519 const results = [];
520 if (r) {
521 // eslint-disable-next-line array-callback-return
522 r.map(function (element, index) {
523 results[index] = {
524 label: element.title,
525 value: element.ID,
526 info: element.info,
527 };
528 });
529 }
530 callback(results);
531 },
532 'json'
533 );
534 }
535