Skip to content
Open
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
10 changes: 9 additions & 1 deletion src/bundle/Resources/public/js/scripts/helpers/text.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ const escapeHTMLAttribute = (str: unknown): string => {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
};

export { escapeHTML, escapeHTMLAttribute };
const stripHTML = (str: string): string => {
const divNode = doc.createElement('div');

divNode.innerHTML = str;

return divNode.textContent ?? '';
};

export { escapeHTML, escapeHTMLAttribute, stripHTML };
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isSafari } from './browser.helper';
import { getBootstrap } from './context.helper';
import { stripHTML } from './text.helper';

const { document: doc } = window;

Expand Down Expand Up @@ -118,7 +119,7 @@ const getTextHeight = (text, styles) => {
return texHeight;
};
const isTitleEllipsized = (node) => {
const title = node.dataset.originalTitle;
const title = stripHTML(node.dataset.originalTitle);
const { width: nodeWidth, height: nodeHeight } = node.getBoundingClientRect();
const computedNodeStyles = getComputedStyle(node);
const styles = {
Expand Down Expand Up @@ -226,6 +227,7 @@ const parse = (baseElement = doc) => {
if (hasNewTitle) {
tooltipNode.dataset.originalTitle = tooltipNode.title;
}

const tooltipInstance = bootstrap.Tooltip.getInstance(tooltipNode);
const hasTooltip = !!tooltipInstance;

Expand Down
Loading