mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 07:55:46 +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:
@@ -291,8 +291,7 @@ define(function() {
|
|||||||
var pid = $(this).parents('li').attr('data-pid');
|
var pid = $(this).parents('li').attr('data-pid');
|
||||||
var uid = $(this).parents('li').attr('data-uid');
|
var uid = $(this).parents('li').attr('data-uid');
|
||||||
|
|
||||||
var element = $(this).find('i');
|
if ($(this).attr('data-favourited') == 'false') {
|
||||||
if ($(element).hasClass('fa-star-o')) {
|
|
||||||
socket.emit('api:posts.favourite', {
|
socket.emit('api:posts.favourite', {
|
||||||
pid: pid,
|
pid: pid,
|
||||||
room_id: app.currentRoom
|
room_id: app.currentRoom
|
||||||
@@ -542,7 +541,9 @@ define(function() {
|
|||||||
var favEl = document.querySelector('.post_rep_' + data.pid).nextSibling;
|
var favEl = document.querySelector('.post_rep_' + data.pid).nextSibling;
|
||||||
if (favEl) {
|
if (favEl) {
|
||||||
favEl.className = 'fa fa-star';
|
favEl.className = 'fa fa-star';
|
||||||
$(favEl).parent().addClass('btn-warning');
|
$(favEl).parent()
|
||||||
|
.addClass('btn-warning')
|
||||||
|
.attr('data-favourited', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -552,7 +553,9 @@ define(function() {
|
|||||||
var favEl = document.querySelector('.post_rep_' + data.pid).nextSibling;
|
var favEl = document.querySelector('.post_rep_' + data.pid).nextSibling;
|
||||||
if (favEl) {
|
if (favEl) {
|
||||||
favEl.className = 'fa fa-star-o';
|
favEl.className = 'fa fa-star-o';
|
||||||
$(favEl).parent().removeClass('btn-warning');
|
$(favEl).parent()
|
||||||
|
.removeClass('btn-warning')
|
||||||
|
.attr('data-favourited', false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -241,7 +241,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function makeConditionalRegex(block) {
|
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) {
|
function getBlock(regex, block, template) {
|
||||||
@@ -311,23 +311,24 @@
|
|||||||
} else {
|
} else {
|
||||||
function checkConditional(key, value) {
|
function checkConditional(key, value) {
|
||||||
var conditional = makeConditionalRegex(key),
|
var conditional = makeConditionalRegex(key),
|
||||||
conditionalBlock = conditional.exec(template);
|
matches = template.match(conditional);
|
||||||
|
|
||||||
if (conditionalBlock !== null) {
|
if (matches !== null) {
|
||||||
conditionalBlock = conditionalBlock[0].split(/<!-- ELSE -->/);
|
for (var i = 0, ii = matches.length; i < ii; i++) {
|
||||||
|
var conditionalBlock = matches[i].split(/<!-- ELSE -->/);
|
||||||
|
|
||||||
if (conditionalBlock[1]) {
|
if (conditionalBlock[1]) {
|
||||||
// there is an else statement
|
// there is an else statement
|
||||||
if (!value) {
|
if (!value) {
|
||||||
template = template.replace(conditional, conditionalBlock[1]);
|
template = template.replace(matches[i], conditionalBlock[1]);
|
||||||
} else {
|
} else {
|
||||||
template = template.replace(conditional, conditionalBlock[0]);
|
template = template.replace(matches[i], conditionalBlock[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// regular if
|
// regular if statement
|
||||||
if (!value) {
|
if (!value) {
|
||||||
template = template.replace(conditional, '');
|
template = template.replace(matches[i], '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,7 +342,6 @@
|
|||||||
checkConditional('@last', blockInfo.iterator === blockInfo.total);
|
checkConditional('@last', blockInfo.iterator === blockInfo.total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template = replace(namespace + d, data[d], template);
|
template = replace(namespace + d, data[d], template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,12 +66,9 @@
|
|||||||
|
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button class="btn btn-sm btn-default follow main-post" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button>
|
<button class="btn btn-sm btn-default follow main-post" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button>
|
||||||
<button class="favourite btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
|
<button data-favourited="{posts.favourited}" class="favourite btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
|
||||||
<span class="favourite-text">[[topic:favourite]]</span>
|
<span class="favourite-text">[[topic:favourite]]</span>
|
||||||
<span class="post_rep_{posts.pid}">{posts.reputation} </span>
|
<span class="post_rep_{posts.pid}">{posts.reputation} </span>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- IF posts.favourited -->
|
<!-- IF posts.favourited -->
|
||||||
<i class="fa fa-star"></i>
|
<i class="fa fa-star"></i>
|
||||||
<!-- ELSE -->
|
<!-- ELSE -->
|
||||||
|
|||||||
Reference in New Issue
Block a user