[HELP] Improve the reputation system so it counts votes Hitskin_logo Hitskin.com

This is a Hitskin.com skin preview
Install the skinReturn to the skin page

The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.
5 posters

    [HELP] Improve the reputation system so it counts votes

    omarpop23
    omarpop23
    Forumember


    Male Posts : 182
    Reputation : 3
    Language : Arabic
    Location : Egypt

    Solved [HELP] Improve the reputation system so it counts votes

    Post by omarpop23 29/6/2017, 08:59

    i couldn't install this JS code in my forum
    Improve the reputation system so it counts votes

    Note: i have edit on Template
    Code:
    viewtopic_bodyody

    Topic link for inspecting: http://tt22.forumarabia.com/t20-topic#74

    @Ange Tuteur


    Last edited by omarpop23 on 3/7/2017, 17:27; edited 1 time in total
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51503
    Reputation : 3519
    Language : English
    Location : United States

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by SLGray 29/6/2017, 21:23

    What is your forum version?



    [HELP] Improve the reputation system so it counts votes Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    omarpop23
    omarpop23
    Forumember


    Male Posts : 182
    Reputation : 3
    Language : Arabic
    Location : Egypt

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by omarpop23 30/6/2017, 10:06

    ModernBB Last one
    Ape
    Ape
    Administrator
    Administrator


    Male Posts : 19147
    Reputation : 1994
    Language : fluent in dork / mumbojumbo & English haha

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by Ape 30/6/2017, 12:13

    Yes i have just tested this on my test forum and i see it fine but i can not press the vote up or down button.
    [HELP] Improve the reputation system so it counts votes Captur11
    as you can see in the screen shot.

    The problem is this code was made way before this new forum system come out so it may not work right on it we will have to ask @Ange Tuteur to see whats going on when he has time.



    [HELP] Improve the reputation system so it counts votes Left1212[HELP] Improve the reputation system so it counts votes Center11[HELP] Improve the reputation system so it counts votes Right112
    [HELP] Improve the reputation system so it counts votes Ape_b110
    [HELP] Improve the reputation system so it counts votes Ape1010
    omarpop23
    omarpop23
    Forumember


    Male Posts : 182
    Reputation : 3
    Language : Arabic
    Location : Egypt

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by omarpop23 30/6/2017, 22:15

    i'm waiting him Very Happy
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13246
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by Ange Tuteur 30/6/2017, 22:27

    Hi,

    Give the following script a try for ModernBB.
    Code:
    $(function() {
      // General Configuration of the plugin
      var config = {
        position_left : true, // true for left || false for right
        negative_vote : true, // true for negative votes || false for positive only
        vote_bar : true, // display a small bar under the vote buttons
     
        // button config
        icon_plus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/plus10.png" alt="+"/>',
        icon_minus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/minus10.png" alt="-"/>',
     
        // language config
        title_plus : 'Like %{USERNAME}\'s post',
        title_minus : 'Dislike %{USERNAME}\'s post',
     
        title_like_singular : '%{VOTES} person likes %{USERNAME}\'s post',
        title_like_plural : '%{VOTES} people like %{USERNAME}\'s post',
     
        title_dislike_singular : '%{VOTES} person dislikes %{USERNAME}\'s post',
        title_dislike_plural : '%{VOTES} people dislike %{USERNAME}\'s post',
     
        title_vote_bar : '%{VOTES} people liked %{USERNAME}\'s post %{PERCENT}'
      },
       
       
      // function bound to the onclick handler of the vote buttons
      submit_vote = function() {
        var next = this.nextSibling, // the counter next to the vote button that was clicked
            box = this.parentNode,
            bar = box.getElementsByTagName('DIV'),
            vote = box.getElementsByTagName('A'),
            mode = /eval=plus/.test(this.href) ? 1 : 0,
            i = 0, j = vote.length, pos, neg, percent;
     
        // submit the vote asynchronously
        $.get(this.href, function() {
          next.innerHTML = +next.innerHTML + 1; // add to the vote count
          next.title = next.title.replace(/(\d+)/, function(M, $1) { return +$1 + 1 });
       
          pos = +vote[0].nextSibling.innerHTML;
          neg = vote[1] ? +vote[1].nextSibling.innerHTML : 0;
          percent = pos == 0 ? '0%' : pos == neg ? '50%' : Math.round(pos / (pos + neg) * 100) + '%';
       
          if (bar[0]) {
            bar[0].style.display = '';
            bar[0].firstChild.style.width = percent;
            box.title = box.title.replace(/\d+\/\d+/, pos + '/' + ( pos + neg )).replace(/\(\d+%\)/, '(' + percent + ')');
          }
        });
     
        // revoke voting capabilities on the post once the vote is cast
        for (; i < j; i++) {
          vote[i].href = '#';
          vote[i].className = vote[i].className.replace(/fa_vote/, 'fa_voted');
          vote[i].onclick = function() { return false };
        }
     
        return false;
      },
       
      vote = $('.vote'), i = 0, j = vote.length,
      version = 0, // version check
     
      // version data so we don't have to redefine these arrays during the loop
      vdata = {
        tag : ['LI'][version],
        name : ['.postprofile-name'][version],
        actions : ['.profile-icons'][version],
      },
     
      post, plus, minus, n_pos, n_neg, title_pos, title_neg, li, ul, bar, button, total, percent, span, pseudo, vote_bar; // startup variables for later use in the loop
     
      for (; i < j; i++) {
        post = $(vote[i]).closest('.post')[0];
        bar = $('.vote-bar', vote[i])[0]; // vote bar
        button = $('a[class^="ion-thumb"]', vote[i]); // plus and minus buttons
        pseudo = $(vdata.name, post).text() || 'MISSING_STRING'; // username of the poster
        ul = $(vdata.actions, post)[0]; // post actions
        li = document.createElement(vdata.tag); // vote system container
        li.className = 'fa_reputation';
     
        if (li.tagName == 'SPAN') li.style.display = 'inline-block';
     
        // calculate votes
        if (bar) {
          total = +bar.title.replace(/.*?\((\d+).*/, '$1');
          percent = +bar.title.replace(/.*?(\d+)%.*/, '$1');
       
          n_pos = Math.round(total * (percent / 100));
          n_neg = total - n_pos;
        } else {
          n_pos = 0;
          n_neg = 0;
        }
     
        // set up negative and positive titles with the correct grammar, votes, and usernames
        title_pos = (n_pos == 1 ? config.title_like_singular : config.title_like_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_pos);
        title_neg = (n_neg == 1 ? config.title_dislike_singular : config.title_dislike_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_neg);
     
        // define the vote counts
        li.innerHTML = '<span class="fa_count fa_positive" title="' + title_pos + '">' + n_pos + '</span>' + (config.negative_vote ? '&nbsp;<span class="fa_count fa_negative" title="' + title_neg + '">' + n_neg + '</span>' : '');
        span = li.getElementsByTagName('SPAN'); // get the vote count containers for use as insertion points
     
        // create positive vote button
        plus = document.createElement('A');
        plus.href = button[0] ? button[0].href : '#';
        plus.onclick = button[0] ? submit_vote : function() { return false };
        plus.className = 'fa_vote' + (button[0] ? '' : 'd') + ' fa_plus';
        plus.innerHTML = config.icon_plus;
        plus.title = (button[0] ? config.title_plus : title_pos).replace(/%\{USERNAME\}/g, pseudo);
     
        span[0] && li.insertBefore(plus, span[0]);
     
        // create negative vote button
        if (config.negative_vote) {
          minus = document.createElement('A');
          minus.href = button[1] ? button[1].href : '#';
          minus.onclick = button[1] ? submit_vote : function() { return false };
          minus.className = 'fa_vote' + (button[1] ? '' : 'd') + ' fa_minus';
          minus.innerHTML = config.icon_minus;
          minus.title = (button[1] ? config.title_minus : title_neg).replace(/%\{USERNAME\}/g, pseudo);
       
          span[1] && li.insertBefore(minus, span[1]);
        }
     
        // create vote bar
        if (config.vote_bar) {
          vote_bar = document.createElement('DIV');
          vote_bar.className = 'fa_votebar';
          vote_bar.innerHTML = '<div class="fa_votebar_inner" style="width:' + percent + '%;"></div>';
          vote_bar.style.display = bar ? '' : 'none';
          li.title = config.title_vote_bar.replace(/%\{USERNAME\}/, pseudo).replace(/%\{VOTES\}/, n_pos + '/' + (n_pos + n_neg)).replace(/%\{PERCENT\}/, '(' + percent + '%)');
          li.appendChild(vote_bar);
        }
     
        // finally insert the vote system and remove the default one
        config.position_left ? ul.insertBefore(li, ul.firstChild) : ul.appendChild(li);
        vote[i].parentNode.removeChild(vote[i]);
      }
    });

    $('head').append('<style type="text/css">li.fa_reputation > * {float:none;}.fa_count,.fa_voted{cursor:default}.fa_count,.fa_vote,.fa_voted{font-size:12px;font-family:Verdana,Arial,Helvetica,Sans-serif;display:inline-block!important;width:auto!important;transition:.3s}.fa_vote:hover,.fa_voted{opacity:.4}.fa_count{font-weight:700;margin:0 3px}.fa_positive{color:#4A0}.fa_negative{color:#A44}.fa_votebar,.fa_votebar_inner{background:#C44;height:3px}.fa_votebar_inner{background:#4A0;transition:.3s}</style>');
    SLGray
    SLGray
    Administrator
    Administrator


    Male Posts : 51503
    Reputation : 3519
    Language : English
    Location : United States

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by SLGray 30/6/2017, 22:39

    If you are using ModernBB, it counts the vote already.



    [HELP] Improve the reputation system so it counts votes Slgray10

    When your topic has been solved, ensure you mark the topic solved.
    Never post your email in public.
    omarpop23
    omarpop23
    Forumember


    Male Posts : 182
    Reputation : 3
    Language : Arabic
    Location : Egypt

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by omarpop23 30/6/2017, 22:50

    [HELP] Improve the reputation system so it counts votes Untitl10
    it's work but i buttons are unclickable
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13246
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by Ange Tuteur 1/7/2017, 21:17

    Hi again,

    Without a test account (guests cannot see message actions, and this issue concerns that) or the modified template, I cannot help you with the issue further ; I need to inspect the markup of your template to make modifications for it specifically. If you can provide either one of these I'll be glad to look into your issue further.

    Have a good weekend and see you soon.
    omarpop23
    omarpop23
    Forumember


    Male Posts : 182
    Reputation : 3
    Language : Arabic
    Location : Egypt

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by omarpop23 3/7/2017, 05:28

    hi @Ange Tuteur , please check inbox
    i sent you user name and password
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13246
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by Ange Tuteur 3/7/2017, 16:30

    @omarpop23 thanks. :rose:

    I gave it a try with your template and it seems to work fine, except for the username which I corrected for you. Give it a try :
    Code:
    $(function() {
      // General Configuration of the plugin
      var config = {
        position_left : true, // true for left || false for right
        negative_vote : true, // true for negative votes || false for positive only
        vote_bar : true, // display a small bar under the vote buttons
     
        // button config
        icon_plus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/plus10.png" alt="+"/>',
        icon_minus : '<img src="http://i18.servimg.com/u/f18/18/21/41/30/minus10.png" alt="-"/>',
     
        // language config
        title_plus : 'Like %{USERNAME}\'s post',
        title_minus : 'Dislike %{USERNAME}\'s post',
     
        title_like_singular : '%{VOTES} person likes %{USERNAME}\'s post',
        title_like_plural : '%{VOTES} people like %{USERNAME}\'s post',
     
        title_dislike_singular : '%{VOTES} person dislikes %{USERNAME}\'s post',
        title_dislike_plural : '%{VOTES} people dislike %{USERNAME}\'s post',
     
        title_vote_bar : '%{VOTES} people liked %{USERNAME}\'s post %{PERCENT}'
      },
     
     
      // function bound to the onclick handler of the vote buttons
      submit_vote = function() {
        var next = this.nextSibling, // the counter next to the vote button that was clicked
            box = this.parentNode,
            bar = box.getElementsByTagName('DIV'),
            vote = box.getElementsByTagName('A'),
            mode = /eval=plus/.test(this.href) ? 1 : 0,
            i = 0, j = vote.length, pos, neg, percent;
     
        // submit the vote asynchronously
        $.get(this.href, function() {
          next.innerHTML = +next.innerHTML + 1; // add to the vote count
          next.title = next.title.replace(/(\d+)/, function(M, $1) { return +$1 + 1 });
     
          pos = +vote[0].nextSibling.innerHTML;
          neg = vote[1] ? +vote[1].nextSibling.innerHTML : 0;
          percent = pos == 0 ? '0%' : pos == neg ? '50%' : Math.round(pos / (pos + neg) * 100) + '%';
     
          if (bar[0]) {
            bar[0].style.display = '';
            bar[0].firstChild.style.width = percent;
            box.title = box.title.replace(/\d+\/\d+/, pos + '/' + ( pos + neg )).replace(/\(\d+%\)/, '(' + percent + ')');
          }
        });
     
        // revoke voting capabilities on the post once the vote is cast
        for (; i < j; i++) {
          vote[i].href = '#';
          vote[i].className = vote[i].className.replace(/fa_vote/, 'fa_voted');
          vote[i].onclick = function() { return false };
        }
     
        return false;
      },
     
      vote = $('.vote'), i = 0, j = vote.length,
      version = 0, // version check
     
      // version data so we don't have to redefine these arrays during the loop
      vdata = {
        tag : ['LI'][version],
        name : ['.user-name'][version],
        actions : ['.profile-icons'][version],
      },
     
      post, plus, minus, n_pos, n_neg, title_pos, title_neg, li, ul, bar, button, total, percent, span, pseudo, vote_bar; // startup variables for later use in the loop
     
      for (; i < j; i++) {
        post = $(vote[i]).closest('.post')[0];
        bar = $('.vote-bar', vote[i])[0]; // vote bar
        button = $('a[class^="ion-thumb"]', vote[i]); // plus and minus buttons
        pseudo = $(vdata.name, post).text() || 'MISSING_STRING'; // username of the poster
        ul = $(vdata.actions, post)[0]; // post actions
        li = document.createElement(vdata.tag); // vote system container
        li.className = 'fa_reputation';
     
        if (li.tagName == 'SPAN') li.style.display = 'inline-block';
     
        // calculate votes
        if (bar) {
          total = +bar.title.replace(/.*?\((\d+).*/, '$1');
          percent = +bar.title.replace(/.*?(\d+)%.*/, '$1');
     
          n_pos = Math.round(total * (percent / 100));
          n_neg = total - n_pos;
        } else {
          n_pos = 0;
          n_neg = 0;
        }
     
        // set up negative and positive titles with the correct grammar, votes, and usernames
        title_pos = (n_pos == 1 ? config.title_like_singular : config.title_like_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_pos);
        title_neg = (n_neg == 1 ? config.title_dislike_singular : config.title_dislike_plural).replace(/%\{USERNAME\}/g, pseudo).replace(/%\{VOTES\}/g, n_neg);
     
        // define the vote counts
        li.innerHTML = '<span class="fa_count fa_positive" title="' + title_pos + '">' + n_pos + '</span>' + (config.negative_vote ? '&nbsp;<span class="fa_count fa_negative" title="' + title_neg + '">' + n_neg + '</span>' : '');
        span = li.getElementsByTagName('SPAN'); // get the vote count containers for use as insertion points
     
        // create positive vote button
        plus = document.createElement('A');
        plus.href = button[0] ? button[0].href : '#';
        plus.onclick = button[0] ? submit_vote : function() { return false };
        plus.className = 'fa_vote' + (button[0] ? '' : 'd') + ' fa_plus';
        plus.innerHTML = config.icon_plus;
        plus.title = (button[0] ? config.title_plus : title_pos).replace(/%\{USERNAME\}/g, pseudo);
     
        span[0] && li.insertBefore(plus, span[0]);
     
        // create negative vote button
        if (config.negative_vote) {
          minus = document.createElement('A');
          minus.href = button[1] ? button[1].href : '#';
          minus.onclick = button[1] ? submit_vote : function() { return false };
          minus.className = 'fa_vote' + (button[1] ? '' : 'd') + ' fa_minus';
          minus.innerHTML = config.icon_minus;
          minus.title = (button[1] ? config.title_minus : title_neg).replace(/%\{USERNAME\}/g, pseudo);
     
          span[1] && li.insertBefore(minus, span[1]);
        }
     
        // create vote bar
        if (config.vote_bar) {
          vote_bar = document.createElement('DIV');
          vote_bar.className = 'fa_votebar';
          vote_bar.innerHTML = '<div class="fa_votebar_inner" style="width:' + percent + '%;"></div>';
          vote_bar.style.display = bar ? '' : 'none';
          li.title = config.title_vote_bar.replace(/%\{USERNAME\}/, pseudo).replace(/%\{VOTES\}/, n_pos + '/' + (n_pos + n_neg)).replace(/%\{PERCENT\}/, '(' + percent + '%)');
          li.appendChild(vote_bar);
        }
     
        // finally insert the vote system and remove the default one
        config.position_left ? ul.insertBefore(li, ul.firstChild) : ul.appendChild(li);
        vote[i].parentNode.removeChild(vote[i]);
      }
    });
     
    $('head').append('<style type="text/css">li.fa_reputation > * {float:none;}.fa_count,.fa_voted{cursor:default}.fa_count,.fa_vote,.fa_voted{font-size:12px;font-family:Verdana,Arial,Helvetica,Sans-serif;display:inline-block!important;width:auto!important;transition:.3s}.fa_vote:hover,.fa_voted{opacity:.4}.fa_count{font-weight:700;margin:0 3px}.fa_positive{color:#4A0}.fa_negative{color:#A44}.fa_votebar,.fa_votebar_inner{background:#C44;height:3px}.fa_votebar_inner{background:#4A0;transition:.3s}</style>');

    Make sure that when you're trying to vote, you're voting on a post that you haven't voted on yet.
    omarpop23
    omarpop23
    Forumember


    Male Posts : 182
    Reputation : 3
    Language : Arabic
    Location : Egypt

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by omarpop23 3/7/2017, 17:26

    yeah banana thank you it works well now groar
    Draxion
    Draxion
    Helper
    Helper


    Male Posts : 2518
    Reputation : 321
    Language : English
    Location : USA

    Solved Re: [HELP] Improve the reputation system so it counts votes

    Post by Draxion 3/7/2017, 17:34

    Problem solved & topic archived.
    Please read our forum rules: ESF General Rules