mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 11:11:04 +01:00
templates bugfix - now supports multiple conditionals of the same variable; added data-favourited button and deprecated reliance on BS3
This commit is contained in:
@@ -241,7 +241,7 @@
|
||||
}
|
||||
|
||||
function makeConditionalRegex(block) {
|
||||
return new RegExp("<!--[\\s]*IF " + block + "[\\s]*-->[\\s\\S]*<!--[\\s]*ENDIF " + block + "[\\s]*-->", 'g');
|
||||
return new RegExp("<!--[\\s]*IF " + block + "[\\s]*-->([\\s\\S]*?)<!--[\\s]*ENDIF " + block + "[\\s]*-->", 'g');
|
||||
}
|
||||
|
||||
function getBlock(regex, block, template) {
|
||||
@@ -311,25 +311,26 @@
|
||||
} else {
|
||||
function checkConditional(key, value) {
|
||||
var conditional = makeConditionalRegex(key),
|
||||
conditionalBlock = conditional.exec(template);
|
||||
|
||||
if (conditionalBlock !== null) {
|
||||
conditionalBlock = conditionalBlock[0].split(/<!-- ELSE -->/);
|
||||
|
||||
if (conditionalBlock[1]) {
|
||||
// there is an else statement
|
||||
if (!value) {
|
||||
template = template.replace(conditional, conditionalBlock[1]);
|
||||
matches = template.match(conditional);
|
||||
|
||||
if (matches !== null) {
|
||||
for (var i = 0, ii = matches.length; i < ii; i++) {
|
||||
var conditionalBlock = matches[i].split(/<!-- ELSE -->/);
|
||||
|
||||
if (conditionalBlock[1]) {
|
||||
// there is an else statement
|
||||
if (!value) {
|
||||
template = template.replace(matches[i], conditionalBlock[1]);
|
||||
} else {
|
||||
template = template.replace(matches[i], conditionalBlock[0]);
|
||||
}
|
||||
} else {
|
||||
template = template.replace(conditional, conditionalBlock[0]);
|
||||
// regular if statement
|
||||
if (!value) {
|
||||
template = template.replace(matches[i], '');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// regular if
|
||||
if (!value) {
|
||||
template = template.replace(conditional, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +342,6 @@
|
||||
checkConditional('@last', blockInfo.iterator === blockInfo.total);
|
||||
}
|
||||
|
||||
|
||||
template = replace(namespace + d, data[d], template);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user