-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the jQuery Tooltip with vanilla Javascript
Add a dom_helper.js to collect a few repetitive functions.
- Loading branch information
1 parent
1bba755
commit 527772d
Showing
3 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* create a HTML element | ||
* @param {string} text | ||
* @returns {HTMLElement} | ||
*/ | ||
export function createHtmlElement(text) { | ||
const element = document.createElement("div") | ||
element.innerHTML = text | ||
return element.firstElementChild | ||
} | ||
|
||
/** | ||
* wrap element with wrappingElement | ||
* @param {HTMLElement} element | ||
* @param {HTMLElement} wrappingElement | ||
*/ | ||
export function wrap(element, wrappingElement) { | ||
element.replaceWith(wrappingElement) | ||
wrappingElement.appendChild(element) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
export default function Tooltips(scope) { | ||
$("[data-alchemy-tooltip]", scope).each(function () { | ||
const $el = $(this) | ||
const text = $el.data("alchemy-tooltip") | ||
$el.wrap('<span class="with-hint"/>') | ||
$el.after('<span class="hint-bubble">' + text + "</span>") | ||
import { createHtmlElement, wrap } from "alchemy_admin/dom_helpers" | ||
|
||
/** | ||
* show tooltips on fixed inputs | ||
* @param {Element|Document} baseElement | ||
* @constructor | ||
*/ | ||
export default function Tooltips(baseElement) { | ||
baseElement.querySelectorAll("[data-alchemy-tooltip]").forEach((element) => { | ||
const text = element.dataset.alchemyTooltip | ||
|
||
wrap(element, createHtmlElement('<div class="with-hint" />')) | ||
element.after(createHtmlElement(`<span class="hint-bubble">${text}</span>`)) | ||
}) | ||
} |