mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-30 09:22:24 +00:00
Merge pull request #2737 from PR0M3TH3AN/refactor-delete-modal-truncate-middle-16500239099294325231
🧹 Refactor: Remove duplicated string truncation logic in DeleteModal.js
This commit is contained in:
1 file changed
+2
-16
@@ -1,3 +1,4 @@
|
||||
import { truncateMiddle as defaultTruncateMiddle } from "../../utils/formatters.js";
|
||||
import { createModalAccessibility } from "./modalAccessibility.js";
|
||||
|
||||
function extractDTagValue(tags) {
|
||||
@@ -28,22 +29,7 @@ export class DeleteModal {
|
||||
this.setGlobalModalState =
|
||||
typeof setGlobalModalState === "function" ? setGlobalModalState : () => {};
|
||||
this.truncateMiddle =
|
||||
typeof truncateMiddle === "function" ? truncateMiddle : (value, maxLength = 48) => {
|
||||
if (typeof value !== "string") {
|
||||
return "";
|
||||
}
|
||||
if (value.length <= maxLength) {
|
||||
return value;
|
||||
}
|
||||
if (maxLength <= 1) {
|
||||
return value.slice(0, maxLength);
|
||||
}
|
||||
const ellipsis = "…";
|
||||
const charsToShow = maxLength - ellipsis.length;
|
||||
const front = Math.ceil(charsToShow / 2);
|
||||
const back = Math.floor(charsToShow / 2);
|
||||
return `${value.slice(0, front)}${ellipsis}${value.slice(value.length - back)}`;
|
||||
};
|
||||
typeof truncateMiddle === "function" ? truncateMiddle : defaultTruncateMiddle;
|
||||
this.eventTarget = eventTarget instanceof EventTarget ? eventTarget : new EventTarget();
|
||||
this.container = container || document.getElementById("modalContainer") || null;
|
||||
|
||||
|
||||
Reference in new issue
Block a user