DOM manipulation of privatebin.js via appendChild messes with custom template #1781
-
Describe the problem/questionIn line 2999 of privatebin.js version 2.0.3 in setAttachment method: Line 2999 in c0d26b5 This alternates custom templates in an unwanted way (ie text floating next to custom download-attachement button). Would it be possible not alter View of custom templates from the Model-Controller, ie. sparate concerns more in a way that enables full customisation of the View? Did you use the FAQ section?
What you did?
What happensWhen attachment is providede by user, the text and size info of the file will be positioned outside of button What should happenWe shouldnt need to alter privatebin.js to alter behaviour of View. (HTML) Issue reproducibilityYes, I can reproduce it on https://privatebin.net. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
Has been solved like this, but it is a ugly Workaround, I would much prefer seperation of concerns (model/controller and view):
<div id="attachmenttemplate" class="hidden d-inline-block" style="margin-left: 5px;">
<a class="btn btn-secondary d-flex justify-content-center align-items-center gap-1">
<svg width="16" height="16" fill="currentColor" aria-hidden="true"><use href="img/bootstrap-icons.svg#download" /></svg>
<span class="attachment-label">Download attachment</span>
</a>
</div>
// Observe attachment container for changes
const attachmentContainer = document.getElementById('attachment');
if (attachmentContainer) {
const attachmentObserver = new MutationObserver((mutations) => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
// Find the attachment link and file info text
const attachmentLink = node.querySelector('a');
const attachmentLabel = node.querySelector('.attachment-label');
if (attachmentLink && attachmentLabel) {
// Get all text nodes (contains filename and size)
const textNodes = Array.from(node.childNodes).filter(
child => child.nodeType === Node.TEXT_NODE && child.textContent.trim()
);
if (textNodes.length > 0) {
// Extract filename and size from text node
const fileInfoText = textNodes.map(n => n.textContent.trim()).join(' ');
// Update button text with file info
attachmentLabel.textContent = 'Download attachment' + fileInfoText;
// Remove the text nodes
textNodes.forEach(textNode => textNode.remove());
}
}
}
});
});
});
attachmentObserver.observe(attachmentContainer, {
childList: true,
subtree: true
});
} |
Beta Was this translation helpful? Give feedback.
Has been solved like this, but it is a ugly Workaround, I would much prefer seperation of concerns (model/controller and view):
attachmentTemplatebutton element:attachment-label, i.e.: