templates bugfix - now supports multiple conditionals of the same variable; added data-favourited button and deprecated reliance on BS3

This commit is contained in:
psychobunny
2013-11-28 17:14:04 -05:00
parent 168052bf45
commit 48e36e3c31
3 changed files with 27 additions and 27 deletions

View File

@@ -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);
}
}