Commit 1533524e authored by Thomas Löffler's avatar Thomas Löffler
Browse files

Finish like with ajax method

parent 1bcfb0be
Pipeline #5745 passed with stages
in 11 minutes and 43 seconds
......@@ -4,12 +4,12 @@
<f:then>
<f:if condition="{hasLiked}">
<f:then>
<button class="btn btn-primary" data-rating-type="dislike" title="Click to dislike">
<button class="btn btn-primary" data-rating-type="dislike" data-rating-extension="{extension.uid}" title="Click to dislike">
<i class="fa fa-heart"></i>&nbsp;<f:format.number decimals="0" thousandsSeparator=".">{extension.likes}</f:format.number>
</button>
</f:then>
<f:else>
<button class="btn btn-primary" data-rating-type="like" title="Click to like">
<button class="btn btn-outline-primary" data-rating-type="like" data-rating-extension="{extension.uid}" title="Click to like">
<i class="fa fa-heart-o"></i>&nbsp;<f:format.number decimals="0" thousandsSeparator=".">{extension.likes}</f:format.number>
</button>
</f:else>
......
......@@ -53,6 +53,47 @@ jQuery(document).ready(function ($) {
}
});
var $ratingButton = $("[data-rating-type]");
if ($ratingButton.length) {
$ratingButton.each(function (index, item) {
if ($(item).data('rating-extension') > 0) {
$(item).click(function () {
let pageType = 0;
let removeClass = '';
let addClass = '';
let likes = $(item).text().trim();
let newRatingType = '';
let ratingType = $(item).data('rating-type');
if (ratingType === 'like') {
pageType = 4500;
removeClass = 'btn-outline-primary';
addClass = 'btn-primary';
likes++;
newRatingType = 'dislike';
}
if (ratingType === 'dislike') {
pageType = 4501;
removeClass = 'btn-primary';
addClass = 'btn-outline-primary';
likes--;
newRatingType = 'like';
}
$.ajax({
url: '/index.php?type=' + pageType,
data: {
"tx_terfe2_rating[extension]": $(item).data("rating-extension")
},
dataType: "json",
success: function (returnData) {
$(item).removeClass(removeClass).addClass(addClass);
$(item).data('rating-type', newRatingType);
item.lastChild.nodeValue = " " + likes;
}
});
})
}
});
}
});
......
......@@ -67,6 +67,3 @@ span.ter-ext-state-expiremental {
}
}
.tx_terfe2_content .navbar {
padding: 0.5rem 1rem;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment