Skip to content

Commit

Permalink
[BSv5] Adjusted offline search popover
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Feb 16, 2023
1 parent 2f29796 commit b8646f9
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions assets/js/offline-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
$(document).ready(function () {
const $searchInput = $('.td-search input');

//
// Options for popover
//

$searchInput.data('html', true);
$searchInput.data('placement', 'bottom');
$searchInput.data(
'template',
'<div class="td-offline-search-results popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>'
);

//
// Register handler
//
Expand Down Expand Up @@ -71,8 +60,18 @@
);

const render = ($targetSearchInput) => {
// Dispose the previous result
$targetSearchInput.popover('dispose');
//
// Dispose existing popover
//

{
let popover = bootstrap.Popover.getInstance(
$targetSearchInput[0]
);
if (popover !== null) {
popover.dispose();
}
}

//
// Search
Expand Down Expand Up @@ -130,8 +129,9 @@
.css({ fontWeight: 'bold' })
)
.append(
$('<span>')
.addClass('td-offline-search-results__close-button')
$('<span>').addClass(
'td-offline-search-results__close-button'
)
)
);

Expand Down Expand Up @@ -178,16 +178,23 @@
});
}

$targetSearchInput.on('shown.bs.popover', () => {
$('.td-offline-search-results__close-button').on('click', () => {
$targetSearchInput.val('');
$targetSearchInput.trigger('change');
});
$targetSearchInput.one('shown.bs.popover', () => {
$('.td-offline-search-results__close-button').on(
'click',
() => {
$targetSearchInput.val('');
$targetSearchInput.trigger('change');
}
);
});

$targetSearchInput
.data('content', $html[0])
.popover('show');
const popover = new bootstrap.Popover($targetSearchInput, {
content: $html[0],
html: true,
customClass: 'td-offline-search-results',
placement: 'bottom',
});
popover.show();
};
});
})(jQuery);

0 comments on commit b8646f9

Please sign in to comment.