Skip to content
Merged
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
40 changes: 26 additions & 14 deletions src/pat/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import $ from "jquery";
import Base from "../../core/base";
import logging from "../../core/logging";
import Parser from "../../core/parser";
import events from "../../core/events";
import registry from "../../core/registry";
import utils from "../../core/utils";

Expand Down Expand Up @@ -80,10 +81,15 @@ export default Base.extend({

if (this.options.trigger === "click" && this.options.source === "ajax") {
// prevent default action for "click" and "mouseenter click"
el.addEventListener("click", (event) => {
event.preventDefault();
event.stopPropagation();
});
events.add_event_listener(
el,
"click",
"pat-tooltip--click-prevent-default",
(event) => {
event.preventDefault();
event.stopPropagation();
}
);
}

if (this.options.trigger === "click") {
Expand Down Expand Up @@ -236,26 +242,31 @@ export default Base.extend({
".pat-tooltip--close-button"
);
for (let close_el of close_els) {
close_el.addEventListener("click", async () => {
await utils.timeout(1); // wait a tick for event being processed by other handlers.
for (let close_button of close_buttons) {
// Also remove the close button
close_button.parentNode.removeChild(close_button);
events.add_event_listener(
close_el,
"click",
"pat-tooltip--close-tooltip",
async () => {
await utils.timeout(1); // wait a tick for event being processed by other handlers.
for (let close_button of close_buttons) {
// Also remove the close button
close_button.parentNode.removeChild(close_button);
}
this.tippy.hide();
}
this.tippy.hide();
});
);
}
// Initialize any other patterns.
registry.scan(this.tippy.popper);
},

async _onMount() {
if (this.options.source === "ajax") {
await this.get_content();
await this.get_content(); // + _initializeContent
} else {
this._initializeContent();
}

this._initializeContent();

// Notify parent patterns about injected content.
// Do not call pat-inject's handler, because all necessary
// initialization after injection is done here.
Expand Down Expand Up @@ -338,6 +349,7 @@ export default Base.extend({
this.tippy.setContent(content);
await utils.timeout(1); // Wait a tick before forceUpdate. Might fail due to unset popperInstance.
this.tippy.popperInstance.forceUpdate(); // re-position tippy after content is known.
this._initializeContent();
}
},

Expand Down