selector.js
26 lines
| 1 | export const url = `${prestoEditorData?.root}${prestoEditorData?.wpVersionString}presto-videos`; |
| 2 | |
| 3 | export default function ($element) { |
| 4 | $element.select2({ |
| 5 | ajax: { |
| 6 | url, |
| 7 | dataType: "json", |
| 8 | headers: { |
| 9 | "X-WP-Nonce": prestoEditorData.nonce, |
| 10 | }, |
| 11 | data: function (params) { |
| 12 | return { |
| 13 | search: params.term, |
| 14 | }; |
| 15 | }, |
| 16 | processResults: function (data) { |
| 17 | return { |
| 18 | results: jQuery.map(data, function (obj) { |
| 19 | return { id: obj.id, text: obj?.title?.raw || "Untitled Video" }; |
| 20 | }), |
| 21 | }; |
| 22 | }, |
| 23 | }, |
| 24 | }); |
| 25 | } |
| 26 |