Skip to content

Commit

Permalink
Pass Awesomplete instance back out of setup method
Browse files Browse the repository at this point in the history
This restores the prior behavior in index.js of storing the
Awesomplete instance on Index.awesomeplete. That reference wasn't
ever used AFAICT, but it might as well stay.
  • Loading branch information
alethiophile committed Aug 15, 2024
1 parent 6e4fb30 commit be7887f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions public/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ LRR.getTagSearchURL = function (namespace, tag) {
};

/**
* Load tag suggestions for the tag search bar.
* Load tag suggestions for the tag search bar. input_tag is the
* selector to pass to the Awesomeplete constructor. instance_cb, if
* provided, will be invoked after construction with the Awesomeplete
* instance as argument.
*/
LRR.setupTagSearchAutocomplete = function (input_tag) {
LRR.setupTagSearchAutocomplete = function (input_tag, instance_cb) {
// Query the tag cloud API to get the most used tags.
Server.callAPI("/api/database/stats?minweight=2", "GET", null, "Couldn't load tag suggestions",
(data) => {
Expand All @@ -75,8 +78,7 @@ LRR.setupTagSearchAutocomplete = function (input_tag) {
});

// Setup awesomplete for the tag search bar
// Index.awesomplete =
new Awesomplete(input_tag, {
let inst = new Awesomplete(input_tag, {
list: data,
data(tag) {
// Format tag objects from the API into a format awesomplete likes.
Expand All @@ -100,6 +102,10 @@ LRR.setupTagSearchAutocomplete = function (input_tag) {
this.input.value = `${before + text}$, `;
},
});

if (instance_cb) {
instance_cb(inst);
}
},
);
};
Expand Down
3 changes: 2 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
const Index = {};
Index.selectedCategory = "";
Index.awesomplete = {};
Index.carouselInitialized = false;
Index.swiper = {};
Index.serverVersion = "";
Expand Down Expand Up @@ -114,7 +115,7 @@ Index.initializeAll = function () {
}

Index.migrateProgress();
LRR.setupTagSearchAutocomplete('#search-input');
LRR.setupTagSearchAutocomplete('#search-input', (inst) => { Index.awesomplete = inst; });
Index.loadCategories();

// Initialize DataTables
Expand Down

0 comments on commit be7887f

Please sign in to comment.