From 4972433406863da21c85b68385de5cc27e8d4ac6 Mon Sep 17 00:00:00 2001 From: Ivan Pantic Date: Sat, 16 Jul 2016 04:35:54 +0200 Subject: [PATCH] Vote levels features (custom classes based on the comment votes) --- isso/js/app/config.js | 3 ++- isso/js/app/isso.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/isso/js/app/config.js b/isso/js/app/config.js index 35bf051..f38dcc7 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -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"); diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 3e09003..e40c351 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -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); }