| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
var __webpack_exports__ = {}; |
| 3 |
/*!***************************************************!*\ |
| 4 |
!*** ./assets/src/apps/js/admin/pages/widgets.js ***! |
| 5 |
\***************************************************/ |
| 6 |
const $ = jQuery; |
| 7 |
function formatCourse(repo) { |
| 8 |
if (repo.loading) { |
| 9 |
return repo.text; |
| 10 |
} |
| 11 |
const markup = "<div class='select2-result-course_title'>" + repo.id + ' - ' + repo.title.rendered + '</div>'; |
| 12 |
return markup; |
| 13 |
} |
| 14 |
function formatCourseSelection(repo) { |
| 15 |
return repo.title.rendered || repo.text; |
| 16 |
} |
| 17 |
function autocompleteWidget() { |
| 18 |
let widget = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; |
| 19 |
const searchs = $('.lp-widget_select_course'); |
| 20 |
const wpRestUrl = searchs.data('rest-url'); |
| 21 |
const postType = searchs.data('post_type') || 'lp_course'; |
| 22 |
searchs.select2({ |
| 23 |
ajax: { |
| 24 |
method: 'GET', |
| 25 |
url: wpRestUrl + 'wp/v2/' + postType, |
| 26 |
dataType: 'json', |
| 27 |
delay: 250, |
| 28 |
data(params) { |
| 29 |
return { |
| 30 |
search: params.term |
| 31 |
}; |
| 32 |
}, |
| 33 |
processResults(data, params) { |
| 34 |
params.page = params.page || 1; |
| 35 |
return { |
| 36 |
results: data |
| 37 |
}; |
| 38 |
}, |
| 39 |
cache: true |
| 40 |
}, |
| 41 |
escapeMarkup(markup) { |
| 42 |
return markup; |
| 43 |
}, |
| 44 |
minimumInputLength: 2, |
| 45 |
templateResult: formatCourse, |
| 46 |
// omitted for brevity, see the source of this page |
| 47 |
templateSelection: formatCourseSelection // omitted for brevity, see the source of this page |
| 48 |
}); |
| 49 |
} |
| 50 |
|
| 51 |
document.addEventListener('DOMContentLoaded', function (event) { |
| 52 |
if (document.querySelector('#widgets-editor')) { |
| 53 |
$(document).on('widget-added', function (event, widget) { |
| 54 |
autocompleteWidget(widget); |
| 55 |
}); |
| 56 |
} else { |
| 57 |
$(document).on('learnpress/widgets/select', function () { |
| 58 |
autocompleteWidget(); |
| 59 |
}); |
| 60 |
autocompleteWidget(); |
| 61 |
} |
| 62 |
}); |
| 63 |
/******/ })() |
| 64 |
; |
| 65 |
//# sourceMappingURL=widgets.js.map |