ellipsis.js 904 B

1234567891011121314151617181920212223242526
  1. function parentId(name) {
  2. return "parent-" + name;
  3. }
  4. function isEllipsed(name) {
  5. const child = document.getElementById(name);
  6. const parent = document.getElementById(parentId(name));
  7. const emptyData = parent.getAttribute("data-content") === "";
  8. const hasOverflow = child.clientWidth < child.scrollWidth;
  9. if (hasOverflow) {
  10. if (emptyData) {
  11. parent.setAttribute("data-content", name);
  12. }
  13. } else {
  14. if (!emptyData) {
  15. parent.setAttribute("data-content", "");
  16. }
  17. }
  18. }
  19. function ellipsedLabel ({ name, parentClass = "", childClass = "" }) {
  20. const child = "<span onmouseover='isEllipsed(\"" + name + "\")' id='" + name + "' class='ellipsed-name " + childClass + "'>" + name + "</span>";
  21. return "<span class='" + parentClass + "' id='" + parentId(name) + "' data-toggle='popover' data-placement='right' data-container='body' data-content=''>" + child + "</span>";
  22. }