Vote levels features (custom classes based on the comment votes)

This commit is contained in:
Ivan Pantic 2016-07-16 04:35:54 +02:00
parent b0f8606b0f
commit 4972433406
2 changed files with 20 additions and 2 deletions

View File

@ -13,7 +13,8 @@ define(function() {
"avatar-bg": "#f0f0f0",
"avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6",
"#be5168", "#f19670", "#e4bf80", "#447c69"].join(" "),
"vote": true
"vote": true,
"vote-levels": null
};
var js = document.getElementsByTagName("script");

View File

@ -165,6 +165,12 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
);
if (config.vote) {
var voteLevels = config['vote-levels'];
if (typeof voteLevels === 'string') {
// Eg. -5,5,15
voteLevels = voteLevels.split(',');
}
// update vote counter
var votes = function (value) {
var span = $("span.votes", footer);
@ -178,6 +184,17 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
} else {
el.classList.add('isso-no-votes');
}
if (voteLevels) {
var before = true;
for (var index = 0; index <= voteLevels.length; index++) {
if (before && (index >= voteLevels.length || value < voteLevels[index])) {
el.classList.add('isso-vote-level-' + index);
before = false;
} else {
el.classList.remove('isso-vote-level-' + index);
}
}
}
};
$("a.upvote", footer).on("click", function () {
@ -191,7 +208,7 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
votes(rv.likes - rv.dislikes);
});
});
votes(comment.likes - comment.dislikes);
}