diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index f44a327760..f805a4a510 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -291,8 +291,7 @@ define(function() { var pid = $(this).parents('li').attr('data-pid'); var uid = $(this).parents('li').attr('data-uid'); - var element = $(this).find('i'); - if ($(element).hasClass('fa-star-o')) { + if ($(this).attr('data-favourited') == 'false') { socket.emit('api:posts.favourite', { pid: pid, room_id: app.currentRoom @@ -542,7 +541,9 @@ define(function() { var favEl = document.querySelector('.post_rep_' + data.pid).nextSibling; if (favEl) { 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; if (favEl) { favEl.className = 'fa fa-star-o'; - $(favEl).parent().removeClass('btn-warning'); + $(favEl).parent() + .removeClass('btn-warning') + .attr('data-favourited', false); } } }); diff --git a/public/src/templates.js b/public/src/templates.js index d933a7db74..9dda5d3847 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -241,7 +241,7 @@ } function makeConditionalRegex(block) { - return new RegExp("[\\s\\S]*", 'g'); + return new RegExp("([\\s\\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(//); - - 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(//); + + 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); } } diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl index d4e0c41bb8..2e2c09228f 100644 --- a/public/templates/topic.tpl +++ b/public/templates/topic.tpl @@ -66,12 +66,9 @@