-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fab2a7
commit 9abe3fb
Showing
3 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
37 changes: 35 additions & 2 deletions
37
src/bundle/Resources/public/js/scripts/helpers/middle.ellipsis.js
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,16 +1,49 @@ | ||
(function (global, doc, ibexa) { | ||
const parseAll = () => { | ||
const middleEllipsisContainers = [...doc.querySelectorAll('.ibexa-middle-ellipsis')]; | ||
const resizeEllipsisObserver = new ResizeObserver((entries) => { | ||
entries.forEach((entry) => { | ||
parse(entry.target); | ||
}); | ||
}); | ||
const parse = (baseElement = doc) => { | ||
const isHTMLElement = baseElement instanceof Element || baseElement instanceof Document; | ||
|
||
if (!isHTMLElement) { | ||
console.warn('Provided element does not belong to Document interface'); | ||
|
||
return; | ||
} | ||
|
||
const middleEllipsisContainers = [...baseElement.querySelectorAll('.ibexa-middle-ellipsis')]; | ||
|
||
if (baseElement instanceof Element) { | ||
middleEllipsisContainers.push(baseElement); | ||
} | ||
|
||
middleEllipsisContainers.forEach((middleEllipsisContainer) => { | ||
const partStart = middleEllipsisContainer.querySelector('.ibexa-middle-ellipsis__name--start'); | ||
|
||
middleEllipsisContainer.classList.toggle('ibexa-middle-ellipsis--ellipsized', partStart.scrollWidth > partStart.offsetWidth); | ||
ibexa.helpers.tooltips.parse(middleEllipsisContainer); | ||
|
||
resizeEllipsisObserver.observe(middleEllipsisContainer); | ||
}); | ||
}; | ||
// @deprecated, will be removed in 5.0 | ||
const parseAll = () => parse(doc); | ||
const update = (baseElement, content) => { | ||
const contentElements = [...baseElement.querySelectorAll('.ibexa-middle-ellipsis__name-ellipsized')]; | ||
const contentEscaped = ibexa.helpers.text.escapeHTML(content); | ||
|
||
baseElement.dataset.bsOriginalTitle = contentEscaped; | ||
contentElements.forEach((contentElement) => { | ||
contentElement.innerHTML = contentEscaped; | ||
}); | ||
parse(baseElement); | ||
}; | ||
|
||
ibexa.addConfig('helpers.ellipsis.middle', { | ||
parse, | ||
parseAll, | ||
update, | ||
}); | ||
})(window, window.document, window.ibexa); |
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