PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.49
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.49
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / controls / Ajax_Select2 / ajax-select2.js

ajax-select2.js in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.49, at includes/controls/Ajax_Select2/ajax-select2.js

65 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // noinspection JSUnresolvedReference,CommaExpressionJS,SpellCheckingInspection
2
3 jQuery(window).on('elementor:init', (function () {
4 "use strict";
5 let kingaddonsAjaxSelect2 = elementor.modules.controls.BaseData.extend({
6 onReady: function () {
7 let $this = this,
8 $select = $this.ui.select,
9 restUrl = $select.attr('data-rest-url'),
10 nonce = window.wpApiSettings.nonce;
11
12 let querySlug = '' !== $select.attr('data-query-slug') ? $select.attr('data-query-slug') : '';
13
14 $select.select2({
15 ajax: {
16 url: restUrl,
17 dataType: 'json',
18 headers: {
19 'X-WP-Nonce': nonce
20 },
21 data: function (response) {
22 return {
23 s: response.term,
24 query_slug: querySlug
25 }
26 }
27 },
28 cache: !0
29 });
30
31 let controlValue = void 0 !== $this.getControlValue() ? $this.getControlValue() : '';
32
33 controlValue.isArray && (controlValue = $this.getControlValue().join()), jQuery.ajax({
34 url: restUrl,
35 dataType: 'json',
36 headers: {
37 'X-WP-Nonce': nonce
38 },
39 data: {
40 ids: String(controlValue),
41 query_slug: querySlug
42 }
43 }).then((function (response) {
44 if ('' !== controlValue) {
45 null !== response && response.results.length > 0 && (jQuery.each(response.results, (function (index, element) {
46 let option = new Option(element.text, element.id, !0, !0);
47 $select.append(option);
48 $select.append(option).trigger('change.select2');
49 $select.val(controlValue).trigger('change.select2');
50 })), $select.trigger({
51 type: 'select2:select',
52 params: {
53 data: response
54 }
55 }))
56 }
57 }))
58 },
59 onBeforeDestroy: function () {
60 this.ui.select.data('select2') && this.ui.select.select2('destroy'), this.el.remove()
61 }
62 });
63
64 elementor.addControlView('king-addons-ajax-select2', kingaddonsAjaxSelect2)
65 }));