feature: removes redundant comments

This commit is contained in:
ievgenii vdovenko 2026-01-06 17:57:39 +01:00
parent e0b2043c71
commit 8123a42f8a

View file

@ -3,12 +3,11 @@ const MIN_LIMIT = 5;
const ELLIPSIS = "...";
const FILL = 0.90; // use 90% of available width
// Cache average char width per font+letterSpacing
const avgCharWidthCache = new Map();
function toChars(s) {
return Array.from(s);
} // unicode-safe
}
function truncateMiddle(str, maxLen) {
maxLen = parseInt(maxLen, 10);
@ -19,7 +18,7 @@ function truncateMiddle(str, maxLen) {
const chars = toChars(full);
if (chars.length <= maxLen) return full;
const keep = maxLen - ELLIPSIS.length; // remaining visible chars besides "..."
const keep = maxLen - ELLIPSIS.length;
const left = Math.ceil(keep / 2);
const right = Math.floor(keep / 2);
@ -51,7 +50,6 @@ function ensureTextSpan($a) {
function getAvgCharWidthPx(el) {
const cs = window.getComputedStyle(el);
// Include letter-spacing because it affects width
const key = [
cs.fontStyle, cs.fontVariant, cs.fontWeight,
cs.fontSize, cs.fontFamily, cs.letterSpacing
@ -87,7 +85,6 @@ function getAvgCharWidthPx(el) {
return avg;
}
// Auto maxLen from width (px) → chars, using 90% available width
function autoMaxLenForAnchor($a) {
const aEl = $a[0];
const $truncate = $a.closest(".truncate");
@ -96,7 +93,6 @@ function autoMaxLenForAnchor($a) {
const containerW = containerEl.getBoundingClientRect().width;
if (!containerW) return null;
// Subtract widths of non-text children (icons etc.), exclude our span
let nonTextW = 0;
$a.children().not("span.js-midcut").each(function () {
nonTextW += $(this).outerWidth(true) || 0;
@ -112,7 +108,6 @@ function autoMaxLenForAnchor($a) {
return Math.max(MIN_LIMIT, est);
}
// limitOverride: optional manual max length for all elements in this call
function applyMiddleCut(selector, limitOverride) {
$(selector).each(function () {
const $el = $(this);
@ -122,15 +117,10 @@ function applyMiddleCut(selector, limitOverride) {
const full = $span.attr("data-full") || $span.text();
// 1) per-element override (if you can add attributes)
// <div class="truncate" data-maxlen="20"> OR <a data-maxlen="20">
const perEl =
$el.closest(".truncate").attr("data-maxlen") ||
$el.attr("data-maxlen");
// 2) manual override passed to function
// 3) auto-detected from width
// 4) fallback default
const autoLen = autoMaxLenForAnchor($el);
const limit = perEl || limitOverride || autoLen || DEFAULT_LIMIT;