Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Gabrielsson committed Jun 6, 2024
1 parent 8373cdb commit 251c4e2
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions nightly/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -1679,13 +1679,28 @@ var app = {
// Create a regular expression using the escaped variable pattern.
var variableRegex = new RegExp('{' + escapedVariable + '(?::([^}]+))?}', 'g')

// Replace all occurrences of {variable} with the replacement value.
var originalContent = object.innerHTML
var modifiedContent = originalContent.replace(variableRegex, replaceValue === 0 ? '0' : replaceValue || '$1' || '')
// Create a stack for elements to process
var elementsToProcess = [object]

// Process elements in the stack
while (elementsToProcess.length > 0) {
var element = elementsToProcess.pop()

// If the element is an Element node, add its children to the stack
if (element.nodeType === 1) {
var childNodes = element.childNodes;
for (var i = childNodes.length - 1; i >= 0; i--) {
elementsToProcess.push(childNodes[i])
}
// If the element is a Text node, replace the variable pattern
} else if (element.nodeType === 3) {
var originalContent = element.nodeValue
var modifiedContent = originalContent.replace(variableRegex, replaceValue === 0 ? '0' : replaceValue || '$1' || '')

// Update element content only if there were replacements.
if (originalContent !== modifiedContent) {
object.innerHTML = modifiedContent
if (originalContent !== modifiedContent) {
element.nodeValue = modifiedContent
}
}
}
}
},
Expand Down

0 comments on commit 251c4e2

Please sign in to comment.