PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.0
Easy Elements for Elementor – Addons & Website Templates v1.3.0
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 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.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / assets / js / easyel-autocomplete.js

easyel-autocomplete.js in Easy Elements for Elementor – Addons & Website Templates 1.3.0, at assets/js/easyel-autocomplete.js

104 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(window).on("elementor:init", function () {
2
3 // Extend Elementor Control
4 const EasyAutocomplete = elementor.modules.controls.BaseData.extend({
5
6 isSearch: false,
7
8 //------------------------------------------------------
9 // Load initial selected items from DB
10 //------------------------------------------------------
11 loadSelectedResults() {
12 const ids = this.normalizeIDs(this.getControlValue());
13 if (!ids.length) return;
14
15 this.showSpinner();
16
17 jQuery.ajax({
18 url: easyel_custom_select_obj.ajax_url,
19 type: "POST",
20 data: {
21 action: this.model.get("render"),
22 post_type: this.model.get("post_type"),
23 taxonomy: this.model.get("taxonomy"),
24 query_type: this.model.get("query_type"),
25 id: ids,
26 security: easyel_custom_select_obj.security,
27 },
28 success: (results) => {
29 this.isSearch = true;
30 this.model.set("options", results);
31 this.render();
32 },
33 });
34 },
35
36 //------------------------------------------------------
37 // Normalize ID Input
38 //------------------------------------------------------
39 normalizeIDs(value) {
40 if (!value) return [];
41 return Array.isArray(value) ? value : [value];
42 },
43
44 //------------------------------------------------------
45 // Add loading spinner
46 //------------------------------------------------------
47 showSpinner() {
48 this.ui.select.prop("disabled", true);
49 this.$el
50 .find(".elementor-control-title")
51 .after(`<span class="elementor-control-spinner">&nbsp;<i class="fa fa-spinner fa-spin"></i>&nbsp;</span>`);
52 },
53
54 //------------------------------------------------------
55 // Ready state – initialize Select2 dropdown
56 //------------------------------------------------------
57 onReady: function () {
58 const self = this;
59
60 this.ui.select.select2({
61 placeholder: "Search",
62 allowClear: true,
63 minimumInputLength: 2,
64 ajax: {
65 url: easyel_custom_select_obj.ajax_url,
66 method: "POST",
67 dataType: "json",
68 delay: 250,
69 data(params) {
70 return {
71 q: params.term,
72 action: self.model.get("search"),
73 post_type: self.model.get("post_type"),
74 taxonomy: self.model.get("taxonomy"),
75 query_type: self.model.get("query_type"),
76 security: easyel_custom_select_obj.security,
77 };
78 },
79 processResults(data) {
80 return { results: data };
81 },
82 cache: true,
83 },
84 });
85
86 if (!this.isSearch) {
87 this.loadSelectedResults();
88 }
89 },
90
91 //------------------------------------------------------
92 // Cleanup when destroyed
93 //------------------------------------------------------
94 onBeforeDestroy() {
95 if (this.ui.select.data("select2")) {
96 this.ui.select.select2("destroy");
97 }
98 this.$el.remove();
99 },
100 });
101
102 // Register the new control
103 elementor.addControlView("easyel_autocomplete", EasyAutocomplete);
104 });