The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

[Tutorial] Reputation Levels

Page 2 of 2 Previous  1, 2

View previous topic View next topic Go down

[Tutorial] Reputation Levels

Post by Daemon on July 20th 2017, 6:59 am

First topic message reminder :

With this code you can customize the reputation profile by adding levels according to the reputation number.



Create a new JavaScript code with the following content (The placement "In topics" only):
Code:
/*
 *  Application: Reputation Levels
 *  Date: 19/05/2017
 *  Version: 1.220072017
 *  Copyright (c) 2017 Daemon <help.forumotion.com>
 *  This work is free. You can redistribute it and/or modify it
 */
function bs_reputation_ipb() {

/*
 * Configure below the levels for the reputation profile,
 * with the respective number needed to win it.
 * You can also add a class to customize the element.
 */
 
var arrConfig = [
    {
      reputation: 0,
      level: "Neutral",
      class: "zero"
    },
    {
      reputation: 1,
      level: "Beginner"
    },
    {
      reputation: 10,
      level: "Regular"
    },
    {
      reputation: 20,
      level: "Good"
    },
    {
      reputation: 35,
      level: "Great"
    },
    {
      reputation: 50,
      level: "Excellent",
      class: "awesome"
    }
];

/*
 * No need to change anything from here down
 */

var userLink, repField, repFieldName, repFieldValue, regExp, level, repClass;
var BreakException = {};
jQuery.each(jQuery(".post"), function(i, val) {
    var thisPost = jQuery(val);
    userLink = thisPost.find("a[href^='/u']").attr("href");
    jQuery.ajax({
        type: "GET",
        url: userLink,
        success: function(data) {
            repField = jQuery("#field_id-14", data);
            repFieldName = repField.find("dt").text().split(" ")[0];
            repFieldValue = parseInt(repField.find("dd").text());
            regExp = new RegExp("(<span class="label">(?:<span style="[^"]*">)?" + repFieldName + "(?:<\\/span>)?\\s:\\s<\\/span>\\d+)", "g");
            try {
                jQuery.each(arrConfig, function(i, val) {
                    if (val.reputation <= repFieldValue) {
                        level = (val.level) ? val.level : "";
                        repClass = (val.class) ? " " + val.class : "";
                    } else {
                        throw BreakException;
                    }
                });
            } catch (e) {
                if (e !== BreakException) throw e;
            }
            thisPost.find(".label").parent().html(function(i, val) {
                return val.replace(regExp, "<div class='reputation_bs" + repClass + "'>$1<br><span class='title' style='font-weight:normal'>" + level + "</span></div>");
            });
        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.log("**An error occurred while trying to request the data");
        }
    });
});
 
};
jQuery(function() {
    bs_reputation_ipb();
});
Add the following in your css style sheet:
Code:
.reputation_bs {
  background-color: #DFF0D8;
  font-weight: bold;
  padding: 3px 8px;
  display: block !important;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
  color: #3C763D;
  margin: 5px auto;
  font-family: Lato,Arial,Helvetica,sans-serif;
  font-size: 13px;
  margin-bottom: 5px;
  max-width: 123px;
  text-align: center;
}
.reputation_bs.zero {
  background: none repeat scroll 0% 0% rgba(222, 222, 222, 0.34);
  color: #6e6e6e;
}
The instructions are inside the code.
Wink


Last edited by Daemon on July 20th 2017, 6:23 pm; edited 2 times in total
avatar
Daemon
Forumember

Posts : 51
Reputation : 29
Language : Portuguęs

Back to top Go down


Re: [Tutorial] Reputation Levels

Post by SLGray on August 6th 2017, 8:38 pm

AP > Modules > Points/Reputation > Reputation


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

avatar
SLGray
Administrator
Administrator

Male Posts : 40523
Reputation : 2733
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: [Tutorial] Reputation Levels

Post by smurfavr on August 6th 2017, 8:41 pm

Thank you SLGray. Now it works.
avatar
smurfavr
Active Poster

Male Posts : 1586
Reputation : 14
Language : Bulgarian

http://smurfa.bulgarianforum.net/

Back to top Go down

Re: [Tutorial] Reputation Levels

Post by SLGray on August 6th 2017, 8:45 pm

You're welcome.


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

avatar
SLGray
Administrator
Administrator

Male Posts : 40523
Reputation : 2733
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Page 2 of 2 Previous  1, 2

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum