Skip to content
Snippets Groups Projects
Commit 1748ee2d authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

check-in-place-select: only load jquery/select2 when needed

parent 1419ff77
No related branches found
No related tags found
No related merge requests found
import $ from 'jquery';
import {findObjectInApiResults} from './utils.js'; import {findObjectInApiResults} from './utils.js';
import select2 from 'select2';
import select2LangDe from './i18n/de/select2' import select2LangDe from './i18n/de/select2'
import select2LangEn from './i18n/en/select2' import select2LangEn from './i18n/en/select2'
import JSONLD from '@dbp-toolkit/common/jsonld'; import JSONLD from '@dbp-toolkit/common/jsonld';
...@@ -20,7 +18,6 @@ const checkInPlaceContext = { ...@@ -20,7 +18,6 @@ const checkInPlaceContext = {
"maximumPhysicalAttendeeCapacity": "http://schema.org/maximumPhysicalAttendeeCapacity" "maximumPhysicalAttendeeCapacity": "http://schema.org/maximumPhysicalAttendeeCapacity"
}; };
select2(window, $);
export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) { export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) {
...@@ -50,7 +47,10 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) { ...@@ -50,7 +47,10 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) {
} }
$(selector) { $(selector) {
return $(this.shadowRoot.querySelector(selector)); if (typeof selector === "string")
return this._jquery(this.shadowRoot.querySelector(selector));
else
return this._jquery(selector);
} }
static get properties() { static get properties() {
...@@ -68,29 +68,33 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) { ...@@ -68,29 +68,33 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) {
clear() { clear() {
this.object = null; this.object = null;
$(this).attr("data-object", ""); this.$(this).attr("data-object", "");
$(this).attr("value", ""); this.$(this).attr("value", "");
$(this).data("object", null); this.$(this).data("object", null);
this.$select.val(null).trigger('change').trigger('select2:unselect'); this.$select.val(null).trigger('change').trigger('select2:unselect');
} }
connectedCallback() { async connectedCallback() {
super.connectedCallback(); await super.connectedCallback();
const that = this;
this.updateComplete.then(()=>{ this._jquery = (await import('jquery')).default;
that.$select = that.$('#' + that.selectId); let select2 = (await import('select2')).default;
select2(window, this._jquery);
// Close the popup when clicking outside of select2 await this.updateComplete;
document.addEventListener('click', (ev) => { const that = this;
if (!ev.composedPath().includes(this)) {
this._closeSelect2();
}
});
// try an init when user-interface is loaded this.$select = this.$('#' + that.selectId);
that.initJSONLD();
// Close the popup when clicking outside of select2
document.addEventListener('click', (ev) => {
if (!ev.composedPath().includes(this)) {
this._closeSelect2();
}
}); });
// try an init when user-interface is loaded
this.initJSONLD();
} }
_closeSelect2() { _closeSelect2() {
...@@ -119,7 +123,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) { ...@@ -119,7 +123,7 @@ export class CheckInPlaceSelect extends ScopedElementsMixin(LitElement) {
*/ */
initSelect2(ignorePreset = false) { initSelect2(ignorePreset = false) {
const that = this; const that = this;
const $this = $(this); const $this = this.$(this);
if (this.jsonld === null) { if (this.jsonld === null) {
return false; return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment