Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 21 additions & 28 deletions src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { debounce } from "../../modules/utility.js"
import { debounce, registerBootstrapBlazorModule } from "../../modules/utility.js"
import { handleKeyUp, select, selectAllByFocus, selectAllByEnter } from "../Input/BootstrapInput.razor.js"
import Data from "../../modules/data.js"
import EventHandler from "../../modules/event-handler.js"
import Input from "../../modules/input.js"
import Popover from "../../modules/base-popover.js"

if (window.BootstrapBlazor === void 0) {
window.BootstrapBlazor = {};
}

export function init(id, invoke) {
const el = document.getElementById(id)
const menu = el.querySelector('.dropdown-menu')
Expand Down Expand Up @@ -76,32 +72,29 @@ export function init(id, invoke) {
filterCallback(v);
});

if (window.BootstrapBlazor.AutoComplete === void 0) {
window.BootstrapBlazor.AutoComplete = {
hooked: false,
registerCloseDropdownHandler: function () {
if (this.hooked === false) {
this.hooked = true;

EventHandler.on(document, 'click', e => {
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
const ac = e.target.closest('.auto-complete');
if (ac === a) {
return;
}

const el = a.querySelector('[data-bs-toggle="bb.dropdown"]');
if (el === null) {
a.classList.remove('show');
}
});
const module = registerBootstrapBlazorModule('AutoComplete', {
hooked: false,
registerCloseDropdownHandler: function () {
if (this.hooked === false) {
this.hooked = true;

EventHandler.on(document, 'click', e => {
[...document.querySelectorAll('.auto-complete.show')].forEach(a => {
const ac = e.target.closest('.auto-complete');
if (ac === a) {
return;
}

const el = a.querySelector('[data-bs-toggle="bb.dropdown"]');
if (el === null) {
a.classList.remove('show');
}
});
}
});
}
}
}

window.BootstrapBlazor.AutoComplete.registerCloseDropdownHandler();
});
module.registerCloseDropdownHandler();
}

const handlerKeyup = (ac, e) => {
Expand Down
47 changes: 26 additions & 21 deletions src/BootstrapBlazor/wwwroot/modules/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,28 +571,23 @@ const hackPopover = (popover, css) => {
}

const hackTooltip = function () {
window.BootstrapBlazor ??= {};

if (window.BootstrapBlazor.Tooltip === void 0) {
window.BootstrapBlazor.Tooltip = {
hooked: false,
hackDispose: function () {
if (this.hooked === false) {
this.hooked = true;

const originalDispose = bootstrap.Tooltip.prototype.dispose;
bootstrap.Tooltip.prototype.dispose = function () {
originalDispose.call(this);
// fix https://github.com/twbs/bootstrap/issues/37474
this._activeTrigger = {};
this._element = document.createElement('noscript'); // placeholder with no behavior
}
const tooltip = registerBootstrapBlazorModule('Tooltip', {
hooked: false,
hackDispose: function () {
if (this.hooked === false) {
this.hooked = true;

const originalDispose = bootstrap.Tooltip.prototype.dispose;
bootstrap.Tooltip.prototype.dispose = function () {
originalDispose.call(this);
// fix https://github.com/twbs/bootstrap/issues/37474
this._activeTrigger = {};
this._element = document.createElement('noscript'); // placeholder with no behavior
}
}
}
}

window.BootstrapBlazor.Tooltip.hackDispose();
});
tooltip.hackDispose();
}

const setIndeterminate = (object, state) => {
Expand Down Expand Up @@ -802,20 +797,30 @@ export function switchTheme(theme, x = 0, y = 0, sync = true) {
}
}

const deepMerge = (obj1, obj2) => {
for (let key in obj2) {
const deepMerge = (obj1, obj2, skipNull = true) => {
for (const key in obj2) {
if (obj2.hasOwnProperty(key)) {
if (obj2[key] instanceof Object && obj1[key] instanceof Object) {
obj1[key] = deepMerge(obj1[key], obj2[key]);
}
else {
const value = obj2[key];
if (skipNull && value === null) {
continue;
}
obj1[key] = obj2[key];
}
}
}
return obj1;
}

export function registerBootstrapBlazorModule(name, module) {
window.BootstrapBlazor ??= {};
window.BootstrapBlazor[name] ??= deepMerge(window.BootstrapBlazor[name] ?? {}, module);
return window.BootstrapBlazor[name];
}

export function setTitle(title) {
document.title = title;
}
Expand Down