Skip to content

Commit

Permalink
Update logic.js
Browse files Browse the repository at this point in the history
Fix #329
  • Loading branch information
mclemente committed Oct 21, 2023
1 parent 0434cc2 commit d34fc25
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/module/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,38 @@ export class Polyglot {
return $state;
};

select.select2({
data: options,
dropdownCssClass: "polyglot-language",
templateResult: formatState,
templateSelection: formatState,
});
$(".select2-selection__rendered").hover(function () {
$(this).removeAttr("title");
});
// This is needed in case a system or another module already defined select2 under version 4.1, which doesn't accept dropdownCssClass
try {
select.select2({
data: options,
dropdownCssClass: "polyglot-language",
templateResult: formatState,
templateSelection: formatState,
});
} catch(error) {
if (error.message.includes("No select2/compat/dropdownCss")) {
select.select2({
data: options,
templateResult: formatState,
templateSelection: formatState,
});
}
else {
console.error(error);
}
}
finally {
$(".select2-selection__rendered").hover(function () {
$(this).removeAttr("title");
});

let selectedLanguage = this.lastSelection || prevOption || defaultLanguage;
if (!this.isLanguageKnown(selectedLanguage)) {
if (this.isLanguageKnown(defaultLanguage)) selectedLanguage = defaultLanguage;
else selectedLanguage = [...this.knownLanguages][0];
let selectedLanguage = this.lastSelection || prevOption || defaultLanguage;
if (!this.isLanguageKnown(selectedLanguage)) {
if (this.isLanguageKnown(defaultLanguage)) selectedLanguage = defaultLanguage;
else selectedLanguage = [...this.knownLanguages][0];
}
select.val(selectedLanguage).trigger("change.select2");
}
select.val(selectedLanguage).trigger("change.select2");
}

/**
Expand Down

0 comments on commit d34fc25

Please sign in to comment.